ssh-passwordless
Sometimes we need a ssh connection that do not ask for passwords. It is use frequently in scripts that involve ssh, scp or sftp connections. Steps to make such connection:
1. Login as user1 on computer1 and generate a pair of authentication keys. Note: even if is unsecured to work without password, do not enter it. Let it empty...
[user1@computer1]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is: 31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1
2. Login to the remote computer (computer2) as user2 and create the .ssh directory (many Linux distributions create this folder by default). You still need the password for now.
[user1@computer1]$ ssh user2@computer2 mkdir -p .ssh
user2@computer2's password:
3. Copy the user1 public key to user2@computer2 .ssh folder into authorized_keys [or authorized_keys2] file. And, type the password again for the last time.
[user1@computer1]$ cat .ssh/id_rsa.pub | ssh user2@computer2 > 'cat >> .ssh/authorized_keys'
user2@computer2's password:
4. If all things are OK, you don't need the password:
[user1@computer1]$ ssh user2@computer2
[user2@computer2]$
Or optionaly:
[user1@computer1]$ ssh -i $HOME/.ssh/id_rsa user2@computer2