Introduction:
- 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/
Steps:
- [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
- [Example]
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"
- root@www.target.com:~# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- root@www.target.com:~# chmod 755 ~/.ssh
- root@www.target.com:~# chmod 644 ~/.ssh/authorized_keys
- [Comment] It's done!
- root@simple-plan:~# ssh www.target.com -p 22 (no password needed)
- root@www.target.com:~#
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:
74:a5:7d:6b:5b:03:98:2f:d3:20:a5:1c:e2:ff:33:18 root@simple-plan
No comments:
Post a Comment