Remote connect using private key of Putty by terminal

By | 2021-04-23

When we want to connect a remote host with private key by Windows, we can use a graphics tools such as Putty. After upgrading Windows 10 to version 20H2, WSL2 (Windows Subsystem for Linux version 2) is available to be used. After installing WSL2, I installed Ubuntu. However, when I tried to connect a remote host by terminal of Ubuntu, I got some errors and could’t connect successfully. After investigation, I found the below solution.

The command of connecting remote host with a private key by Ubuntu terminal is shown as follows.

$ssh -i paivate-key.ppk userid@hostname

When excuting the above command, the following error was displayed.

Load key "private-key.ppk": invalid format
userid@hostname: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

The meaning of this error is that Putty’s private key cannot be used by Ubuntu terminal, and it is necessary to convert it to a format that can be used in the Ubuntu terminal. The details of convert private key is shown as follows.

convert private key with Puttygen

The first step is executing Puttygen and load private key by selecting [File] ->[Load private key] from the menu. Then, select [Conversions]->[Export OpenSSH key] from the menu to export the private key that can be used by Ubuntu terminal. Then set the permissions of the new private key to “600”.

When I tried to connect to remote host with the new private key by Ubuntu terminal, the following error as displayed.

sign_and_send_pubkey: no mutual signature supported

The reason of the above error seems to be that the current OpenSSH rejected the old ancryption method “ssh-dss”. The solution is to add the following setting in file “~ / .ssh / config” to avoid it.

~ / .ssh / config
Host hostname
  HostKeyAlgorithms ssh-dss
  PubkeyAcceptedKeyTypes ssh-dss

If the encryption method is specified in Cipher, it is necessary to add “+”.

~ / .ssh / config
Host hostname
  HostKeyAlgorithms + ssh-dss
  PubkeyAcceptedKeyTypes + ssh-dss

With the above, the remote connection was successfully established in the Ubuntu terminal.