我有一个暴发户的工作/etc/init/tunnel.conf :
description "SSH Tunnel" start on (net-device-up IFACE=eth0) stop on runlevel[016] respawn exec autossh -nNT -o ServerAliveInterval=15 -R 12345:localhost:22 myuser@myserver
当我看到/var/log/upstart/tunnel.log :
Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-with-mic,password).
但如果我尝试从terminal
autossh -R 12345:localhost:22 myuser@myserver
它连接到myserver而不要求我input密码(我已经复制了SSH密钥)
当我使用sudo运行它时:
sudo autossh -R 12345:localhost:22 myuser@myserver
它问我为我的服务器密码,所以我想这是我的暴发性工作的问题。 为什么SSH要求我input密码,我们以root身份运行它?
当sudo或init进程调用autossh , autossh使用root用户提供的identity / ssh-keys文件(例如/root/.ssh/sshkeys )。 当您尝试从terminal运行autossh时,也许使用非root用户。 因此, autossh使用该用户提供的身份/ ssh-keys文件(例如/home/non-root/.ssh/sshkeys )。
为了得到预期的行为,你可以在tunnel.conf提供标识文件。 要做到这一点,修改最后一行
exec autossh -nNT -i /home/non-root/.ssh/sshkeys -o ServerAliveInterval=15 -R 12345:localhost:22 myuser@myserver
有关Ubuntu Upstart Autossh的更多信息