Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gembin
Last active March 15, 2018 07:18
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 gembin/3f1962b0135e32d20728aa58153f2ad6 to your computer and use it in GitHub Desktop.
Save gembin/3f1962b0135e32d20728aa58153f2ad6 to your computer and use it in GitHub Desktop.
SSH Port Forwarding on Mac OS X
ssh    -L local_port:service_host:service_port \
       -p ssh_server_port \
       -l ssh_server_username \
       -N \
       ssh_server_host

local_port: the port on your local machine that your local program expects to be able to connect to. If this is one of the reserved ports (i.e., under 1023), you will have to run your ssh tunnel command as root (using sudo). Ports above 1024 are freely available for any user to listen on.

service_host: the fully-qualified domain name or the IP address of the server that is hosting the service that you wish to connect to.

service_port: the port number on which the desired service is running

ssh_server_host: the machine that you’re SSHing into. This is the one that is running sshd, the SSH daemon.

ssh_server_port: the port number on which the SSH daemon is listening on ssh_server_host. This is most likely 22; you should only use a different value if your sysadmin has told you that the SSH server is running on another port (or if you’re a sysadmin yourself and you set up your SSH server to run on a non-standard port for security through obscurity.)

ssh_server_username: the username you would use to connect to ssh_server_host in a regular SSH session. This may or may not be the same as the username you currently use on your local machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment