Leo*_*sar 2 linux ssh upstart ubuntu-12.04
我有一份新贵的工作/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
Run Code Online (Sandbox Code Playgroud)
当我查看/var/log/upstart/tunnel.log:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
Run Code Online (Sandbox Code Playgroud)
但如果我从终端尝试
autossh -R 12345:localhost:22 myuser@myserver
Run Code Online (Sandbox Code Playgroud)
它连接到我的服务器而不要求我输入密码(我已经复制了 SSH 密钥)
当我使用sudo:
sudo autossh -R 12345:localhost:22 myuser@myserver
Run Code Online (Sandbox Code Playgroud)
它要求我提供 myserver 密码,所以我想这就是我在新贵工作中遇到的问题。为什么 SSH 要求我输入密码,我们以 root 身份运行它?
mas*_*oeh 10
当autossh被sudo或 init 进程调用时, autossh使用root用户提供的 identity/ssh-keys 文件(例如/root/.ssh/sshkeys)。当您尝试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
Run Code Online (Sandbox Code Playgroud)
Autossh 中的更多信息与 Ubuntu Upstart