Secure shell authentication (SSH Authentication) can be used by client to connect to a server remotely with encryption enabled. SSH or secure shell access offers a convenient way to access the servers terminal securely, however it becomes annoying if we need to type the password every time we need to connect to a server especially if we have a strong password in place. Doing it automatically offers a convenient and secure way to access our servers.
We can do this using OpenSSH if you have a Linux machine or Mac then by no means you already have it in your system. This article focus primarily in using OpenSSH via Windows machine, I just included the Cygwin to do this but it can also be done by using Putty alone.
So to start with, lets define what do we mean:
* Client: the system one types directly on, such as a laptop or desktop system.
* Server: anything connected to from the client.
Some precautions don’t allow your root account to do this, you can always run sudo command to perform administrative task. To do this of just add a user to the wheel group in Linux system to allow them to become
1. Run Cygwin in your command prompt then check the version of OpenSSH installed in your system:
by by typing $ ssh -V
2. Run ssh-keygen to generate the private/public key pair if you are in Windows then it will save the copy of the keys under the account you are using in C:/Documents and Settings/Your_Account/.ssh/id_rsa (for the private key file) and id_rsa.pub (for the public key file)
3. Upload your public key in the server by typing $ scp ~/.ssh/id_rsa.pub server.example.org
then set up the public key in your server
4. To do this create an .ssh directory in your folder in the server. This ~ symbol is an alias for your home directory
4.1 – server$ mkdir ~/.ssh >>> this creates a hidden .ssh directory in your home folder
4.2 – server$ chmod 700 ~/.ssh >>> make sure to set the file permission to 700
4.3 – server$ cat ~/id_rsa.pub >> ~/.ssh/authorized_keys >>> authorized your keys
4.4 – server$ chmod 600 ~/.ssh/authorized_keys >>> then set the file permission to 600 sometimes ssh will refuse connection if the file permission is too loose this is also useful to make sure to make sure that you are the only one who have access to your keys.
4.5 – server$ rm ~/id_rsa.pub >>> remove the copy of your public key from your home folder.
Then everything is ready lets test our connection if you do it correctly:
in cygwin type $ ssh email@example.com -p 22 then it will prompt for your pass phrase. You can put a blank pass phrase but that is not advisable.
If that is working let’s setup putty to login automatically
1. Open Puttygen then load your private key file it will prompt you for your pass phrase save this as id_rsa.ppk, ppk us the default filename for putty’s private key file.
2. Next Open Putty pageant and load your private key file to achieve automatic login via putty.
3. In putty set up your session by typing the details of your server then go to SSH and select Auth browse for your private key file generated by puttygen and load it save this session profile before connecting.
4. If you do it correctly then you will get this login prompt when connecting to your server:
First it will ask you of your username, and after typing it will automatically log you in using your generated keys for authentication.