How to get ssh to automatically use a certain port for a specific server?

Ghopper21 asked:

I use ssh to get into a specific server on a specific port as normal:

ssh -p <port_number> <server_name>

How do I configure ssh to automatically use the right port number for a specific server, so that I don’t have to enter the -p <port_number> parameter? Note different servers I connect to will have different port numbers.

My answer:

Put it in your $HOME/.ssh/config file. For example:

    Port 2222

Host *
    Port 22

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.