CentOs7 Linux下互相SSH免密码登录配置

记录一下有关 Linux下SSH免密码登录配置步骤
环境准备

node1:192.168.0.103

node2:192.168.0.102

1. 关闭防火墙

查看防火状态

systemctl status firewalld
service  iptables status

暂时关闭防火墙

systemctl stop firewalld
service  iptables stop

永久关闭防火墙

systemctl disable firewalld
chkconfig iptables off

重启防火墙

systemctl enable firewalld
service iptables restart  

2. 关闭SELinux

永久生效
修改 /etc/selinux/config 文件中的 SELINUX=enforcing 修改为 SELINUX=disabled ,然后重启
临时生效

 setenforce 0

3. 分别在两台机器上生成私钥/公钥对

[root@localhost ~]# ssh-keygen -t rsa

4. 将node1主机下的id_rsa.pub复制到node2主机下

[root@localhost ~]$ scp .ssh/id_rsa.pub root@192.168.0.102:~

此时还没有免密码登录,所以要输入node2的密码

5. node2主机须将复制过来的id_rsa.pub文件中的内容添加到/home/user/.ssh/authorzied_keys文件中

[root@localhost ~]$ cat id_rsa.pub >> .ssh/authorized_keys
[root@localhost ~]$ chmod 600 .ssh/authorized_keys

说明:第4、5步可以用一个命令搞定:ssh-copy-id 192.168.0.102

6. 验证是否可以免密码登录

[root@localhost ~]$ ssh 192.168.0.102

7. node2 登录node1 在nod2主机上重复上面4,5步骤

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值