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 [email protected]:~

此時還沒有免密碼登錄,所以要輸入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步驟

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章