SSH login without passwords

From assela Pathirana
Revision as of 04:09, 11 July 2006 by Root (talk | contribs) (→‎Synopsis)
Jump to navigationJump to search

Synopsis

{{wbox|;IMPORTANT: The method described here has inherant problem of sever being vulnarable if the client is compromised. There is no line of defence in between. To overcome this issue the application known as Keychain can be used.} Whenever the ssh command is used to login to a remote machine, user needs to provide the remote machines password. While this is an obvious security issue , it soon becomes a headache once you start to login fifty-times a day to the same, known-and-trusted server from your known-and-trusted client! For such situations, the following is a good approach.

Howto

Note
Let's assume the client and server names are

client1 server1

respectively and username in the remote machine is

user1

.

  1. Create public-private key pair in client1

$ ssh-keygen -t dsa -f ~/.ssh/id_dsa Generating public/private dsa key pair. Enter passphrase (empty for no passphrase): (Don't type anything, just press enter here.) Enter same passphrase again: (Again empty) 52:da:75:66:09:15:5e:cb:6f:a3:xd:39:rd:15:f6:da user@client1

  1. Copy public-key to somewhere in server1
    $ scp ~/.ssh/id_dsa.pub user1@client1:~/.ssh/id_dsa.pub
  2. In the server1, append the public-key for client1 to the authorized-keys file
    cat ~user1/.ssh/id_dsa.pub >> ~user1/.ssh/authorized_keys2
  3. Secure the authorized-keys file (otherwise the scheme will not work!) and remove unnecessary files. (in server1)

$ chmod 640 ~user1/.ssh/authorized_keys2 $ rm ~user1/.ssh/id_dsa.pub .


Now you should be able to login from client1 to user1@server1 without providing password.