Question

How do I copy a SSH Private Key to my Windows Computer?

Posted October 7, 2020 164 views
Ubuntu 18.04

For some reason, Putty wouldn’t accept my key. It’s probably something I did many months ago. I’ve generated a new key pair on the terminal as per instructions on this site and they’re in my ./ssh directory I need to copy the private key to my Windows box so that Putty can find it. I’ve tried numerous cut/paste methods including Ctrl 6 and Alt 6 but nothing is going to my windows clipboard. How is it done? (Ubuntu 18.04)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi there @Johnk42,

What I would suggest in your case is to generate your SSH key directly on your Windows PC and then upload your private key to your server and not the other way around.

You can generate the SSH key on your Windows PC by following the steps here:

https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-putty/

Once you have the key, you need to add the new generated public to the ~/.ssh/authorized_keys file. If you do that by following the steps here:

https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/to-existing-droplet/

Let me know how it goes.
Regards,
Bobby

  • Hi Bobby and thank you for your speedy reply. This may sound a bit nasty, but the tutorials you point to are from my perspective, nerds trying to impress other nerds. It’s a sad fact of life that many novices like myself are attempting to develop sites and they need concise tutorials written in Layman’s language. Tutorial writers must understand that people seeking help are doing so because they don’t understand. We all start at the bottom and the best educated kids are the ones who have the best teachers.

    Okay, I’ve read the tutorials and I already know most of the stuff they discuss. I know how to create a key set using Putty or using the terminal. I also know that the Putty Public key we’re asked to save doesn’t work with the DigitalOcean Droplets. We have to cut and past the public key that appears in the top box of Putty, but nobody bothers to tell us that. They just let us waste hours and hours figuring it all out for ourselves.

    So I copied the key from the top box and placed it in my Windows Clipboard. Then I tried to place it in the “Authorised Keys” file in the terminal, but the Terminal refused to accept the few lines of text regardless of what I did. Firstly it mirrored everything - Caps become L/C and visa versa. Chunks went missing, characters were replaced and the whole thing was a mess. After 20 plus hours of frustration, I decided to try to copy a generated key pair from the terminal to my Windows machine, but then I found I couldn’t copy that few lines of code to my Windows box as well.

    Hey, this should be as simple as catching Covid-19, but no, Mr Linux/Unix has made as difficult as hell. Why I ask?

    I appreciate your help, but Piping, using Putty and most other options are not available. Surely there must be come simple way of accurately copying and pasting text from my Linux server to my Windows box and visa versa. Then the job will be done and I can move on.

    In all honesty, once I find out how to do this I could write a tutorial in four paragraphs, rather than writing several hundred lines using nerd jargon.

    Gee, I really do appreciate your help, but I’ve already been there and done that. All I want to do is get access to my server via Putty.

    • Hi there @Johnk42,

      Yes, it is quite understandable, server management could be a bit frustrating when first getting started, but it’s true for all new things, right? My advice is to embrace it as a challenge and enjoy the process.

      What I could suggest in your case is to enable password authentication rather than using SSH keys. That way when you try to connect via SSH you will have to enter a password instead of having to specify an SSH key.

      To do that, connect to your server via the web console, then follow these steps:

      • Open this file:
      nano /etc/ssh/sshd_config
      
      • Go down until you find the PasswordAuthentication line

      • Change the no to yesnext toPasswordAuthentication`

      • It will look like this at the end

      PasswordAuthentication yes
      
      • After that save and exit the file, if you are using nano you can save the file with CTRL+O then press Enter then exit with CTRL+X.

      • Finally restart the ssh service with the below command:

      systemctl restart ssh
      

      After that when connecting with putty you will be asked for your password instead of specifying your SSH key.

      Once you have SSH access to your server, it will be easier for you to add your SSH key to the authorized_keys file in case that you decide to use SSH key authentication in the future.

      Hope that this helps!
      Regards,
      Bobby

Hi Bobby and I thank you again for you speedy and detailed answer. You actually beat me by a few minutes because I was about to respond to my previous message.

After finding a thread from a person with the same problem as mine and reading the endless negative comments about the DigitalOcean terminal, I concluded that it was impossible to paste Windows text. As I desperately needed to access my site via Putty, I entered the Public Key by hand. I made two small mistakes because the lowercase L, Upper case I and the figure 1 look all to similar. Once the errors were fixed, I was back into Putty. It took about an hour to enter the Key compared to the several hours I wasted trying to paste it.

I don’t recommend doing it by hand, so hopefully your excellent tutorial will come in very handy to the next person with key issues, provided they can find it.

Once again, many thanks and best wishes.

Submit an Answer