Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-22-2013, 01:38 PM   #1
LQ Newbie
Registered: Apr 2012
Posts: 5

Rep: Reputation: Disabled
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..?
Old 03-22-2013, 02:24 PM   #2
Registered: Jun 2007
Distribution: Debian, SLES, Ubuntu
Posts: 308

Rep: Reputation: 50
This sums up pretty well how to do the key based authentication:
1 members found this post helpful.
Old 03-22-2013, 02:25 PM   #3
Registered: Aug 2006
Location: Canada
Distribution: Debian, Slackware
Posts: 106

Rep: Reputation: 28
on the client machine, generate a key:

ssh-keygen -t rsa -v 4096

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

paste the contents of 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.
1 members found this post helpful.
Old 03-22-2013, 05:13 PM   #4
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
###### 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/
		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
		-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/ rx30@XXX.XXX.XXX.XXX
		rx30@XXX.XXX.XXX.XXX's password:
		Now try logging into the machine, with "ssh 'rx30@XXX.XXX.XXX.XXX'", and check in:


		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
		[rx30@rx30 ~]$ exit
		Connection to XXX.XXX.XXX.XXX closed.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] problem configuring ssh for private key authentication rtz Linux - Newbie 2 07-08-2012 10:20 AM
[SOLVED] SSH Public/Private Key Authentication Concepts vahab Linux - Security 9 12-28-2011 09:05 AM
How can I setup SSH private key authentication? davidlu766 Linux - Server 3 04-29-2010 08:32 AM
Private/Public key vs. Password authentication w/ SSH MykeV Linux - Security 5 11-25-2007 12:49 PM
SSH public / private key authentication problems thronh Linux - Security 7 06-14-2006 12:21 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration