Monday, November 28, 2011

Passwordless ssh access

The SSH protocol is recommended for remote login and remote file transfer which provides confidentiality and security for data exchanged between two computer systems, through the use of public key cryptography. The OpenSSH server provides this kind of setup under Linux. It is installed by default. But in window we need to use 3rd party software link putty.
Here I am sharing some basic steps to create ssh keys & to access remote system via key
Case 1) for Linux to Linux box
Step a) create public private key for system
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): [press enter for default]
Enter passphrase (empty for no passphrase): [not shown]
Enter same passphrase again: [not shown]
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:                               
44:c8:07:c9:f8:f4:f5:9b:05:d1:0f:d1:05:f0:5d:bf user@localhost $
 Step b) copy public key to remote system authorized key file
$ scp ~/.ssh/id_rsa.pub user@somehost:/home/user/.ssh/authorized_keys
user@somehost's password: [not shown]
id_rsa.pub           100% |*****************************|   225 00:00

After copy you can access your remote host without asking for password
Case 2) for window to Linux box
As we know putty is most popular windows ssh client. First of all i downloaded puTTygen and putty software from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Then I executed puttygen to generate private and public keys. I saved my public key file as user.pub and private key file as user.ppk.
Now public file has to be transferred on Linux system, after transfer i written following line on Linux system to import public key into authorized key
   root#ssh-keygen -i -f user.pub >>/root/.ssh/authorized_key

Now my ssh server is ready to accept private key for authentication.
Finally i executed putty and specify following parameters
         IP address of Linux box
         default username as 'root'
         and location of private key file.
And Linux box get connected without asking password

3 comments:

  1. If Authorized.key file dose not exits than you can also use this command.

    ssh-copy-id -i ~/.ssh/id_rsa.pub root@serverip

    i posting this bcoz i am facing this issue

    ReplyDelete

Renew k8s certificates

Check If certificate expires: amikum@~:03:06:54(⎈ |local-cluster:default):sudo kubeadm certs check-expiration CERTIFICATE                EXP...