I keep learning new amazing stuff that SSH can do for me. Recently I had to connect to a postgres database which was only accessible from the university network. After a bit of googling I found a way to connect to a remote database via an SSH tunnel:

1
[burger@meepo $] ssh -L 31337:localhost:5432 user@database-server.tld

This basically opens an SSH connection to database-server.tld and connects your local port localhost:31337 to the remote port database-server.tld:5432.

This was pretty close to what I wanted, but not exactly: I had no SSH account on the machine running the database, but only on some other university PC. None of the ‘SSH tunneling HowTos’ stated it, but the solution is straightforward, and kind of intuitive, too:

1
[burger@meepo $] ssh -L 31337:database-server.tld:5432 user@university-machine.tld

This creates a normal connection between some port on the university-machine.tld and the database, and forwardsthat over ssh to my local meepo. Pretty cool, ain’t it? ¯\_(ツ)_/¯