https://gist.github.com/rfairley/41f4a8e8b4c13f19d748ba4b0e600cc5
- Create ssh key pair.
- Disable password authentication by ensuring that
PasswordAuthenticationandChallengeResponseAuthenticationare set tonoin/etc/ssh/sshd_config - (If
sudo ufw statusis active) Allow external connections on JUMPHOST_PORT by configuring the firewall (any number above 1024 is good, 12345 used here)sudo ufw allow 12345/udp sudo ufw allow 12345/tcp sudo ufw enable - Add target machine's public ssh key to
~/.ssh/authorized_keys. - Add local machine's public ssh key to
~/.ssh/authorized_keys.
-
Disable password authentication by ensuring that
PasswordAuthenticationandKbdInteractiveAuthenticationare set tonoin/etc/ssh/sshd_config -
Add jumphost machine's public ssh key to
~/.ssh/authorized_keys. -
Add local machine's public ssh key to
~/.ssh/authorized_keys. -
Make sure openssh is installed:
sudo apt install openssh-server sudo systemctl enable ssh sudo systemctl start ssh sudo systemctl status sshVerify that it's actually working.
-
Add a reverse ssh systemd that automatically connects to the jumphost on boot as well as when it crashed to
/etc/systemd/system/call-vps.service:[Unit] Description=Reverse SSH connection After=network.target [Service] User=TARGET_MACHINE_USER ExecStart=/usr/bin/ssh -vvv -g -N -T -o "ServerAliveInterval 10" -o "ExitOnForwardFailure yes" -R UMPHOST_IP:JUMPHOST_PORT:localhost:22 JUMPHOST_USER@JUMPHOST_IP -i ~/.ssh/TARGET_MACHINE_PRIVATE_KEY_FILE Restart=always RestartSec=30s [Install] WantedBy=multi-user.target -
Enable the service:
sudo systemctl enable call-vps.service sudo systemctl start call-vps.service sudo systemctl status call-vps.serviceVerify that it's actually working.
-
Add the following to
~/.ssh/config:Host JUMPHOST_NAME Hostname JUMPHOST_IP IdentityFile ~/.ssh/LOCAL_MACHINE_PRIVATE_KEY_FILE User JUMPHOST_USER Host TARGET_NAME Hostname localhost Port JUMPHOST_PORT User TARGET_USER ProxyCommand ssh -q -W %h:%p JUMPHOST_NAMENote that
JUMPHOST_NAMEandTARGET_NAMEcan be anything.On windows, make sure ssh is installed and replace the
ProxyCommandline with:ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -q -W %h:%p JUMPHOST_NAME -
To connect to the target (or for rsync operations or whatnot as well), just do:
ssh TARGET_NAME