Many of us at some point in time have faced this situation of working remotely on a Unix/Linux box. The most preferred way is through SSH. But every time you login to a machine remotely you have to provide your password. How about logging in without password; using public keys ???☺
Server Side Settings (Caffeine)
That's all we need to do on the server side !!
Client Side Settings (Coffee)
In order to login without password, first you need to create public-private key pairs.
In order to do this on linux (fedora or ubuntu ) execute
Just hit and accept the default file name. Enter the pass-phrase or hit enter for none.
This step would have created 2 files as shown below in your
Of the two files,
After we have the public and private key files, we need to add these keys to the authenticating agent. Its the authentication agent who performs the authentication on our behalf. To add the keys execute
If you have provided the password in the above step, it will ask for a password
else it will not
The next step is to copy and paste the public key from
** Important: The file permission for
Testing !!
That's all that is needed. You can now try to login to the server without passwords.
To demonstrate this method, I will be using 2 Linux machines.
1. Caffeine: This will act as ssh server.
2. Coffee: This machine will act as client.
Server Side Settings (Caffeine)
On the server we need to start the ssh daemon. $ sudo /etc/init.d/sshd start
![]() |
Start the SSH server |
Client Side Settings (Coffee)
In order to login without password, first you need to create public-private key pairs.
In order to do this on linux (fedora or ubuntu ) execute
$ ssh-keygen
![]() |
Create public-private key pair |
This step would have created 2 files as shown below in your
~/.ssh
folder.![]() |
Public/Private key files |
id_rsa
contains the private key and id_rsa.pub
contains the public key.After we have the public and private key files, we need to add these keys to the authenticating agent. Its the authentication agent who performs the authentication on our behalf. To add the keys execute
$ ssh-add
If you have provided the password in the above step, it will ask for a password
![]() |
ssh-add, keys with password |
![]() |
ssh-add, keys without password |
id_rsa.pub
into Server's (Caffeine) ~/.ssh/authorized_keys
file on a new line. This step needs to be done once, either manually or by executing $ ssh-copy-id user@machine.
You will be prompted for your password.** Important: The file permission for
~/.ssh/authorized_keys
must be 400, else it will not work. **![]() |
ssh-copy-id |
That's all that is needed. You can now try to login to the server without passwords.
To login just type
$ ssh user@machine
or like most of the cases if the user-name is same on both machines then just $ ssh machine
![]() |
Login with user and machine names |
![]() |
If the username is same, just use machine name |
No comments:
Post a Comment