Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 12 down vote accepted

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 as id_rsa, and the public key as id_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 follows

ssh -i ~/.ssh/id_rsa_ubuntu.pub <hostName>

I haven't played with it, but I hear that ssh-agent can also be used to manage ssh-keys.

share|improve this answer
3  
This does work in ubuntu. However, make sure to not over-write an existing id_rsa key if you already have one (by copying the new key on top of it) unless you know you don't use the old one. –  David Oneill Nov 29 '10 at 17:35
    
it worked, thanks! –  Assaf Lavie Nov 30 '10 at 8:15

By coincidence, I just had to do this. You do need to convert the keys to OpenSSH format. The command for doing that is:

ssh-keygen -i -f puttygen_key > openssh_key

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 tells ssh-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).

share|improve this answer
    
This answer solves my problem. I had to convert the key. Thanks –  leticia Feb 4 at 0:47
    
This only solves part of the problem by converting the public key. I used @user18617 's answer to convert the private key as well. –  Vincent Jul 31 at 12:43

How to re-use your Putty key pairs in Ubuntu as OpenSSH keys:

apt-get install putty-tools #Install Putty tools in Linux
cd /my-putty-keys
puttygen mykey-sec.ppk ‐O private‐openssh ‐o my‐openssh‐key.sec
ssh-keygen -i -f mykey-pub.ppk > my-openssh-key.pub

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:

puttygen ‐L mykey-sec.ppk >> $HOME/.ssh/authorized_keys
share|improve this answer
    
about step 4: if the private key name was mykey-sec.ppk, the source file name in this case would usually be mykey-sec.pub. –  Kinjal Dixit Sep 4 '11 at 4:56

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:

  1. Start PuTTYGen.
  2. Click on "Load".
  3. Select your private key and enter the passphrase.
  4. From the 'Conversions' menu, select "Export OpenSSH key".
  5. Choose destination filename.
share|improve this answer
    
I just wanted to say that this worked for me on my Mac OS X, even though I know this is an Ubuntu section. I converted my generated private key in Windows as described above, then copied it in my mac to ~/.ssh/id_rsa. chmod id_rsa 600 to keep Mac from complaining about it. –  Richard Jul 1 at 14:16

** 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.