putty login to linux box with ssh keys

Most of the instructions I have found tell you to generate a key with with puttygen however I have had no success getting it to work this way.  The best way I have found is to use linux to generate a key pair, copy the public key on to the server as per per ssh notes, get the private on to the client using whatever means you see fit and then use puttygen to convert the key to something putty can comprehend.

Navigate to a suitable directory (does not have to be ~/.ssh, in fact it would be better to put the keys somewhere else).

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mkdir mykeypair
ssh-keygen -t rsa -b 4096 -C mykeypair_rsa -f mykeypair_rsa
mkdir mykeypair ssh-keygen -t rsa -b 4096 -C mykeypair_rsa -f mykeypair_rsa
mkdir mykeypair

ssh-keygen -t rsa -b 4096 -C mykeypair_rsa -f mykeypair_rsa

Don’t set a password as doing so kinda defeats the object.

Now you should have 2 files in the directory you created.

 

Server

Next you need to copy the public key to the server:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ssh-copy-id –i mykeypair_rsa.pub myUserName@myServer
ssh-copy-id –i mykeypair_rsa.pub myUserName@myServer
ssh-copy-id –i mykeypair_rsa.pub myUserName@myServer

You will be prompted to enter your password. This command essentially adds the key to the user’s authorized_keys file on the server and if successful should display:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'myUserName@myServer'"
and check to make sure that only the key(s) you wanted were added.
Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'myUserName@myServer'" and check to make sure that only the key(s) you wanted were added.
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'myUserName@myServer'"
and check to make sure that only the key(s) you wanted were added.

That is it for the server; now for the client:

 

Client

Find a way to get the private key (The file that doesn’t end in “pub” on to the client)  You can copy and paste the contents if you like. Now start puttygen and hit the “load an existing private key file” button.  You should be notified that the key was successfully imported.  Click “OK”

This converts the private key to a format that putty can understand, now click “save private key” and save it in a location only accessible by the logged on user (unless you want all users to be granted access).

Now open putty and load your session (configuration of a session is beyond the scope of this how to).  Next navigate to SSH > Auth > Credentials and click “Browse” next to the “Private key file for authentication” field.  Now navigate to the private keyfile you saved earlier and that should be it, you can now log on without authenticating first.

 

Create a shortcut

Finally you may want to create a shortcut to automatically open you session, do do so right click and select new > shortcut from the popup menu.  In the dialogue box browse to “C:\program files\putty\putty” now append the location with -load mysessionname (where mysessionname is the name you have given to your session.  Now you can name your shortcut and you are done.

The shortcut will look something like:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
"C:\program files\putty\putty" -load mysessionname
"C:\program files\putty\putty" -load mysessionname
"C:\program files\putty\putty" -load mysessionname