所选的用户密钥未在远程主机上注册
问题
部署新服务器的时候,将登陆方式从密码登陆改为密钥登陆。在使用xshell验证密钥登陆的时候提示(报错):所选的用户密钥未在远程主机上注册
.
排查
查看日志
[[email protected] .ssh]# tailf /var/log/secure
....
Dec 24 20:24:50 nl sshd[1067]: error: Received disconnect from 112.xx.xx.xx port 26514:0: [preauth]
Dec 24 20:24:50 nl sshd[1067]: Disconnected from 112.xx.xx.xx port 26514 [preauth]
....
查看ssh密钥
[[email protected] .ssh]# ll
total 8
-rw------- 1 root root 1679 Dec 25 08:59 id_rsa
-rw-r--r-- 1 root root 397 Dec 25 08:59 id_rsa.pub
根据经验发现缺少authorized_keys
文件,需要将本机的pub公钥导入到此文件中授信。
解决
[[email protected] .ssh]# cat id_rsa.pub >> authorized_keys
[[email protected] .ssh]# chmod 600 authorized_keys
[[email protected] .ssh]# ll
total 12
-rw------- 1 root root 397 Dec 25 09:34 authorized_keys
-rw------- 1 root root 1679 Dec 25 08:59 id_rsa
-rw-r--r-- 1 root root 397 Dec 25 08:59 id_rsa.pub