在后台autossh不起作用

我通过autosshbuild立了一个隧道。

这工作:

autossh -M 33201 -N -i myIdFile -R 33101:localhost:22 [email protected] 

我想在后台运行autossh。 似乎很容易使用-f选项。

但是这不起作用:

 autossh -f -M 33201 -N -i myIdFile -R 33101:localhost:22 [email protected] 

Autossh在后台运行正常,但ssh连接似乎每次都失败。 在/ var / syslog中,我看到多个出现的:

 autossh[3420]: ssh exited with error status 255; restarting ssh 

我究竟做错了什么? 一个疯狂的猜测是它与通过密钥文件进行身份validation有关。 我怎样才能debugging(添加-v到ssh选项似乎不logging任何地方)。

编辑:我有一些使用-y选项的ssh日志

 /usr/bin/ssh[3484]: debug1: Next authentication method: publickey /usr/bin/ssh[3484]: debug1: Trying private key: /home/myuser/.ssh/id_rsa /usr/bin/ssh[3484]: debug1: Trying private key: /home/myuser/.ssh/id_dsa /usr/bin/ssh[3484]: debug1: Trying private key: /home/myuser/.ssh/id_ecdsa /usr/bin/ssh[3484]: debug1: No more authentication methods to try. /usr/bin/ssh[3484]: fatal: Permission denied (publickey). autossh[3469]: ssh exited with error status 255; restarting ssh 

所以当使用-f选项时,似乎autossh不接受我的标识文件( -i myIdFile )。 这是为什么?

(Raspian上的autossh 1.4c)

看起来像autossh下降到后台(-f选项)它正在改变工作目录,意味着相对path不再工作。 或者更具体的:通过input你的id文件的绝对path,你可能会成功。

我通过在非默认位置创build没有密码的密钥重新创build了该场景:

 ~/$ mkdir test ~/$ cd test ~/test$ ssh-keygen -f test_id_rsa 

我只需要input两次来生成一个不受密码保护的密钥。

我将新密钥复制到我的服务器(目前允许密码authentication):

 ~/test$ ssh-copy-id -i test_id_rsa user@server 

首先我确认了这个键是用普通的ssh,然后像你一样使用autossh:

 ~/test$ ssh -i test_id_rsa user@server ~/test$ autossh -M 13000 -N -i test_id_rsa user@server ^C 

他们都很好,所以我重新创build了你的问题:

 ~/test$ autossh -f -M 13000 -N -i test_id_rsa user@server 

这没有奏效,下面写到/var/log/syslog

autossh [2406]:ssh提前退出状态255; autossh退出

通过改变密钥文件的path是绝对的,它工作,虽然:

 ~/test$ autossh -f -M 13000 -N -i /home/user/test/test_id_rsa user@server 

/var/log/syslog没有错误。

不知道-f是怎么回事,但是你也可以禁用它:

 nohup autossh -M 33201 -N -f -i myIdFile -R 33101:localhost:22 [email protected] &