Use ssh-keys for authentication with MobaXterm

MobaXterm is also a more convenient ssh client like putty. Session management in the professional version is very handy. Since MobaXterm comes with cygwin, ssh is also available in the local terminal. To eliminate the hassle for entering the password (especially if security compliance requires you to change the password every month), ssh keys are a more secure and convenient method for authentication on severs. This post illustrates how you do it with MobaXterm.

Before using ssh, MobaXterm requires a persistent home directory. Go to Settings and set the persistent home directory.

Persistent Home Directory

First step is to generate the ssh key, therefore open a local terminal and generate a key (rsa) with this command:

ssh-keygen -t rsa

The output

Generating public/private rsa key pair.
Enter file in which to save the key (/home/mobaxterm/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mobaxterm/.ssh/id_rsa.
Your public key has been saved in /home/mobaxterm/.ssh/id_rsa.pub.
The key fingerprint is:
a8:68:33:c4:61:32:d0:08:93:f1:36:a9:6a:76:b2:c8 vinh@cinhtau
The key's randomart image is:
+---[RSA 2048]----+
|*=               |
|+o..             |
|o B              |
| B o   .         |
|. o   . S        |
|.. . .           |
|.+=..            |
|=.+o             |
|.E               |

The second step is to export the public key to the servers, with respective logins, to the authorized keys file. Replace user@host to your needs.

cat ~/.ssh/id_rsa.pub | ssh vinh@omega "cat - >> ~/.ssh/authorized_keys"

You may need to create the ssh folder first in your home directory on the remote machine.

mkdir ~/.ssh

or combine it within the ssh command

cat ~/.ssh/id_rsa.pub | ssh vinh@omega "mkdir .ssh && cat - >> ~/.ssh/authorized_keys"

Edit: After some instruction with my co-worker, you have to change the session to use the ssh-key (see picture below).

Private SSH Key