sh SSH反向隧道作为systemd服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh SSH反向隧道作为systemd服务相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash

: '
SOURCE node creates a tunnel to DESTINATION
This allows connections from DESTINATION to SOURCE with: ssh $USERNAME@localhost -p 19999
'

USERNAME=tunnel
PRIVKEY=/etc/tunnel/id_rsa
DESTINATION=ssh.example.com

cat << EOF | sudo tee /etc/systemd/system/sshtunnel.service
[Unit]
Description=SSH Tunnel
After=network.target

[Service]
Restart=always
RestartSec=20
# User=sshtunnel
ExecStart=/usr/bin/ssh -N -p 22 -o PubkeyAuthentication=yes -o ServerAliveInterval=60 -i $PRIVKEY -R 19999:localhost:22 $USERNAME@$DESTINATION

[Install]
WantedBy=multi-user.target
EOF

sudo chmod a+x /etc/systemd/system/sshtunnel.service
sudo chmod a+r /etc/systemd/system/sshtunnel.service
# sudo useradd sshtunnel

sudo systemctl enable sshtunnel.service
sudo systemctl start sshtunnel.service

以上是关于sh SSH反向隧道作为systemd服务的主要内容,如果未能解决你的问题,请参考以下文章

两步建立 ssh 反向隧道

基于 SSH 反向隧道的 Dockerized Telnet

自动杀死损坏的反向 ssh 隧道

通过反向 SSH 隧道访问 NAT 后面的 Linux 服务器

RaspberryPI 和云服务器中的反向隧道?

使用动态端口分配的反向 SSH 隧道