$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/daodao/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/chengang/.ssh/id_rsa.
Your public key has been saved in /home/chengang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RymhT9wC+nuQHe9v6e9rSAUYQIxKuKbrEF1tAVWGiwY chengang@chengang-vm
The key's randomart image is:
+---[RSA 2048]----+
| ..o+**..o |
| E .oo*.o... |
| +oo+.* + . |
| .o.+o.= * . |
|.o.. + S o . |
|.. o o . |
|.. . . .. o |
|o . .+ . |
|.. oo++. |
+----[SHA256]-----+
用ssh-copy-id將公鑰復制到遠程機器中
$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.10.4.76
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/daodao/.ssh/id_rsa.pub"
The authenticity of host '10.10.4.76 (10.10.4.76)' can't be established.
RSA key fingerprint is SHA256:BERyt3qqK2giIkBJw0Nny1dEaKWdKxYGlF9rp6b9rT0.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.10.4.76's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.10.4.76'"
and check to make sure that only the key(s) you wanted were added.
登錄到遠程機器(不用輸入密碼)
$ ssh root@10.10.4.76
Last login: Fri Sep 30 2016 from 10.10.4.77
[root@localhost ~]# who
root pts/0 2016-09-30 13:02 (10.10.4.77)