首页 > 技术文章 > Linux之SSH免密登录

MisterZZL 2018-09-09 17:40 原文

实验方法:

  1. 开启两台虚拟机A和B,IP地址分别为192.168.222.12、192.168.222.10

  2. 在虚拟机A下做如下操作,生成公钥和密钥:

     [root@localhost ~]# ssh-keygen -t rsa
    
  3. 连续3次回车,结果如下:

  4. 此时可以进入/root/.ssh查看:

     [root@localhost ~]# cd /root/.ssh
     [root@localhost .ssh]# ls
    

  5. 同样的操作在B虚拟机上做一遍。

  6. 如果想A机器登录到B机器,则:

     [root@localhost .ssh]# scp /root/.ssh/id_rsa.pub root@192.168.222.10:/root/.ssh/authorized_keys
    
  7. 上一步回车之后:

  8. 在ssh目录下查看:

     [root@localhost .ssh]# ls
    

  9. 如果需要B登录到A,操作是一样的,只是注意(远程拷贝scp那行命令)IP地址

  10. 所有步骤完成,最后一步验证登录

    [root@localhost .ssh]# ssh 192.168.222.10
    

推荐阅读