Skip to content

Instantly share code, notes, and snippets.

@chriselgee
Last active July 13, 2023 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriselgee/761e66afc6449baf23d258199efe9ceb to your computer and use it in GitHub Desktop.
Save chriselgee/761e66afc6449baf23d258199efe9ceb to your computer and use it in GitHub Desktop.
SSH Callback Service
# SSH Callback Service
# Replace HOSTNAME with the VPS you're connecting to
# Replace USERNAME with your user on the VPS
# Replace LOCALUSER (or the whole path) to point to the private key for USERNAME on HOSTNAME
# Usage:
# - Try the SSH manually first, as the root user, so the VPS can be added to the known_hosts file
# - `systemctl enable callback.service`, `systemctl start callback.service`
# - SSH to the VPS from your system, and `ssh USER@127.0.0.1 -p22000 -i KEYNAME`, where USER is a user on the distant system and KEYNAME is an accepted key for that user
# Troubleshooting:
# - Ensure "GatewayPorts" is set to "Yes" in /etc/ssh/sshd_config on the VPS
# - `chmod 400 KEYNAME`
[Unit]
Description=Callback Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/ssh USERNAME@HOSTNAME -i /home/LOCALUSER/.ssh/id_rsa -NR 22000:127.0.0.1:22
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
Alias=callback.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment