Παρασκευή 7 Φεβρουαρίου 2014

How to connect with Putty ssh client to a Linux ssh server without password!

Hello my friends,
for some time I wanted to connect directly with my Linux machines without the need of typing all the time the username/password. 
So I found some time to spent on this and found the way through a bit of searching on the internet.

Install ssh server on linux

First let's suppose you use Ubuntu 12.04 LTS which is very common, so you need to install ssh server on this.

Follow the instructions on this link

https://help.ubuntu.com/community/SSH/OpenSSH/Configuring
Your Ubuntu should be ready to accept ssh connections!

Install putty

Now download Putty for windows (or the host you are using) if you don't already have it from

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

I used for this tutorial the Windows Installer.

Now that you are set try login with putty to your account, to be sure you can login.

It should be similar to this:



Generate the Private and Public keys (puTTYgen)

now run puTTYgen
pic 2











generate the keyPair, move your mouse in the blanc area you see.











pic 3

Save your keys, but make sure you do not use a Password!!! But ok, if you want to use a password you just have to use Pagent which will communicate with putty when there is a need to use the password and you'll be ok again. I'll describe what you do if you want password later.










Save the public key on the Linux server

First you have to edit the sshd_config of you server
so just 
sudo vi /etc/ssh/sshd_config





Make sure the line which describes where the authorized keys are saved is not commented out!
If it is, just remove the # to look like screenshot below


Now mkdir .ssh if you don't have it
then
vi .ssh/authorized_keys

Now copy the key which was created earlier, and paste it in the authorized_keys file.


Save and exit ( esc :wq enter)

Create a putty session to connect without password!

Now you have everything set to connect without password!

Open putty and type the hostname or IP address of you Linux machine.

On Connection->Data , make sure you type in the Auto-login username. For my case it is kostas.


On Connection->SSH->Auth browse for the private key you previously saved. 

Load it and you should see something similar.

Now go back to the first screen
Session
and save the session.

Now press "Open" and you will be connected without having to type a username/password!



In case you want to use password to protect private key

You will have to just save the key with password, and then you just use Pagent.

When you run Pagent you just right-click the mouse on the icon on the taskbar, and you select "View Keys".
Then you just press "add key" and you select your password saved private key. The agent will ask for the password. You are done!
When you try to connect with Putty, putty will communicate with Pagent and will use the key from there without you having to use the password.



1 σχόλιο: