引导时重新启动autossh反向隧道的问题

时间:2018-11-10 04:48:03

标签: linux boot ssh-tunnel autossh rc.d

我似乎有一个奇怪的问题: 我想在启动时重新启动反向ssh隧道,我已经尝试使用init脚本(当以用户身份执行时效果很好)并在/etc/rc.d中添加了一行,但没有任何效果。开机后我得到的是:

$ ps ax  | grep autossh
  397 pts/10   S+     0:00 grep --color=auto autossh
 1351 ?        Ss     0:00 /usr/lib/autossh/autossh -M 22221    -N -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu@server

但是我无法从server登录。所以我在启动后做了以下事情:

$ sudo killall -KILL autossh
[sudo] password for ron: 
$ /usr/bin/autossh -M 22221 -f -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu@server

我可以使用端口19999登录了!

密钥权限看起来像:(但是root不需要关心,对吗?)

$ ls -l ~/.ssh/etherwan.key
-r-------- 1 ron ron 1675 Nov  6 04:15 /home/ron/.ssh/etherwan.key

1 个答案:

答案 0 :(得分:1)

在{em> rc.d 脚本中用~/.ssh/etherwan.key

替换/home/ron/.ssh/etherwan.key

shell将'〜'字符扩展到用户的主目录,但是 rc.d 脚本以root身份运行。