autossh自动自动重连
先安装autossh 树莓派安装命令 apt-get install update,apt-get install upgrade,apt-get install autossh;
其次,做免密登录:略,有空再补充
目标机代码如下:
from Base.setting import setting import os def start_autoSSH(): GuardianID = setting.mncode[-4:] GuardianID = str(int(GuardianID)+8000) command = 'autossh -M 5678 -NfR %s:localhost:22 root@%s' % (GuardianID,setting.ssh_server) print(command) os.system(command) start_autoSSH() # ssh -NfR 1011:localhost:22 root@47.97.102.118