Linux ssh免密登录
1、首先在A机下生成公钥/私钥对:(-P表示密码,-P '' 就表示空密码,一次回车即可。在~/.ssh会生成id_rsa和id_rsa.pub两个文件)
[root@registry home]# ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (直接回车)
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:
e8:a1:c0:cc:d0:2c:88:82:35:0f:c7:75:2b:79:14:72 root@registry
The key's randomart image is:
+--[ RSA 2048]----+
| +...o E. |
|++ =. * . |
|B o . o o |
|.* + |
| = o S |
| . o . |
| . . |
| |
| |
+-----------------+
[root@registry home]# cd ~/.ssh/
[root@registry .ssh]# ll
总用量 12
-rw-------. 1 root root 1675 4月 5 13:27 id_rsa
-rw-r--r--. 1 root root 395 4月 5 13:27 id_rsa.pub
-rw-r--r--. 1 root root 2492 4月 5 10:52 known_hosts
2. 将A机下的id_rsa.pub复制到B机下
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.2