Category: ssh

How to Scp, Ssh And Rsync Without Prompting For Password.

Whenever you need to use scp to copy files, it asks for passwords. Same with rsync as it (by default) uses ssh as well. Usually scp and rsync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying when the password is asked every time.

Lets say you want to copy between two hosts user_src and user_dest.user_src is the host where you would run the scp, ssh or rsync command, irrespective of the direction of the file copy!

1. On user_src,
run this command as the user that runs scp/ssh/rsync

 $ ssh-keygen -t rsa

This will prompt for a passphrase. Just press the enter key. It’ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub: Your public key has been saved in <your_home_dir>/.ssh/id_rsa.pub

2. Transfer the id_rsa.pubfile to user_dest by either ftp, scp, rsync or any other method.

3. On user_dest, login as the remote user which you plan to use when you run scp, ssh or rsync on user_src.

4. Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys

$ cat id_rsa.pub >>~/.ssh/authorized_keys 
$ chmod 700 ~/.ssh/authorized_keys

If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.

  1. Note that ssh by default does not allow root to log in. This has to be explicitly enabled on user_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin
    from no to yes. Don’t forget to restart sshd so that it reads the modified config file. Do this only if you want to use the root login.
  1. Note that ssh by default does not allow root to log in. This has to be explicitly enabled on user_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin
    from no to yes. Don’t forget to restart sshd so that it reads the modified config file. Do this only if you want to use the root login.

Well, that is it. Now you can run scp, ssh and rsync on user_src connecting to user_dest and it won’t prompt for the password. Note that this will still prompt for the password if you are running the commands on user_dest connecting to user_src. You can reverse the steps above (generate the public key on user_dest and copy it to user_src) and you have a two way transfer ready without prompting for password!

Useful and Important commands for Fedora 28

After fresh installlation:

sudo dnf update  

Enable and start SSH:

sudo systemctl start sshd.service
sudo systemctl enable sshd.service


RPM Fusion:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

Install Vlc:

sudo dnf install vlc

Restart apache:   

systemctl restart httpd  

                       or

service httpd restart
  
Enable apache on startup:

systemctl enable httpd

Allow http connections:

firewall-cmd –add-service=http –permanent

firewall-cmd –reload

Install  php and Mysql(mariadb):

dnf install php-cli
dnf install mariadb mariadb-server

systemctl restart mariadb

finalize mariadb installation

/usr/bin/mysql_secure_installation

dnf install php-mysqlnd (For php-mysql driver)

After doing all these restart apache

systemctl restart httpd

Resolve gedit open issue when opening from remote machine

What happens is  sometimes when we try  to ssh into a system and open gedit in that machine(remote) everything seems fine until we try to  type something or save into that file or even we cannot open other files using open menu in file tab.

So the solution here is:

Use nautilus/gedit on local machine

1. Open a nautilus file browser window and select “connect to server” from the menu in the top panel.

2. Enter in the server(remote) info (use ssh:// or sftp:// for ssh connections).

3. Enter password and there you go. You will be connected to the remote machine and now your gedit works fine.

Courtesy: this answer from ask ubuntu is where I found the solution.