记录_Linux_SSH密钥链接【问题】

关于Linux中生成SSH密钥后,传输公钥仍连接不上的问题

实验目的

通过servera生成的密钥,传输给fundation2
fundation2关闭密码验证
servera仍能链接fundation2

前提

不同虚拟机之间能够ping通

操作

servera上的操作

  1. root@servera ~]# ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/servera
    /root/.ssh/目录下创建一个密码为servera

  2. ping通fundation2

点击查看详情
[root@servera .ssh]# ping 192.168.155.128
PING 192.168.155.128 (192.168.155.128) 56(84) bytes of data.
64 bytes from 192.168.155.128: icmp_seq=1 ttl=64 time=0.579 ms
  1. 远程传输给servera
点击查看代码
[root@servera .ssh]# ssh-copy-id -i /root/.ssh/servera.pub root@192.168.155.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/servera.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.155.130's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.155.130'"
and check to make sure that only the key(s) you wanted were added.
`
  1. 关闭密码验证
点击查看代码
[root@servera .ssh]# vim /etc/ssh/sshd_config 

PasswordAuthentication no

  1. 重启SSH安全服务
    [root@servera .ssh]# systemctl reload sshd.service

fundation2上的操作

  1. 查看/root/.ssh/authorized_keys文件夹中是否有来自servera的密钥

  2. 链接ssh root@192.168.155.128
    出错,

最终结果

总结

其实是servera链接fundationa。。。

posted @ 2022-02-14 12:14  Demon丶安梓  阅读(82)  评论(0编辑  收藏  举报