注意:这篇文章不是SSH 远程端口转发失败的重复。这里的问题不是导致端口转发(暂时)失败的原因,我们知道它是什么。问题是如何删除损坏的 sshd 端口绑定。谢谢。
我有一台具有动态 IP 的服务器 A,运行 autossh,以维护到具有静态 IP 的计算机 B 的反向隧道。下面的代码工作正常:
autossh -M 0 -q -N -R2222:localhost:22 -o ServerAliveInterval 60 -o ServerAliveCountMax 3 -o ExitOnForwardFailure yes USER@B -p PORT
Run Code Online (Sandbox Code Playgroud)
然而,当由于 A 的 IP 更改而导致连接崩溃时,需要“很长”的时间(比如一个小时)才能恢复连接。这是因为来自机器 B 的 sshd 仍然监听端口 2222,从而阻止了 ssh(来自机器 A)在崩溃后绑定端口 2222。
B 的 auth.log 包含数十条:
Accepted publickey for USER from A port SOMEPORT ssh2: ED25519 XXXXXXXX
error: bind: Address already in use
error: channel_setup_fwd_listener_tcpip: cannot listen to port: 2222 …
Run Code Online (Sandbox Code Playgroud) 将身份文件重命名id_ed2519_2(.pub)
为 后id_ed2519(.pub)
,
ssh-copy-id
可以使用文件id_ed25519
(它要求输入密码)连接到远程服务器,而ssh
不能,除非我添加一个身份文件选项(它要求输入密码):
$ ssh-copy-id -n remoteserver
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
Enter passphrase for key '/home/helloworld/.ssh/id_ed25519':
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
$ ssh remoteserver
no such identity: /home/helloworld/.ssh/id_ed25519_2: No such file or directory
Permission denied (publickey).
$ ssh remoteserver -i ./ssh/id_ed25519
Enter passphrase for key 'id_ed25519':
Run Code Online (Sandbox Code Playgroud)
怎么可能ssh-copy-id …