I set up my Linux server to accept connections from my home PC by adding the public key generated by PuTTYgen to the authorized_keys
file.
Now I'm trying to connect to the same machine, but this time from another Ubuntu machine. I have to use the same private key (for a weird reason, don't ask..) and I don't quite get how to install it on my client Ubuntu.
Do I have to convert it to some other format?
By coincidence, I just had to do this. You do need to convert the keys to OpenSSH format. The command for doing that is:
then you can copy the contents of
openssh_key
in to.ssh/authorized_keys
just as with a normal SSH key.The
-i
option is the one that tellsssh-keygen
to do the conversion. The-f
option tells it where to find the key to convert.This works for unencrypted keys. The public key is unencrypted, but the private one is probably encrypted. I'm not sure if it there's a way to unencrypt the private key, convert it, and then recrypt it. It may well be easier to use new keys as the other answer suggests (and I'd recommend using
ssh-agent
though that's orthogonal to the current issue).Andrew Stacey explained how to convert the keys to OpenSSH format on Linux.
If you want to do the same on Windows, follow these steps:
I am not sure if your private key will work in ubuntu, but its worth a shot. just copy the keys to
/home/yourName/.ssh/
name the private key asid_rsa
, and the public key asid_rsa.pub
.If that is not working, then you can create you own ssh key-pair using
ssh-keygen
and copy the new public key to the server, and ssh as followsI haven't played with it, but I hear that ssh-agent can also be used to manage ssh-keys.
How to re-use your Putty key pairs in Ubuntu as OpenSSH keys:
Since purpose of step 4 is to add your public key to *~./ssh/authorized_keys*, so you can use your Putty secret key like this instead of doing 4 as an intermediate step:
PuTTY/PuTTYgen uses its own proprietary format of key pair. It won't work on Linux, where OpenSSH format of keys prevails.
In PuTTYgen, you can directly see (and copy + paste) a public key in the format used by the OpenSSH
authorized_keys
file.You can use the button Save public key to save the public key in the
.pub
format (RFC 4716). On Linux the file is typically namedid_rsa.pub
(orid_dsa.pub
). But that's typically not needed.Use the Conversions > Export OpenSSH key to export the private key in the OpenSSH format. On Linux the file is typically named
id_rsa
(orid_dsa
) and is stored in.ssh
folder.See the official Using PuTTYgen, the PuTTY key generator.
You can also use a Linux version of PuTTYgen to do the conversion. Linux version is command-line, contrary to Windows version.
See Linux
puttygen
man page.I found one more clear solution.
On
puttygen
create a key, then navigate to Top menu - Conversion and click export openssh keyFile content will start and end with
for root user Copy that key file to
/root/.ssh/
asid_rsa
orid_dsa
for other user Copy that key file to
/home/user/.ssh/
asid_rsa
orid_dsa
Note :
authorized_keys
.** Be careful and make sure you have console access to the box because if you don't do it right, you won't be able to ssh in again until you fix it from the console.
The process is much easier than you think. Load the public / private key pair you generated in puttygen again. In puttygen, you'll notice a window in the middle of the screen which says: "Public key for pasting into Open SSH authorized_keys file:".
highlight the entire contents of the box and press control-c to copy it.
SSH into your linux box and paste it into the "/home/username/.ssh/authorized_keys" file. I prefer to use nano and just right click to paste it in. Make sure it all stays on one line.
Modify your /etc/sshd_config file as needed and restart your sshd service: "service ssh restart"
If you need a sample sshd_config file, let me know and I can post mine.
I've done this on Ubuntu 8.04, 10.04 and 12.04 LTS server and it works slick.
The easiest way to install OpenSSH private keys is by creating or editing
~/.ssh/config
, as answered below. You need to export your PuTTY private key as an OpenSSH key.Best way to use multiple SSH private keys on one client
This works on Linux, macOS, Windows, GIT when using OpenSSH.
I am not sure if this thread is still active, but I stumbled upon a similar problem with Windows 10 anniversary edition which now support Ubuntu kernel. I use to use Putty before for connecting to Linux machine. For generating id_rsa in linux format, use puttykeygen and load your putty private key then click on conversion and choose the second option.
Putty KeyGenerator conevrsions
open the newly generated key file and copy all it's contents, make sure your content starts with : -----BEGIN RSA PRIVATE KEY----- and ends with -----END RSA PRIVATE KEY-----
vi id_rsa inside your ~/.ssh directory and paste the copied contents, this is required because linux otherwise will not understand the contents of the file.
That's all, try ssh to the remote server, it should work.