Tuesday, February 21, 2012

Login to a UNIX account from Windows without password



   UNIX users login to their unix boxes umpteen times in a day. Every time, while logging in, we give username and passwords which, takes quite a bit of time, if you happen to login many times in a day. In this article, we will see how we can login to a UNIX account without providing username and password using ssh.

Logging into an UNIX account usually happens in 2 ways:

1. User is already in a UNIX box or server. He tries to login to another UNIX server from the first one.
2. User logs into the UNIX box using putty installed in his Windows system.


   We are looking at the Option 2 in this article wherein we try to login without the username and password from Windows to a UNIX account.(We assume the putty is already present in your system)

The following are the steps:

1. Download puttygen.exe to your windows PC.
2. Run PuttyGen.
3. Click on Generate. In a few seconds, public and private key gets generated.


4. Click on 'Save Public Key' and save the public key as say 'myputty.pub'.
5. Click on 'Save Private Key' and save the Private key as say 'myputty.ppk' .
6. Copy the 'Key' part(the one highlighted in blue) into some notepad. Close the puttygen.

7. Logon to your unix account in the normal fashion by providing the username and password through putty. For example, the username is gpr in the UNIX server gurus.
8. Create a directory .ssh in the home directory of the user to which you want to do a password-less login.
9. Create a file authorized_keys2 under the .ssh directory.
10. Copy the contents(Step 6) to the authorized_keys2 file. Save the file. Log out of the user account and close the putty.

The final  steps are to be done in the putty:

11. Open the putty. Choose your session and click on load.(If you don't have a saved session, create a saved session by providing your ip address or host name in the 'HostName' box and save the session).

NOTE: The connection type should be ssh.



12. Under 'Connections' category, choose 'Data'. In the 'Auto-login username' text box, enter the username(The username of the UNIX account to which you want to login). The username used here is 'gpr'.


13. Under the 'SSH' category, choose the 'Auth' tab. Click on 'Browse', and choose the myputty.ppk file which you had saved earlier.


14.  Click on the category 'Session' and click on 'Save'. Close the putty.

You are now all set to auto-login without username and password.

Open the putty, and double click on your saved session, you should land right in your account without providing the username or the password.

Happy Logging!!!

4 comments:

  1. Nice article guru. I have something to add.

    If you are doing ssh to Linux server from a cygwin, you can create keys from command line itself.
    1. Login to Cygterm (using puttycyg )

    2. Create a ssh key using the following command:
    ssh-keygen –t rsa

    Hit ‘Enter’ key at each prompt until you return to your $ prompt, to accept the default choices.

    3. Copy the ssh-key to Linux using the following command:
    scp $HOME/ .ssh/id_rsa.pub username@ server:$HOME/.ssh/authorized_keys

    ReplyDelete
  2. super .. nice article ... please post about awk command with example please.. as i am new to unix

    ReplyDelete
    Replies
    1. Hi Maddy
      There are quite a few articles on awk in our blog. You can either use the search box above or check in the tags link.

      Delete