Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- sudo -i
- USERNAME=tunnel
- PRIVKEY=/etc/tunnel/id_rsa
- DESTINATION=ssh.example.com
- cat << EOF > /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
- chmod a+x /etc/systemd/system/sshtunnel.service
- chmod a+r /etc/systemd/system/sshtunnel.service
- # useradd sshtunnel
- systemctl enable sshtunnel.service
- systemctl start sshtunnel.service
- # TEST from $DESTINATION: ssh $USERNAME@localhost -p 19999
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement