实现linux服务器之间无密码互访

环境介绍
两台CentOS服务器,主机名和IP分别是: server1 192.168.1.69 server2 192.168.1.70
准备
#两台都要安装

yum install -y openssh-clients

分别打开两台服务器的hosts文件,在文件末尾添加以下内容,让主机名和IP对应。(还有就是别忘了分别修改两台服务器的/etc/sysconfig/network文件里的HOSTNAME,改成对应的服务器的主机名即可。)

vim /etc/hosts
server1 192.168.1.69
server2 192.168.1.70

开始
准备工作做好了,现在就可以开工了,首先在server1运行ssh-keygen,直接一路回车

[root@server1 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
d8:0c:6c:f8:44:a3:61:c3:53:5c:09:93:2d:1d:d1:82 root@server1
The key's randomart image is:
+--[ RSA 2048]----+
| .+o*B+= |
| .oBEo= . |
| o.=. . |
| + = |
| o S |
| |
| |
| |
| |
+-----------------+

切换到server2,同上。
回到server1,运行ssh-copy-id -i .ssh/id_rsa.pub root@server2

[root@server1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@server2
The authenticity of host 'server2 (192.168.1.70)' can't be established.
RSA key fingerprint is 99:3b:ea:56:48:73:07:08:79:1f:69:b7:f2:a8:01:5c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server2,192.168.1.70' (RSA) to the list of known hosts.
root@server2's password: #输入对方服务器root密码
Now try logging into the machine, with "ssh 'root@server2'", and check in:
 
.ssh/authorized_keys
 
to make sure we haven't added extra keys that you weren't expecting.

切换到server2,运行ssh-copy-id -i .ssh/id_rsa.pub root@server1
现在,你就可以不需要输入对方服务器的密码而直接登录了

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MichaelYZ111

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值