Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. sudo -i
  3.  
  4. USERNAME=tunnel
  5. PRIVKEY=/etc/tunnel/id_rsa
  6. DESTINATION=ssh.example.com
  7.  
  8. cat << EOF > /etc/systemd/system/sshtunnel.service
  9. [Unit]
  10. Description=SSH Tunnel
  11. After=network.target
  12.  
  13. [Service]
  14. Restart=always
  15. RestartSec=20
  16. # User=sshtunnel
  17. ExecStart=/usr/bin/ssh -N -p 22 -o PubkeyAuthentication=yes -o ServerAliveInterval=60 -i $PRIVKEY -R 19999:localhost:22 $USERNAME@$DESTINATION
  18.  
  19. [Install]
  20. WantedBy=multi-user.target
  21. EOF
  22.  
  23. chmod a+x /etc/systemd/system/sshtunnel.service
  24. chmod a+r /etc/systemd/system/sshtunnel.service
  25. # useradd sshtunnel
  26.  
  27. systemctl enable sshtunnel.service
  28. systemctl start sshtunnel.service
  29.  
  30. # TEST from $DESTINATION: ssh $USERNAME@localhost -p 19999
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement