openbsd的初始化脚本ssh VPN隧道

我有一个服务器托pipeSSH隧道和Openbsd 4.5客户端连接到它。

事情工作得很好,但我需要自动从客户端到服务器的连接。 因此,如果客户端意外重新启动,则连接启动无人值守。

所以它应该像在init脚本中包含ssh连接一样简单。 然而,我很悲剧地没有把它包含到/etc/rc.local中,这是我通常做这种事情的文件。

现在,我正在使用autossh来重新启动连接,如果需要的话,我把脚本放在/etc/rc.local如下:

#!/bin/sh # # Example script to start up tunnel with autossh. # # This script will tunnel 2200 from the remote host # to 22 on the local host. On remote host do: # ssh -p 2200 localhost # # $Id: autossh.host,v 1.6 2004/01/24 05:53:09 harding Exp $ # ID=root HOST=example.com #AUTOSSH_POLL=600 #AUTOSSH_PORT=20000 #AUTOSSH_GATETIME=30 #AUTOSSH_LOGFILE=$HOST.log #AUTOSSH_DEBUG=yes #AUTOSSH_PATH=/usr/local/bin/ssh export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT autossh -2 -f -M 20000 ${ID}@${HOST} 

手动运行时脚本分离得很好,所以我只是把它包含在/etc/rc.local中

 echo -n 'starting local daemons:' if [ -x /usr/local/sbin/autossh.sh ]; then echo -n 'ssh tunnel' /usr/local/sbin/autossh.sh fi echo '.' 

我也尝试从/etc/hostname.tun0调用它,以防万一在networking连接准备就绪的时候/etc/rc.local没有被调用,所以我会使用:

 inet 10.254.254.2 255.255.255.252 10.254.254.1 !/usr/local/sbin/autossh.sh 

您的意见非常感谢。

我没有完全理解你的问题:你确定你的autossh运行? 如果在重新启动时没有find隧道,可能是因为没有启动,或者由于错误而立即完成。 如果要检查它,可以在“logger”命令中插入一个调用,并在运行autossh之前和之后通过sysloglogging一条消息,以确保它已经运行。 请在第二次调用“logger”命令时包含shell $ rcvariables。

另一个select是从/ etc / inittab运行ssh(不带autossh),就像这个问题所解释的那样: rc.local中的runuser