Setting Up Passwordless SSH Login in Ubuntu from Windows

Last night I decided to set up passwordless ssh login on my ubuntu server. As you may know by now, I have an in-house server, and I ssh into it from my windows computer to work. This is mainly because the server is too old to handle my usual work load. I preffer that machine to work as a server only, rather than running firefox and all other tools that I need. Yesterday I had to generate a public key to pass to a client so I can ssh into his machine tow ork over git on a project. Since I generated the key pair, I though it would be nice to generate one on my windows computer and use key based login rather than password. Since the server is in-house, I never worried too much about the password being sent over the whire. After all, in theory at least, the password never goes outside the local network. Despite all that, I though it would be nice to do it. Little did I know that I was in for a long ride.

I encountered a lot of trouble trying to get my windows machine to connect to the server. I generated the key pair, and send the public to my ubuntu box and set it up there, but it was not working. Later, much later, I learnt that they use different format. PuTTYgen use a different format than the one expected by Open SSH. This cuased trouble. At the end, I was able to set it up correctly, but not without a lot of searching and some frustration. I believe one of them main problems was that I was getting too confused by what I was readin on the internet. It wasn’t until today that I realized that some of the things I read were for something different. For example, using PuTTYgen public key on ubuntu, I ended up readin this pages:

Which explain something completely different from what I was trying to do. I did not know that at the moment though. For example, on the last link, what the person really wants to do is use the keys generated by PuTTYgen on a linux machine. He does not want to login from windows to a linux machine, but rather use the keys generated on windows to login to a host using a linux machine. This kind of informatino was getting me all confused, but at the same time it threw hints on how to accomplish what I wanted. In fact, that same page gave me the answer on how to do what I wanted to do. Here is what I did:

I will not explain how to generate the keys because that info is already on most of the links that I will be sharing on this post.

1)Generate my keys using PuTTYgen.
2)When generating the keys, there is a section that displays the Open SSH equivalent. It is labeled “Public Key for pasting into OpenSSH authorized_keys file”. Copy it.
3)SSH into ubuntu, still using password.
4)Create a file called authorized_keys under ~/.ssh/
5)Open the newly created file, and paste the text you copied on step 2.
6)Save the file. (At this point you can close the connection to ubuntu)
7)Back in windows, open Pageant, which is on the same folder as PuTTY on the start menu.
8)Pageant won’t open a new window, but it will display its icon on the system tray. Double click it.
9)On the window that appears, click the Add Key button, and select your private keey. If you used a passphrase, enter it.
10)Open PuTTY, and make sure the Connection -> SSH -> Auth -> Attempt authentication using Pageant, is selected.

You should now be able to login without a password. If you can log in now, but not later, make sure your private key is added on Pageant (7 – 9). Aditionaly, I dissabled password logins. You can read how to do it here: I had to edit sshd_config rather than ssh_config. Also, I had to restart the ssh server (sudo restart ssh)

Here is a list of other material I found while doing this:

Also related: I saw a Known_hosts file under ~/.ssh/ and got curious:

I hope you find this infomration useful. I know future me might.