Creating SSH keys in Eclipse on Windows 10

If you want to use SSH keys in Eclipse, such as if you’re going to connect an Eclipse Git repository with GitHub or BitBucket, you may want to use Eclipse to create and manage the keys for you.  It’s pretty easy to do.

Where to store your keys

I recommend storing your keys in a folder named .ssh underneath your home folder.  Most programs that use SSH keys expect that, including Eclipse, so unless you’ve got a really good reason to do it differently, go with the standard.

What type of key to use

You’ve got two choices for type of key to use with Eclipse: RSA and DSA.  According to this page on StackExchange, you want to use RSA.

The next thing you need to decide is how long your key is.  Ideally, we’d use a key length of 2048 or 4096; unfortunately, Eclipse only generates a 1024 bit key.  There is a bug report filed against Eclipse to change this, but it’s been open since 2013, so I’m guessing it’s not going to be changed soon.  So, I guess I lied — you don’t need to decide how long your key is, because it’s going to be 1024 bits!

Generating the key

Open Eclipse, then from the menu, select Window, and from the Window menu, select Preferences.  You’ll get a window that looks like this:

On the left side, expand General (click on the > beside General), then expand Network Connections, and finally select SSH2:

You’ll see here that it defaults to storing the keys in the .ssh folder of your home folder — that’s good, that’s what we want.

Select the Key Management tab:

We want to create an RSA Key, so click the “Generate RSA Key…” button.  You’ll get something like this:

So, what’s happened?  Eclipse has generated a “key pair”, a pair of matching keys that you can use to authenticate who you are.  The idea is that you keep one of the keys secret (the “private” key), and you don’t ever let anyone else ever see that.  The other key (the “public” key) you can let anybody see; in fact, they’re going to need to know your public key so that you can authenticate with them.  The public key is what’s shown in the “You can paste this public key into the remote authorized_keys file:” box.

The private key is not shown.  You will want to save it to your .ssh folder.  Before saving it, you need to decide if you want to encrypt the key.  If you don’t, anyone who gets access to your .ssh folder can get your private key and pretend they’re you.  But, if you do encrypt it, every time you go to use the key, you’re going to have to type in a password. I generally encrypt my private key.

To specify a password to encrypt your private key, enter it into the “Passphrase” field.  Type it again into the “Confirm passphrase” field. Be sure to choose a good password! If you don’t type anything into those two fields, your private key will be stored unencrypted.  Eclipse will warn you when you try to save your private key:

In this example, I have typed in a passphrase.  When I press the “Save Private Key…” button, I get this dialog box:

You can ignore the “known_hosts” file in there; that’s from something else I’ve done.  You probably don’t have it. Anyways, it defaults to saving your private key in a file called “id_rsa”; unless you’ve got a really good reason to change it, just go with the default.

Actually, when I save it, it creates two files: one called “id_rsa” that contains my encrypted private key, and another called “id_rsa.pub” that contains my public key that I can share with anybody.

Done!  Now I can share my public key with GitHub or BitBucket, and I can easily authenticate with those systems with Eclipse.  Click the “Apply and Close” button, and you’re good to go!