ubuntu22.04 服务器 ssh 密钥登录失败 1. 背景介绍 SSH密钥登录,是将SSH公钥写入服务端的 ~/.ssh/authorized_keys文件中。 今天装了ubuntu22.04的系统,按照以往操作,在服务端配置了SSH
SSH密钥登录,是将SSH公钥写入服务端的 ~/.ssh/authorized_keys
文件中。
今天装了ubuntu22.04的系统,按照以往操作,在服务端配置了SSH公钥之后,发现竟然无法登录。
首先查看OpenSSH版本:
$ ssh -VOpenSSH_8.9p1 Ubuntu-3ubuntu0.1, OpenSSL 3.0.2 15 Mar 2022
查看 /var/log/auth.log
文件,发现有如下错误信息:
sshd[2648]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlGorithms [preauth]
通过错误信息来看,填入authorized_keys
文件的SSH公钥类型是 ssh-rsa 类型,属于不支持的公钥类型。应该是SSH版本高版本中增加该限制。
查看支持的公钥类型:
$ sudo sshd -T | egrep "pubkey"pubkeyauthentication yespubkeyacceptedalgorithms 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-256pubkeyauthoptions none
知道了问题原因,问题就好解决了。
使用受支持的公钥类型,重新生成OpenSSH公私钥,比如使用ed25519
。
使用ssh-keygen
命令生成ed25519
公私钥方法如下:
$ ssh-keygen -t ed25519 # 默认生成到~/.ssh/ 目录下,默认文件名为:id_ed25519 和 id_ed25519.pub$ ssh-keygen -t ed25519 -f test # 生成文件到当前目录,文件名为:test 和 test.pub
修改sshd配置文件/etc/ssh/sshd_config
,使得pubkeyacceptedalgorithms
支持ssh-rsa
公钥类型。
修改方法:在/etc/ssh/sshd_config
文件末尾增加一行PubkeyAcceptedAlgorithms +ssh-rsa
$ sudo echo "PubkeyAcceptedAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config$$ tail /etc/ssh/sshd_configSubsystemsftp/usr/lib/openssh/sftp-server# Example of overriding settings on a per-user basis#Match User anoncvs#X11Forwarding no#AllowtcpForwarding no#PermitTTY no#ForceCommand cvs serverPubkeyAcceptedAlgorithms +ssh-rsa
修改完/etc/ssh/sshd_config
配置文件后,需要重启sshd服务,执行 sudo systemctl restart sshd.service
来源地址:https://blog.csdn.net/ljz0929/article/details/129759705
--结束END--
本文标题: ubuntu22.04 服务器 SSH 密钥登录失败
本文链接: https://www.lsjlt.com/news/377818.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-13
2024-05-13
2024-05-11
2024-05-11
2024-05-10
2024-05-07
2024-04-30
2024-04-30
2024-04-30
2024-04-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0