SSH-问题处理记录

482 阅读2分钟

Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 [preauth]

堡垒机是老版本的,密钥不能更新,后续购入新机器在 ssh 时会得到上述报错。

解决办法: /etc/ssh/sshd_config 添加如下并 restart sshd 即可

KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

Permission denied (publickey,gssapi-with-mic). fatal: Could not read from remote repository.

有些 mac 系统不支持 rsa 算法,需要在 .ssh/config 增加一些配置才行

在 .ssh/config 中添加如下配置

Host *
     HostkeyAlgorithms +ssh-rsa
     PubkeyAcceptedAlgorithms +ssh-rsaHost *

Authorized users only. All activities may be monitored and reported. Please login as the user "openeuler" rather than the user "root".

PVE制作openEuler的qcow2模板后通过Cloud-init注入root账号、ip等信息后登录被提示如上。随后被强制退出,期间也无法输入命令。

通过openeuler账号登录查看sshd日志确认,

Starting session: forced-command (key-option) 'echo 'Please login as the user "openeuler" rather than the user "root".';echo;sleep 10;exit 142' on 

所以在authorized_keys中被加入了:

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user "openeuler" rather than the user "root".';echo;sleep 10;exit 142"

检查sshd_config中发现有两个PubkeyAuthentication yes,第一个在46行,第二个在141行,但46行的配置被注释了。

利用模板新建节点后,取消46行的注释,去除第141的配置,重新cloud-init启动,即可正常ssh root。

依据我对ssh的理解,141行的配置能生效,但实际上没有成功,对此表示不解。

后记

PVE注入root账号时将密码也注入就不会遇到这个问题。

拒绝端口转发 refused local port forward originator

open Euler 23.03

搭配VS Code 试图通过Remote SSH 远程开发。配置完善远程登录如本地Mac的/User/xxx/.ssh/config后,VS Code自动连接Euler后,在Euler里ps -efwww可以看见关于.vscode-server的进程,但是VS Code 左下角始终提示正在远程连接,且无法正常获取Euler目录。

通过systemctl status sshd后可得refused local port forward originator字样。

查看/etc/ssh/sshd_config后可见以下内容:

UsePAM yes
 
 #AllowAgentForwarding yes
 #AllowTcpForwarding yesUsePAM yes
 
 #AllowAgentForwarding yes
 #AllowTcpForwarding yes

默认理解该注释代表着默认配置,就忽略了继续查看后文,以至于我一直怀疑是iptables限制了自身端口转发。

实际上在后半篇配置中,有如下:

StrictModes yes
 AllowTcpForwarding no
 AllowAgentForwarding noStrictModes yes
 AllowTcpForwarding no
 AllowAgentForwarding no

将后半篇的AllowTcpForwarding 和 AllowAgentForwarding 的no修改为yes,并systemctl restart sshd。

重新打开VS Code远程连接即可正常连接。