在 Ubuntu 上安裝 autossh
打開終端窗口並運行以下命令
sudo apt-get install autossh
Autossh 語法
autossh [-V] [-M port[:echo_port]] [-f] [SSH_OPTIONS]
在啟動時啟動 ssh 通道
我們可以使用 upstart 來在 Ubuntu 下啟動 ssh 通道,只需要將如下 autossh.conf 文件放在 /etc/init 目錄即可。
# autossh startup Script description "autossh daemon startup" start on net-device-up IFACE=eth0 stop on runlevel [01S6] respawn respawn limit 5 60 # respawn max 5 times in 60 seconds script export AUTOSSH_PIDFILE=/var/run/autossh.pid export AUTOSSH_POLL=60 export AUTOSSH_FIRST_POLL=30 export AUTOSSH_GATETIME=0 export AUTOSSH_DEBUG=1 autossh -M 0 -4 -N USER@HOSTNAME -D 7070 -o "ServerAliveInterval 60″ -o "ServerAliveCountMax 3″ -o BatchMode=yes -o StrictHostKeyChecking=no -i SSH_KEY_FILE_PATH end script