Xshell使用密钥远程登录Ubuntu 22.04报错:所选的用户密钥未在远程主机上注册。请再试一次

报错截图如下:

问题原因:

Ubuntu 22.04 不支持 Xshell使用的私钥。
查看系统支持的私钥:sudo sshd -T | egrep "pubkey"

bash 复制代码
~$ sudo sshd -T | egrep "pubkey"
pubkeyauthentication yes
pubkeyacceptedalgorithms ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256
pubkeyauthoptions none

查看Xshell使用的密钥:

默认使用密钥类型是: ssh-rsa

到这里就已经清晰了,只需要把ssh-rsa密钥加入到ubuntu 22系统内,就可以远程了。

新增密钥类型支持

配置文件:/etc/ssh/sshd_config

bash 复制代码
PubkeyAcceptedKeyTypes +ssh-rsa
  • +ssh-rsa 使用 + 表示新增密钥类型支持,不使用 + 表示只支持指定类型的密钥

最后重启sshd

查看密钥是否新增了ssh-rsa

bash 复制代码
root@bird:/etc/ssh# sudo sshd -T | egrep "pubkey" | grep "ssh-rsa"
pubkeyacceptedalgorithms ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa

可以看出最后已经新增了 ssh-rsa 密钥类型支持

查看远程效果

最后使用密钥远程连接成功!

相关推荐
Jia ming6 分钟前
跟踪器与事件使用举例
linux·事件·跟踪器
生活很暖很治愈18 分钟前
Linux——基础IO&软硬链接
linux·ubuntu
2401_8589368830 分钟前
【Linux C 编程】标准 IO 详解与实战:从基础接口到文件操作实战
linux·c语言
Roc.Chang42 分钟前
Ubuntu 下 VLC 无法启动(Segmentation fault)终极解决方案
linux·ubuntu·vlc·媒体播放
松涛和鸣1 小时前
72、IMX6ULL驱动实战:设备树(DTS/DTB)+ GPIO子系统+Platform总线
linux·服务器·arm开发·数据库·单片机
Anesthesia丶1 小时前
Ubuntu20.04 升级 Ubuntu24.04 LTS
ubuntu
简单中的复杂2 小时前
【避坑指南】RK3576 Linux SDK 编译:解决 Buildroot 卡死在 host-gcc-final 的终极方案
linux·嵌入式硬件
wVelpro2 小时前
如何在Pycharm 2025.3 版本实现虚拟环境“Make available to all projects”
linux·ide·pycharm
程序员老舅3 小时前
C++高并发精髓:无锁队列深度解析
linux·c++·内存管理·c/c++·原子操作·无锁队列
雨中风华3 小时前
Linux, macOS系统实现远程目录访问(等同于windows平台xFsRedir软件的目录重定向)
linux·windows·macos