端口 22:连接被拒绝,但只有 60% 的时间

端口 22:连接被拒绝,但只有 60% 的时间

我正在运行这个:

ssh_command = f'ssh -vvv -o StrictHostKeyChecking=no -i {private_key_file} ubuntu@{public_ip}'

# Use os.system to execute the SSH command in a subshell
os.system(ssh_command)

但是,这只有 40% 的时间有效。我见过的所有调试要么 100% 有效,要么 100% 无效。据我所知,我的连接性并不不稳定。我正在 ssh 进入 EC2。

我经常会收到这个错误:

OpenSSH_9.4p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname [...] is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/scott/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/scott/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: ssh_connect_direct: entering
debug1: Connecting to [...] [[...]] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: connect to address [...] port 22: Connection refused
ssh: connect to host [...] port 22: Connection refused

我使用的是 MacOS 14.2.1,但正在通过 ssh 连接到 Ubuntu 服务器。当我手动 ssh 时,没有遇到任何问题。

相关内容