- Sometimes we need to use SSH login without password to access the target server quickly.
- Below will show you how to do it step by step.
- Reference: http://www.linuxproblem.org/art_9.html
- Reference: http://josephj.com/article/understand-ssh-key/
- [Comment] First, login into your workstation and generate a pair of authentication keys.
- [Comment] rsa1 for SSH protocol 1, rsa and dsa for SSH protocol 2
- [Comment] In my environment, I choose RSA 2 (rsa).
- root@simple-plan:~# ssh-keygen -t rsa (dsa | rsa1)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
- [Comment] Now, check the directory contains the key pairs
- root@simple-plan:~# ls /root/.ssh/
id_dsa id_dsa.pub identity identity.pub id_rsa id_rsa.pub
- [Comment] Copy the public key to the target server
- root@simple-plan:~# scp ~/.ssh/id_rsa.pub target_server:~/.ssh/id_rsa.pub -P target_server_port
root@simple-plan:~# scp ~/.ssh/id_rsa.pub www.example.com:~/.ssh/id_rsa.pub -P 22
- [Comment] Login the target server and append the public key into a file named "authorized_keys"
- firstname.lastname@example.org:~# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- email@example.com:~# chmod 755 ~/.ssh
- firstname.lastname@example.org:~# chmod 644 ~/.ssh/authorized_keys
- [Comment] It's done!
- root@simple-plan:~# ssh www.target.com -p 22 (no password needed)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is: