Skip to content

Instantly share code, notes, and snippets.

@alkavan
Created June 15, 2024 19:52
Show Gist options
  • Save alkavan/27771b63b830c35d592c7aa36105a66a to your computer and use it in GitHub Desktop.
Save alkavan/27771b63b830c35d592c7aa36105a66a to your computer and use it in GitHub Desktop.
Advance SSH usage

SSH and SSH Tunnel Instructions

The secure and correct way to communicate with non-public services on a virtual server machine is via ssh tunnel (services like managment console or a database).

To create a simple ssh tunnel from your host machine to the server on the same port number:

ssh -L 9090:localhost:9090 god@kewldomain.com

However, you probably don't want to type this every time or remember the port numbers of each of your machines. In that case edit your local ssh config file ~/.ssh/config and add the following below other settings:

Host monitor.vps1
    HostName kewldomain.com
    User god
    LocalForward 9090 localhost:9090

Now you can just type ssh monitor.vps1 and it will connect the machine and open a secure tunnel to the service on port 9090 (no need to update the hostfile).

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