If you find enter password for ssh is irritating, then you may setup ssh without password. With public key authentication, you can ssh without password and it will auto login to the server once you key in the ssh command. The authentication is done via the public key that you generate from your computer and do not let others have your public key.
In this example, i’m going to use DSA (Digital Signature Algorithm) for key generation.
To setup SSH without password, follow the steps below:-
Advertisements
- First check if you have generated any DSA key in your client side .ssh folder
$ cd ~/.ssh $ ls -l
If you see any of the file name shown below, then you already have the key, you can skip the next steps (DSA key generation).
id_dsa id_dsa.pub
- Enter the command below to generate the DSA key at the client side
$ ssh-keygen -t dsa
and you will see sth like below. just leave everything blank and press Enter all the way till it end.
Generating public/private dsa key pair. Enter file in which to save the key (/home/urname/.ssh/id_dsa): Created directory '/home/a/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/urname/.ssh/id_dsa. Your public key has been saved in /home/urname/.ssh/id_dsa.pub. The key fingerprint is: 4e:3f:05:78:3f:9e:97:6c:3b:ad:e8:58:37:bd:35:d4 urname@yourmachine
- Now transfer your DSA public key from client to the server using the command below:-
$ scp ~/.ssh/id_dsa.pub remoteuser@remotemachine:.ssh/myid_dsa.pub
- Now, login to the remote machine and make sure the .ssh folder is at right permission
$ chmod 700 ~/.ssh
- At the remote machine, append the myid_dsa.pub to authorized_keys and remove the original key.
$ cat myid_dsa.pub >> ~/.ssh/authorized_keys $ rm myid_dsa.pub
- Now change the permission of authorized_key file at the remote server
$ chmod 600 ~/.ssh/authorized_keys
- Configuration done. you may now try to ssh to the remote server. It should not prompt you for any password from now on.
Notes to check if you still not able to ssh without password.
- check if your remote .ssh folder has 700 permission.
If not use the command below:-$ chmod 700 ~/.ssh
- check if your remote .ssh/authorized_keys has 600 permission. If not then use the command below to change:-
$ chmod 600 ~/.ssh/authorized_keys
Related posts:
How to batch resize image in Mac OS X
How to connect Creative Zen V Plus in Mac OS X
How to flush DNS cache in Linux / Windows / Mac
How to disable ssh root login?
How to burn data CD or DVD in Mac OS X
Secure file transfer thru scp in Mac and Linux
How to delete all .svn folder in Linux / Mac?
N900 virtual keyboard not working after uninstall SCIM
Share this with your friends:-
Another thing to check if the login does not work is ownership of the .ssh directory and the authorized_keys or authorized_keys2 files. If they are created as root but placed into a non-root user’s folder , they may not behave as expected.
Also, RedHat-based systems come with a utility called “ssh-copy-id” that can automatically copy a key to a remote server.
The ssh-copy-id command uses the following syntax:
ssh-copy-id [-i [identity_file]] [user@]machine
It will ask for the user’s password before connecting, but after that one time, future logins should be allowed using the key sent to the remote machine.
good thanks you. will
The scp command copies myid_dsa.pub into the .ssh directory on the remote machine, but later commands seem to expect it to be in the home directory. I did
$ cat ~/.ssh/myid_dsa.pub >> ~/.ssh/authorized_keys
$ rm ~/.ssh/myid_dsa.pub
and that worked.
Thanks,
Steve
An alternative to ssh keys is using expect to do automatic login.
http://blog.hortopan.com/ssh-scm-simple-connection-manager.html