Skip to content

Instantly share code, notes, and snippets.

@EarthlingDavey
Created February 5, 2020 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EarthlingDavey/cef6a2bf8474f5ae536086e678c7ce50 to your computer and use it in GitHub Desktop.
Save EarthlingDavey/cef6a2bf8474f5ae536086e678c7ce50 to your computer and use it in GitHub Desktop.
Adapted from: https://www.joshcurry.co.uk/posts/ssh-create-a-tunnel-only-user-for-reverse-tunnels
sudo useradd -m tun-user
sudo nano /etc/ssh/sshd_config
Match User tun-user
AllowAgentForwarding no
PasswordAuthentication no
X11Forwarding no
GatewayPorts no
PermitTunnel no
ForceCommand echo 'Port binding... ctrl + c to exit'
AllowStreamLocalForwarding no
#AllowTcpForwarding remote
PermitOpen localhost:9009
sudo su tun-user
ssh-keygen -t rsa -b 4096
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
And now, copy ~/.ssh/id_rsa or a different keyfile if you used that, to the remote machine which you will be forwarding from.
exit to usual user.
cp /bin/bash /bin/rbash
usermod -s /bin/rbash tun-user
On local machine
ssh -i ~.ssh/id_rsa_tun_user -l tun-user -L 9999:localhost:9009 33.22.11.69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment