生成密钥
- 在机器一上
命令:ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
c3:b9:63:72:1c:80:85:f5:75:91:51:0f:a0:a8:e0:87 root@suning-01
The key's randomart image is:
+--[ RSA 2048]----+
| oo . =*o |
| .o . o o. o |
| o . o . .|
| . o + . |
| E o S |
| . . + |
| . * |
| + . |
| |
+-----------------+
命令 ls /root/.ssh/
authorized_keys id_rsa id_rsa.pub
#其中id_rsa.pub是公钥
命令:cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCa3Z+I2evvNyO5vl6Izh15L8R1cVkDmjYFqt2a/Aazq6ogWGkxSChXc46aDUHGkjJnMtjZHe5cuSKXOhYBBxbhak1dFS248R4DsH4BAWHb2AeIIKIwEc/XXRfPpTK97YQ2yllGN+gdfPa/l5nR9e6FySKXSWfrgZ34I6DLQGeHndkAykjRZmp9mU20XO3KJYRm6WezLWI2y7/OQuktRw/R7qalg3fiZHFly5A8SPl87fZ7Rioyqzf5IQxQfpHeBGnrCRLN3pKKAYAUG2PHJZO2634vMjfG4HilBJzys1WAI6O5mkRrht/1haAjODRgMqdCOxO+72wBtyZ5BzSY+Xir root@suning-01
2. 在另外一台机器上
vim /root/.ssh/authorized_keys
#将上方的.pub文件内容粘贴到authorized_keys中
关闭防火墙
- 查看防火墙状态
$ getenforce
Enforcing :表示启用
$ setenforce 0
$ getenforce
Permissive:表示关闭防火墙
登陆格式
ssh -p 22 root@192.168.139.138
再次登陆时,不再需要输入密码