Mar*_*ark 5 ssh debian port-forwarding
我在使用 sshpass 进行端口转发命令时遇到问题。问题是它在一台服务器上工作而在另一台服务器上不起作用。两者都是 Debian 7 x64 机器。
sshpass -p password ssh -f -D 0.0.0.0:2002 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=debug root@5.5.5.5 -T -N
Run Code Online (Sandbox Code Playgroud)
此命令在服务器 1 上运行没有问题,但在服务器 2 上不起作用。
调试失败服务器的输出:
Authenticated to 5.5.5.5 ([5.5.5.5]:22).
debug1: Local connections to 0.0.0.0:2002 forwarded to remote address socks:0
debug1: Local forwarding listening on 0.0.0.0 port 2002.
debug1: channel 0: new [port listener]
debug1: forking to background
Run Code Online (Sandbox Code Playgroud)
工作服务器的调试输出:
Authenticated to 5.5.5.5 ([5.5.5.5]:22).
debug1: Local connections to 0.0.0.0:2002 forwarded to remote address socks:0
debug1: Local forwarding listening on 0.0.0.0 port 2002.
debug1: channel 0: new [port listener]
debug1: forking to background
debug1: Entering interactive session.
Run Code Online (Sandbox Code Playgroud)
两台服务器上的 sshpass 和 ssh 二进制文件是相同的。我已经使用 md5sum 检查过这一点。
有谁知道可能出了什么问题吗?我在试图解开这个谜团时失去了理智。
TL;DR
这对我有用:
sshpass -p password nohup ssh -f ... >/dev/null
Run Code Online (Sandbox Code Playgroud)
嗯,我也快失去理智了。导致sshpass
工作或不工作
的 debian 主机之间的差异在于 CPU 内核的数量。该问题出现在单核主机上。使用strace显示sshpass进程在收到SIGHUP后被系统终止。在多核主机上,分叉的ssh进程有足够的时间来设置SIGHUP处理程序,因此不会被终止。
作为解决方法,您可以使用nohup实用程序来运行sshpass,这样它就不会被SIGHUP杀死。
归档时间: |
|
查看次数: |
2691 次 |
最近记录: |