模拟场景:192.168.1.5服务器上配置,通过ssh远程免密登录192.168.1.160

1、安装SSH,此处省略
2、生成公钥和私钥,生成的秘钥默认在/root/.ssh/文件夹里面
[root@localhost ~ 09:16:45&&26]# ssh-keygen #默认按enter直至结束
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:
SHA256:2GM5hi5CJhi+6JbmYkHfbbnNzYB3FoFUr+D50gGt9KQ root@localhost.localdomain
The key’s randomart image is:
+—[RSA 2048]—-+
| ..o. |
| …. |
|. + o.. |
|oo +o.O.. |
|+.+ . + SE +. |
|.=.. o B =oo. |
|..+ . o =.o | |o= . . . o.o | |o |
+—-[SHA256]—–+

3、把生成的公钥发送到对方的主机上去,用ssh-copy-id命令,自动保存在对方主机的/root/.ssh/authorized_keys文件中去

/c/Users/zhibiao/.ssh/id_rsa
vim ~/.ssh/known_hosts

[root@localhost ~ 09:16:45&&26]# ssh 192.168.1.160 #需要登录密码
[root@localhost ~ 09:16:45&&26]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.160
[root@localhost ~ 09:16:45&&26]# ssh 192.168.1.160 #免密登录

作者 baiwangea

发表评论

您的电子邮箱地址不会被公开。