大网数据广告活动
服务器运维问答

SSH2 fails authentication with a working key converted with PuttyGen (due to deprecated ssh-rsa?)

· 52CE 我爱测

I have an EC2 instance authenticated with a key-pair generated by AWS. With Putty, I can connect to the instance by providing the private key in a PPK file. When I try to use SSH2 (via one of the NodeJs wrappers, e.g. through the…

问题原文

原帖链接 · sebf · CC BY-SA 4.0

I have an EC2 instance authenticated with a key-pair generated by AWS.

With Putty, I can connect to the instance by providing the private key in a PPK file.

When I try to use SSH2 (via one of the NodeJs wrappers, e.g. through the 'ssh2-sftp-client' module), it fails with an error:

getConnection: All configured authentication methods failed

And the auth.log on the instance reports,

sshd[1841]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

I know that OpenSSH has deprecated ssh-rsa but I am still not sure what is wrong here:

  • ssh-rsa seems to mean a number of things, and it appears only SHA1 has been deprecated. My key is SHA256 as reported by PuttyGen however so should still work, no?
  • If I understand right, changing from ppk to pem just changes the layout and encoding of the file, not the key value itself. If the OpenSSH server is the one doing the rejection, why does Putty work OK?

Does converting from PPK to PEM change the type of the key? If so, how can I convert PPK to PEM into something other than ssh-rsa?

The SSH (server) version is OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022

-- Edit because I can't comment yet --

@Tanjin Alam's answer is correct, and in AWS this can be done automatically when the machine is built by adding the following text to the User Data field in the launch template:

#!/bin/bash
sed -i '$aPubkeyAcceptedKeyTypes=+ssh-rsa' /etc/ssh/sshd_config
service sshd restart

已采纳解答

原帖链接 · Tanjin Alam · CC BY-SA 4.0

Goto

/etc/ssh #goto this directory
sudo nano sshd_config #edit the file
PubkeyAcceptedKeyTypes=+ssh-rsa #add this line and save and quit 
sudo systemctl restart sshd #restart sshd

Try again it will work

Reference : Click HERE

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-07-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。