生成密钥
sh
ssh-keygen -t ed25519 -C "node01"
客户端保持连接
sh
vi /etc/ssh/ssh_config
sh
# 在客户端配置
ServerAliveInterval 30
auto ssh
sh
vi /root/ssh_proxy.py
py
import os
with os.popen('ps x | grep ssh') as ps:
ps_response = ps.read()
if '1.1.1.1' not in ps_response:
os.system('ssh root@1.1.1.1 -fgnNC -D7890')
sh
crontab -e
sh
* * * * * /usr/bin/python3 /root/ssh_proxy.py