autossh 使用


centos7下配置为服务

编辑服务配置文件

cat  /usr/lib/systemd/system/autossh.service

[Unit]
Description=Auto SSH Tunnel
After=network-online.target
[Service]
User=yoo
Type=simple
ExecStart=/bin/autossh -p 22 -M 12340 -NR '*:12345:127.0.0.1:22' pi@yourip -i /home/yoo/.ssh/id_rsa
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -TERM $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
WantedBy=graphical.target

开机启动与取消

[root@centos7proxy ~]# systemctl disable  autossh.service
Removed symlink /etc/systemd/system/multi-user.target.wants/autossh.service.
Removed symlink /etc/systemd/system/graphical.target.wants/autossh.service.
[root@centos7proxy ~]# systemctl enable  autossh.service
Created symlink from /etc/systemd/system/multi-user.target.wants/autossh.service to /usr/lib/systemd/system/autossh.service.
Created symlink from /etc/systemd/system/graphical.target.wants/autossh.service to /usr/lib/systemd/system/autossh.service.

命令式使用

映射远程主机防火墙之后的端口到本机

ssh -L localhost:3306:localhost:3306 test.domain
autossh -NL localhost:3306:localhost:3306 test.domain

映射本机端口到远程主机

ssh -p 22 -qngfNTR 8080:127.0.0.1:8080 test.domain
autossh -p 22 -M 6777 -NR 8080:127.0.0.1:8080 test.domain


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM