SSH and Transfer Files using Putty Private Key (.ppk)

For a concise summary, skip to the end!

Recently, I was given access to a server which requires key authentication using a PuTTY key (with the extension .ppk).

So I tried the usual:

$ ssh -i /path/to/my_key.ppk username@host

But it asked me for a passphrase, which I never set:

Enter passphrase for key '/path/to/my_key.ppk'

After some digging around, it turns out PuTTY uses a different key format than the de facto standard - OpenSSH.

Because of this, ssh didn't recognise the key format and assumed it was encrytped by a passphrase.

So there are two ways you can use the PuTTY key to login to the server and/or transfer files:

  • Convert the PuTTY private key (.ppk) to a PEM-formatted file (the 'normal' private key format used by OpenSSH) and ssh/sftp in the usual way; or
  • Use a PuTTY SSH client to login and pscp to transfer files

Converting the .ppk to PEM

This is probably the most convenient way as you only have to run one command and everything would be like it was before:

puttygen my_key.ppk -O private-openssh -o openssh_key

Now you can run the command again as before, but this time you should be granted access automatically.

$ ssh -i /path/to/openssh_key username@host
[username@host ~]$

The same is true for sftp:

$ ssh -i /path/to/openssh_key username@host
Connected to host.
sftp >

Use a PuTTY SSH client to login and pscp to transfer files

Login using PuTTY SSH Client

First, download the PuTTY SSH Client. If you're using a Linux distribution, check the package repositories as well (PuTTY is such an old ancient program you practically don't need to ensure it's up-to-date)

Open up the client and under Session, input your host's name or IP address. If you're server's default SSH port has been changed, input the port number too.

Next, go to SSH > Auth and browse for your private key.

After that, click 'Open'.

It will prompt you for the username, enter it

login as:

and if your credentials are correct, be given access to the server.

login as: username  
Authenticating with public key "rsa-key-username"  
[username@host ~]$
Transferring Files using pscp

Transferring files the pscp command is similar to using the sftp command:

$ pscp -sftp -r -i /path/to/my_key.ppk /path/on/local/to/transfer/files/from/ username@host:/path/on/remote/to/transfer/files/to/

The -r flag tells pscp to transfer all the files recursively inside the directory, sftp forces pscp to use the the SFTP protocol (instead of SCP) and the -i flag allows you to specify the key to use.

Read about the Difference between the SCP and SFTP Protocols on SuperUser.

For a full list of options, run pscp -h

Summary

To login using a .ppk key, you can:

  • Convert it to a PEM-formatted OpenSSH key and use ssh normally:

    puttygen my_key.ppk -O private-openssh -o openssh_key
    
  • Download and use the PuTTY client

To transfer files using a .ppk key, you can:

  • Convert it to a PEM-formatted OpenSSH key and use ssh normally:

    puttygen my_key.ppk -O private-openssh -o openssh_key
    
  • Use pscp

    pscp -sftp -r -i /path/to/my_key.ppk /path/on/local/to/transfer/files/from/ username@host:/path/on/remote/to/transfer/files/to/
    
comments powered by Disqus