autossh 使用
autossh 使用
Table of Contents
- 1. centos7下配置为服务
- 2. 命令式使用
- 2.1. 映射远程主机防火墙之后的端口到本机
- 2.2. 映射本机端口到远程主机
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 posted on 2018-12-16 10:46 BlackSwanYucatan 阅读( ...) 评论( ...) 编辑 收藏
转载于:https://www.cnblogs.com/BlackSwanYucatan/p/10125836.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
