首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >autossh不工作于rc.local

autossh不工作于rc.local
EN

Unix & Linux用户
提问于 2017-12-19 04:45:25
回答 1查看 3.8K关注 0票数 1

我通过机器A(本地的,在几个路由器后面)B(中间商)和C(远程的,我试图从A访问的机器)配置了反向ssh隧道。

把所有相关的钥匙放在所有机器上,如果我这样做的话

代码语言:javascript
复制
autossh -M 10984 -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no -i /home/user/.ssh/id_rsa.pub 9999:localhost:22 user@machine-B

在机器A上,我可以从机器C连接到机器B(中间人),通过端口9999连接到A。

现在,我补充说

代码语言:javascript
复制
autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no -i /home/user/.ssh/id_rsa.pub 9999:localhost:22 user@machine-B &

到我的/etc/rc.local文件中,这样命令就会在引导、重新启动时执行,现在隧道就不能工作了。我犯了个错误

代码语言:javascript
复制
autossh[1966]: starting ssh (count 14)
autossh[1966]: ssh child pid is 4916
autossh[1966]: ssh exited with error status 255; restarting ssh 

在赛斯日志上。

我的/etc/rc.local有:

代码语言:javascript
复制
autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B &
ethtool -s eth0 autoneg on
exit 0

知道我做错了什么吗?

更新:我注意到了

代码语言:javascript
复制
autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B

在命令行上工作,因此:

代码语言:javascript
复制
sudo autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B

使命令行提示我输入公钥密码,即使它没有附加密码。我在另一个堆栈问题(我找不到)上看到,-f标志阻止ssh请求进一步的输入。由于rc.local上的thigs作为根运行(据我所知),我认为这就是为什么autossh一直创建退出失败的ssh进程的原因。事实上,删除-f标志使ubuntu不断创建窗口,提示我输入密码。创建密钥时,我没有输入任何密码。

EN

回答 1

Unix & Linux用户

发布于 2018-01-09 09:56:48

我想你是在遵循这个网站的指示:https://raymii.org/s/tutorials/Autossh_持久的_tunnels.html

正如您正确地观察到的,尝试执行

代码语言:javascript
复制
sudo autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B

导致在启动时自动失败的附加提示。

一个简单的解决方案是将SSH密钥从“user”复制到root。

代码语言:javascript
复制
cp /home/user/.ssh/id_rsa.pub /root/.ssh/id_rsa.pub
cp /home/user/.ssh/id_rsa /root/.ssh/id_rsa -R

这对我来说没问题。复制是从“root”帐户执行的,因此所有权自动设置为“root”。然后从终端(而不是引导)运行autossh命令,这样主机就知道了。修改引导命令,将键的新路径包含在根文件夹中,您就设置好了。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/411731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档