即使使用绝对path也无法在后台使用autossh

我很想设置autossh启动运行,将其添加到/etc/rc.local

这个命令的作用:

autossh -i /root/.ssh/id_rsa -R 2522:localhost:22 user@address

但是,如果我添加-f选项

autossh -f -i /root/.ssh/id_rsa -R 2522:localhost:22 user@address

ssh会话没有启动。

正如你所看到的,我正在使用我的身份文件的绝对path,所以这似乎是一个不同于这里所述的问题: 在后台autossh不起作用

/var/log/syslog

 Oct 18 11:08:39 raspberrypi autossh[2417]: starting ssh (count 1) Oct 18 11:08:39 raspberrypi autossh[2417]: ssh child pid is 2418 Oct 18 11:08:39 raspberrypi autossh[2417]: ssh exited with status 0; autossh exiting 

我使用它与debian wheezy在树莓派,autossh版本1.4C。

难道是它将-f选项传递给ssh吗?

当你不使用-f启动autossh时,你会得到一个shell。 当shell正在工作时,您将获得端口转发。 注销后,ssh以退出代码0结束,autossh知道不需要再次启动ssh会话。

当你用-f启动autossh时,它也会把-f传给ssh。 然后SSH在后台运行,并不会给你一个shell。 由于您没有指定任何其他标志或远程命令,ssh立即以状态0退出(不需要做任何事情),并且autossh不会启动它。

只需要添加-N选项来避免它:

 -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only) 

喜欢这个:

 autossh -f -N -i /root/.ssh/id_rsa -R 2522:localhost:22 user@address