Ubuntu 22.04 ssh 问题

Ubuntu 22.04 ssh 问题

我最近在两台不同的计算机上升级到 Ubuntu 22.04 LTS,它们有一个令人困惑的行为:

  • 通过这些 22.04,我可以毫无问题地连接到本地网络中的其他人
  • 从这些 22.04 我无法连接到外部计算机,长时间延迟和超时(见下文)
  • 我的本地网络中还有一个 Ubuntu 20.04.3 LTS,我可以从 20.04 连接到同一台外部计算机
  • 我可以从那台外部计算机连接到 22.04 计算机

我认为这个问题:

  • 与防火墙无关,我没有安装任何防火墙,或者路由器问题
  • 与 RSA 问题无关,我在所有计算机上共享相同的密钥
  • 跟端口没关系,我使用默认的22端口

在这里找到完整的详细输出,希望它有所帮助:

alice:~$ ssh -vvv externalHost
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/user/.ssh/known_hosts2'
debug2: resolving "externalHost" port 22
debug3: resolve_host: lookup external-host:22
debug3: ssh_connect_direct: entering
debug1: Connecting to externalHost [XXXXX] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: connect to address XXX port 22: Connection timed out
ssh: connect to host externalHost port 22: Connection timed out*

使用 strace 我检测到了最后的系统调用,当执行在超时之前被阻止时

...
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, [128 => 16]) = 0
getpid()                                = 10276
setsockopt(3, SOL_IP, IP_TOS, [16], 4)  = 0
connect(3, {sa_family=AF_INET, sin_port=htons(22), sin_addr=inet_addr("externalHost-IPaddress")}, 16) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)

答案1

由于我无法发表评论,因此我将把它作为答案。我遇到了同样的问题,经过几个小时的搜索,找到了可以解决该问题的方法。

我补充道

 IPQoS none

到我的 /etc/ssh/ssh_config

看起来上一个版本的 ssh 客户端发生了一些变化,并且无法与本地路由器进行通信。

我希望它有帮助。

答案2

如果仍然不起作用,请尝试

GSSAPIAuthentication no

答案3

如果不起作用,那么您可以尝试在/etc/ssh/sshd_config文件中注释以下行。

KbdInteractiveAuthentication no

并重启 ssh 服务, systemctl restart ssh

相关内容