LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to setup SSH Private key authentication in Linux (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-setup-ssh-private-key-authentication-in-linux-4175455146/)

nixonp 03-22-2013 12:38 PM

How to setup SSH Private key authentication in Linux
 
I need to generate key file.

Client computer need to login using that key.

eg: ssh -i /mykeyfile.pem user@hostname

How to configure this..?

grim76 03-22-2013 01:24 PM

This sums up pretty well how to do the key based authentication:

https://help.ubuntu.com/community/SSH/OpenSSH/Keys

roreilly 03-22-2013 01:25 PM

on the client machine, generate a key:

ssh-keygen -t rsa -v 4096

This will create two new files in .ssh/ id_dsa and id_dsa.pub

paste the contents of id_dsa.pub into ~/.ssh/authorized_keys on the host machine. (note that ~/ refers to your home directoy on the host machine)

Open a new ssh session and test it. It should log you in automaticalyl.

lleb 03-22-2013 04:13 PM

Code:

###### DIRECTIONS FOR CREATING RSA KEY################

        Directions for creating the rsa key and making the two
 servers talk to each other without password.

        1st change directory into .ssh and check what files are there.

                [rx30@rx30 ~]$ cd .ssh
                [rx30@rx30 .ssh]$ ls -l
                total 4
                -rw-r--r-- 1 rx30 group 2980 Jun 13 12:02 known_hosts

        2nd create the rsa key.

                [rx30@rx30 .ssh]$ ssh-keygen -t rsa -b 4096
                Generating public/private rsa key pair.
                Enter file in which to save the key (/usr/rx30/.ssh/id_rsa):
                Enter passphrase (empty for no passphrase):
                Enter same passphrase again:
                Your identification has been saved in /usr/rx30/.ssh/id_rsa.
                Your public key has been saved in /usr/rx30/.ssh/id_rsa.pub.
                The key fingerprint is:
                cb:b0:40:c6:e9:f4:9e:f5:71:fc:c3:00:c0:f7:c6:75 rx30@rx30.localdomain

        3rd check that there are two new files with the following permissions

                [rx30@rx30 .ssh]$ ls -l
                total 12
                -rw------- 1 rx30 group 3243 Jun 22 15:50 id_rsa
                -rw-r--r-- 1 rx30 group  743 Jun 22 15:50 id_rsa.pub
                -rw-r--r-- 1 rx30 group 2980 Jun 13 12:02 known_hosts
       
        4th change directory back to the users $HOME

                [rx30@rx30 .ssh]$ cd

        5th copy the key to the remote server

                [rx30@rx30 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub rx30@XXX.XXX.XXX.XXX
                25
                rx30@XXX.XXX.XXX.XXX's password:
                Now try logging into the machine, with "ssh 'rx30@XXX.XXX.XXX.XXX'", and check in:

                .ssh/authorized_keys

                to make sure we haven't added extra keys that you weren't expecting.

        6th, follow directions on the screen.

                [rx30@rx30 ~]$ ssh rx30@XXX.XXX.XXX.XXX
                Last login: Fri Jun 22 14:12:08 2012 from 10.10.4.77
                [rx30@rx30 ~]$ exit
                logout
                Connection to XXX.XXX.XXX.XXX closed.



All times are GMT -5. The time now is 08:04 PM.