mynote/linux/ssh.md
2025-11-21 18:59:25 +08:00

785 B

ssh 代理



# 将本地的 2017 端口映射到远程服务器的 8022 端口
ssh -R 8022:localhost:2017 user@ip -N

# 将远程服务器的 8022 端口映射到本地的 2017 端口
ssh -L 2017:localhost:8022 user@ip -N



auto ssh proxy

ssh -C -N -R remote_port:localhost:local_port username@remote_server

vim /etc/systemd/system/vautossh.service

[Unit]
Description=AutoSSH tunnel service for reverse port forwarding
After=network.target

[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/ssh  -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -C -N -R remote_port:localhost:local_port username@remote_server
Restart=always
User=your_username

[Install]
WantedBy=multi-user.target

systemctl daemon-reload systemctl enable vautossh.service