第一步,先用ssh-keygen工具生成公钥和私钥,如下:
james@james-myhome:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/james/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/james/.ssh/id_rsa.
Your public key has been saved in /home/james/.ssh/id_rsa.pub.
The key fingerprint is:
cd:b4:f8:25:35:be:fb:78:a3:48:61:75:6e:f1:2f:53 james@james-myhome
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . + o |
| = = + o |
| S B o o E|
| o + o ..|
| o . o .|
| . . ooo |
| . ++.. |
+-----------------+
james@james-myhome:~$ cd .ssh/
james@james-myhome:~/.ssh$ ll
总用量 20
drwx------ 2 james james 4096 11月 25 22:17 ./
drwxr-xr-x 39 james james 4096 11月 25 22:12 ../
-rw------- 1 james james 1766 11月 25 22:17 id_rsa
-rw-r--r-- 1 james james 400 11月 25 22:17 id_rsa.pub
-rw-r--r-- 1 james james 1549 11月 24 22:41 known_hosts
其中id_rsa就是私钥要保管好,可以设置一个密码,id_rsa.pub是公钥,放在需要登陆的服务器的家目录下的.ssh目录下,
然后可以cat id_rsa.pub >>authorized_keys就可以了,也可以使用工具操作.
ssh-copy-id -i id_rsa.pub root@172.16.100.1
用工具操作速度会快很多.
转载于:https://my.oschina.net/u/2007368/blog/348744