By | 2020-04-05

SSH远程转发命令

ssh -NCfR 2222:localhost:22 root@test #将本地主机22端口转发至远程主机2222端口

SSH本地转发命令

ssh -NCfL 23:localhost:23 root@test #将远程主机23端口转发至本地主机23端口

SSH动态转发命令

ssh -NCfD 1080 root@test #将本地1080端口流量通过代理隧道转发至服务器所在网络

添加Autossh.service服务实现开机启动

#file path /lib/systemd/system/autossh.service

[Unit]
Description=autossh
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Environment="AUTOSSH_GATETIME=0"
User=root
Group=root
WorkingDirectory=/root
ExecStart=/usr/bin/autossh -M 0 -CNR 22:127.0.0.1:22 -i /root/.ssh/id_rsa root@test
Restart=always
RestartSec=10
KilMode=process
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target

服务操作命令

systemctl enable autossh  #设置开机自启
systemctl disable autossh #删除开机自启
systemctl status autossh  #查看服务状态
systemctl start autossh   #启动服务
systemctl stop autossh    #停止服务
systemctl restart autossh #重启服务

发表评论