Want to SCP SSH and Rsync without prompting for password? Follow the steps given below.
In this case, Server “S” is the source or local server, and Server “R” is the remote or destination server.
1) First thing you have to do is to log in to the “S” server and create pair of authentication keys using the “ssh-keygen” tool.
ssh-keygen generates, manages, and converts authentication keys for ssh.
ssh-keygen can create RSA keys for use by SSH protocol version 1 and RSA ( RSA stands for Ron Rivest, Adi Shamir, and Leonard Adleman, who first publicly described the algorithm in 1977 ) or DSA ( Digital Signature Algorithm (DSA) is a United States Federal Government standard or FIPS for digital signatures. ) keys for use by SSH protocol version 2. The type of key to be generated is specified with the -t option.
If invoked without any arguments, ssh-keygen will generate an RSA key for two connections in the SSH protocol. So now you know what it is, and it’s time to create the authentication keys. ( You don’t have to type any passphrase )
S:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/s/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/s/.ssh/id_rsa. Your public key has been saved in /home/s/.ssh/id_rsa.pub. The key fingerprint is: 80:55:8e:ef:48:45:6e:ac:b4:d3:08:cb:fc:df:8f:3a email@example.com The key's randomart image is: +--[ RSA 2048]----+ | ..o | | o * | | o + * | | o + X | | + * S | | o + | | o . | | .E. . | | ooo.. | +-----------------+
2) Now, you have created a unique SSH authentication key using the RSA algorithm and stored it in “/home/s/.ssh/id_rsa”. Let’s copy this public key to remote machine “R” using the “ssh-copy-id tool.
ssh-copy-id is a script that uses ssh to log into a remote machine.
It also changes the permissions of the remote user’s home, ~/.ssh, and ~/.ssh/authorized_keys to remove group write ability (which would otherwise prevent you from logging in if the remote sshd has StrictModes set in its configuration).
If the -i option is given, the identity file (defaults to ~/.ssh/id_rsa.pub) is used, regardless of whether there are any keys in your ssh-agent. So, in this case, we are using the “-i” switch to make this easy. ( Just provide the password when it asks for. )
S:~$ ssh-copy-id -i r@remote_machine
Now try logging into the machine, with “ssh ‘r@remote_machine'”, and check-in:
To make sure we haven’t added extra keys that you weren’t expecting.
That’s it!! That’s how you do SCP SSH and Rsync without prompting for the password. Please test it and verify the working.