LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-02-2013, 06:46 PM   #1
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Rep: Reputation: Disabled
SSH athentication via RSA key fails.


Hi all,

I am trying to setup a passwordless authentication on one of my boxes in order to be able to use ssh commands in a script.

I have generated public/private RSA keys on the client machine (in the user I'm logged in as' .ssh directory) and added the public key to the server machine's authorized_keys files (in the user I want to be able to ssh as' .ssh directory).

I have set the rights on both .ssh directories, the key files and the authorized_keys files to 700.

On the server machine, in the /etc/ssh/sshd_config file, I have set the two following parameters :
Code:
RSAAuthentication yes
PubkeyAuthentication yes
When I try and ssh from the client machine, it still prompts me for password. The verbose output ends with the following:
Code:
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: My Key
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/me/.ssh/id_rsa
debug3: no such identity: /home/me/.ssh/id_rsa
debug1: Trying private key: /home/me/.ssh/id_dsa
debug3: no such identity: /home/me/.ssh/id_dsa
debug1: Trying private key: /home/me/.ssh/id_ecdsa
debug3: no such identity: /home/me/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
Then it prompts me for a password.

I don't understand why the "My Key" "Offering" doesn't seem to succeed. Does anyone have any idea of what I am doing wrong?

Notes: I am using Linux Mint 15 on both machines. Password logging works as expected. SSH versions are as follows:
Code:
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.1p1 Debian-4
debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4

Any help is greatly appreciated. Let me know if you need any additional information.

Thanks.

Last edited by remslug; 11-02-2013 at 06:59 PM.
 
Old 11-02-2013, 10:47 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
The reason is probably logged in /var/log/auth.log on the server
 
1 members found this post helpful.
Old 11-03-2013, 03:47 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,345
Blog Entries: 3

Rep: Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756
What is the name of your private key? ssh will not find it automatically. It either has to be loaded into the agent (no more than the 6th key on the list or you will fail the default server auth settings) or else pointed to manually. You point to a private key manually with -i

Code:
ssh -i /home/remslug/.ssh/some_key_rsa remslug@93.184.216.119
 
Old 11-03-2013, 05:33 AM   #4
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
Quote:
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/me/.ssh/id_rsa
debug3: no such identity: /home/me/.ssh/id_rsa
debug1: Trying private key: /home/me/.ssh/id_dsa
debug3: no such identity: /home/me/.ssh/id_dsa
debug1: Trying private key: /home/me/.ssh/id_ecdsa
debug3: no such identity: /home/me/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
Looks like you have no generated and exchanged keys yet. Please do according to well know practice.
 
Old 11-03-2013, 06:22 AM   #5
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks for your replies.

As mentioned, I have generated and exchanged keys. I have done so using the following instructions : http://www.tecmint.com/ssh-passwordl...-5-easy-steps/.

I can cat the authorized_keys file on the server and the ssh-rsa entry is in there. The only difference is I have not named the key files id_rsa and id_rsa.pub because I need to be able to use different keys in order to connect to different servers. My files are named ~me/.ssh/my_key and ~me/.ssh/my_key.pub. I have tried specifying my private key file as an "IdentityFile" entry in /etc/ssh/ssh_config on the client machine to no avail. I also tried specifying it with the -i option with the same result. When I specify the file, the ouput is different though:
Code:
debug2: key: /home/me/.ssh/my_key (0x7f65d5317cd0)
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/me/.ssh/my_key
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
The /var/log/auth.log file only contains this single entry for a failed login attempt:
Code:
Nov  3 12:57:29 slg-NAS sshd[2478]: Connection closed by 192.168.0.1 [preauth]
192.168.0.1 being the client machine's IP.
 
Old 11-03-2013, 06:40 AM   #6
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
Then, content of ~me/.ssh/my_key.pub should be pasted in authorized_keys on server side.
Correct command should be:
Code:
$ ssh -i ~me/.ssh/my_key remoteuser@server
The second well known problem is wrong permissions on destination home directory.
It should not be group,other writable. The .ssh directory should be 700,
authorized_keys should be 644.
 
Old 11-03-2013, 06:54 AM   #7
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks for your help, voleg.

