SSH: Forwarding privileged ports
Let's assume you have an access to a machine aliased as
tx2 in your
Host tx2 Hostname 126.96.36.199 User zaiste
Let's try to forward the port
ssh tx2 -L 80:localhost:80 Privileged ports can only be forwarded by root.
Let's try to overcome that with
sudo ssh tx2 -L 80:localhost:80 ssh: Could not resolve hostname tx2: Name or service not known
tx2 is a host configured in
~/.ssh/config. This can be fixed with
sudo ssh -F ~/.ssh/config tx2 -L 80:localhost:80
This tries to connect as
root user and prompts for a password.
We can use
-l $USER (or explicitly
-l zaiste) to set a proper user name.
-E to sudo preserves the environment allowing a proper SSH agent to be used.
sudo -E ssh -F ~/.ssh/config -l $USER tx2 -L 80:localhost:80