↑ ↓ select, Enter open, Esc close

Make a remote port available locally with an SSH tunnel

Adjust the values, the command updates live
user@server
ssh -N -L 3307:127.0.0.1:3306 webuser@server.example.com

Forwards connections to 127.0.0.1:3307 on your own machine, encrypted, to port 3306 on the server. This lets you work on a database with a local client without exposing the port to the internet. -N only sets up the tunnel without opening a shell, stop it with Ctrl+C.

Note: The client must explicitly use 127.0.0.1 instead of localhost, otherwise MySQL tries a socket connection.

Also searched as

  • ssh tunnel to remote mysql
  • ssh local port forwarding example
  • access remote database through ssh

Related one-liners

All in SSH

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.