Client side rights:
Code:
drwx------ 2 me me 4096 Nov  3 13:10 .ssh
-rwx------ 1 me me 1679 Nov  2 23:36 my_key
-rwxr--r-- 1 me me  389 Nov  2 23:36 my_key.pub
Server side rights:
Code:
drwx------ 2 me me 4096 nov.   2 23:22 .ssh
-rw-r--r-- 1 me me  389 nov.   2 23:37 authorized_keys
Is this correct?

Command I use:
Code:
ssh -vvv -i /home/me/.ssh/my_key me@192.168.0.4
This config gives the output in my last post.
 
Old 11-03-2013, 08:17 AM   #8
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
This looks OK (my_key and my_key.pub don't need execute bits set, but this shouldn't prevent login). A couple of thoughts:
  • what does authorized_keys contain? It should have the exact contents of my_key.pub on a single line.
  • It might be worth trying re-generating the keys, just in case the files got corrupted.
 
Old 11-03-2013, 08:31 AM   #9
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
What about permissions on home directory on server side ?
It should be writable by owner only.
 
Old 11-03-2013, 11:27 AM   #10
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
  • what does authorized_keys contain? It should have the exact contents of my_key.pub on a single line.
  • It might be worth trying re-generating the keys, just in case the files got corrupted.
Yes, authorized_keys contains the ssh-rsa entry on a single line, eg:
Code:
ssh-rsa <key string> My Key
I have tried regenerating the keys several times. I have also tried using ECDSA encryption instead of RSA, just to make sure, with the same result.

Rights on my home directory are 700 on both machines.
Server:
Code:
drwx------ 23 me  me   4096 nov.   2 23:22 /home/me/
Client:
Code:
drwx------ 73 me me 4096 Oct 26 17:33 /home/me/
 
Old 11-03-2013, 01:45 PM   #11
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
If content of /var/log/secure does not have a clue,
next step may be run sshd in debug mode, like:
Code:
# sshd -d -p 222
Then connect to port 222:
Code:
$ ssh -v -p 222 ......
 
Old 11-03-2013, 06:00 PM   #12
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Apparently, the server can't find the authorized_keys file:
Code:
debug1: userauth-request for user me service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: test whether pkalg/pkblob are acceptable [preauth]
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/me/.ssh/authorized_keys
debug1: Could not open authorized keys '/home/me/.ssh/authorized_keys': No such file or directory
Rights:
Code:
drwxr-xr-x 5 root root 4096 juil. 21 22:26 /home
drwx------ 23 me me 4096 nov.   4 00:43 /home/me/
drwx------ 2 me me 4096 nov.   2 23:22 /home/me/.ssh/
-rw-r--r-- 1 me me 389 nov.   2 23:37 /home/me/.ssh/authorized_keys
I have no problem doing :
Code:
cat /home/me/.ssh/authorized_keys
It outputs the file correctly:
Code:
ssh-rsa <long RSA string> My Key
Does this make any sense?
 
Old 11-04-2013, 01:46 AM   #13
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
An issue becomes interesting.
Quote:
debug1: Could not open authorized keys '/home/me/.ssh/authorized_keys': No such file or directory
Are you sure that /home/me/.ssh/authorized_keys exist on server side ?
As I see, user "me" has UID/GID 1000/1000:
Quote:
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
If you login as "me" on server, could you do "cat /home/me/.ssh/authorized_keys" ?
If you still has no solution, probably it is selinux problem.
Please set it to PERMISSIVE and check what happen in /var/log/messages.
 
Old 11-04-2013, 08:11 AM   #14
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
This is weird. This morning when I restarted both machines (after I had switched them off for the night), it started working without changing anything. I guess some services had to be restarted for some of the changes to take effect... I had already tried to restart sshd on the server, though.

Thanks for the help.

Last edited by remslug; 11-04-2013 at 08:27 AM.
 
Old 11-04-2013, 08:21 AM   #15
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
Bad. Now we never will know what it was....
 
  


Reply



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
Putty/SSH login failed when using RSA public key: 'Server refused our key' itsecx@gmail.com Linux - Server 10 10-04-2010 01:19 PM
SSH RSA Key question dorlack Linux - Newbie 4 08-11-2010 02:38 PM
SSH rsa key PB0711 Linux - Security 3 09-10-2006 03:57 PM
SSH RSA key problem taiwf Linux - General 3 05-21-2006 09:33 PM
ssh RSA key thanat0s Linux - Security 3 09-29-2003 09:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

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

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