Mac OS X Snow Leopard, CentOS 6
A while back I wrote a few articles on improving security on your production server. A lot of chatter revolved around using non-standard ports for connecting via SSH. This affects other services that use SSH, such as Git, SFTP and others.
Today I’m going to show you a quick tip to set your SSH port permanently and spare you some typing.
Normally, an SSH connection would look like this:
$ ssh email@example.com
To improve security when connecting to the server, I suggested changing the port (on the server) so that your login would require a port to be specified, like so:
$ ssh -p 1234 firstname.lastname@example.org
This requires some other configuration to get certain services like Git and SFTP to work as expected. Take a look at these articles for more info:
- Secure SSH on CentOS 6 And RHEL
- Clone A Git Repository Using A Non-Standard Port
- Change Default FTP Port For VSFTP
- Git Pull & Push Using A Custom Port
We can save the extra -p 1234 part and a lot of configuration effort if we just change SSH’s default port on the local machine. It’s very easy to do:
$ vi ~/.ssh/config
And then we simply add the following lines:
Save and restart SSH. This means every time we ask for an SSH connection, the default port that will be requested is 1234. Easy!
You can specify different ports for different hosts by adding more Host definitions, like so:
Just make sure the last definition is your * one, the way I have it above.