In the last months I have been working with MPI. In particular, with OpenMPI. The basis of the work of OpenMPI consist in SSH-ing without password to the nodes that are part of a parallel calculation.
The problem is that in my case I was not using the default SSH port because I was trying to use OpenMPI with Docker and the SSH server is mapped to other port (in a later post I will write about this). And so this time I learned…
How to automatically SSH to a non-default port and other cool things of SSH
Yes, I know that I can SSH to a non default port using a syntax like this one:
$ ssh firstname.lastname@example.org -p 4000
But the problem is that in some cases I cannot change the commandline. As an example, when using OpenMPI, it is not possible to modify the port to which the master will SSH the slaves. It will just ssh the slaves.
At the end, SSH has the possibility of creating a ssh-config file that enables to change the port to which the SSH client will try to connect, and also will enable to configure some other cool things. I found a very straightforward explanation about the SSH config file in this post.
So making that a ssh email@example.com will connecto to the port 4000 without including it in the commandline will consist in creating a file named $HOME/.ssh/config with the following content:
Hostname my.server Port 4000
I am used to use the ssh config file, but I did not know about its potential. In particular, I didn’t know about the possibility of changing the default port. Digging a bit on it, the ssh-config is powerful, as it enables to avoid the annoying messages about the host keys in a internal network, to assign aliases to hosts or even to enable the port forwarding.
An example of config file that I use to SSH the internal nodes of my clusters is the next one:
Host node* StrictHostKeyChecking no UserKnownHostsFile /dev/null
And well… now I know that I can change the port of the SSH server (perhaps to avoid attacks from users).