将 KexAlgorithms 和 MAC 添加到 sshd_config 后无法通过 SSH 进入服务器

将 KexAlgorithms 和 MAC 添加到 sshd_config 后无法通过 SSH 进入服务器

将以下几行附加到 的末尾后/etc/ssh/sshd_config

KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

MACs [email protected],[email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected],hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96

并重新启动 ssh

sudo /etc/init.d/ssh restart

我发现自己无法再通过 ssh 进入实例。

ssh -i xxxxx.pem -vvvv [email protected]                                                                                                            
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: resolve_canonicalize: hostname xx.xx.xx.xx  is address
debug2: ssh_connect_direct
debug1: Connecting to xx.xx.xx.xx  [xx.xx.xx.xx ] port 22.
debug1: connect to address xx.xx.xx.xx  port 22: Connection refused
ssh: connect to host xx.xx.xx.xx  port 22: Connection refused

我是不是完全没运气了,还是说当我尝试从客户端使用时,通过指定一些特定的东西-m,我是否还有机会?这超出了我的能力范围,所以任何建议都值得感激。-oKexAlgorithmsssh

答案1

我用另一个实例进行了测试,思考盲目地将这两行附加到 sshd_config 会导致配置无效,所以当我重新启动 ssh 守护程序时,它无法启动,所以我会被锁定。

幸运的是,这是一个 EC2 实例,我可以停止并编辑该实例的用户数据,这样我就可以让 Cloud Init 运行一些命令,使用我在搞乱一切之前创建的备份文件来恢复 sshd_config。

例如用户数据

#cloud-config
bootcmd:
 - cp /etc/ssh/sshd_config_bak /etc/ssh/sshd_config
 - /etc/init.d/ssh restart

有一次,我确认我能够通过 SSH 进入,我再次停止了实例,恢复了用户数据(因此下次实例启动时不会再次运行这些命令)并重新启动了实例。

相关内容