LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-04-2013, 08:37 AM   #16
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled

Yeah, I know

Although, I need to perform the same install again on another couple of client/server boxes (same hardware, same distros). I have written down everything I did, so there's good probability I'll come across the same issue if I repeat the steps. I'll update this post in case I find out what was causing this problem.

In the meantime, I have marked this thread as solved.

Thanks, voleg.

Last edited by remslug; 11-04-2013 at 08:43 AM.
 
Old 11-05-2013, 10:03 PM   #17
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
I have found something interesting. The fact that it worked had nothing to do with the reboots. Actually what happens is:
  • If the same user is already logged into the server (whether that be locally or via another ssh session), key authentication works,
  • If they are not, key authentication fails

When it fails, it (as previously) is because the server can't open the authorized_keys file:
Code:
debug1: Could not open authorized keys '/home/me/.ssh/authorized_keys': No such file or directory
I can now reproduce this consistently.
  • I try to log into the server via SSH --> key authentication fails
  • I log into the server physically
  • I try to log into the server via SSH again --> key authentication WORKS
  • I exit the local session
  • I try to log into the server via SSH again --> key authentication fails

I did not change any rights or ownership. I don't understand this behaviour. I tried and google for something similar but could not find anything relevant. Am I missing something?

Last edited by remslug; 11-05-2013 at 10:04 PM.
 
Old 11-05-2013, 11:43 PM   #18
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
What is type of /home FS ?
Did you checked, what the state of selinux as i said above ?
 
Old 11-06-2013, 01:21 AM   #19
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Encrypted home directory?

Is your home directory encrypted? One symptom is being unable to use keys unless already logged in. If so, you'll have to configure sshd to store keys in a second place, outside the encrypted directory using "AuthorizedKeysFile" in sshd_config. You could make a directory /etc/ssh/remslug and put the keys there. Then sshd_config could contain something like this:

Code:
AuthorizedKeysFile .ssh/authorized_keys /etc/ssh/%u/authorized_keys
 
Old 11-06-2013, 07:05 AM   #20
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
What is type of /home FS ?
Did you checked, what the state of selinux as i said above ?
My /home filesystem is ext4.

SELinux is disabled (which is the default on Mint).
Code:
#$ getenforce 
Disabled
Quote:
Is your home directory encrypted? One symptom is being unable to use keys unless already logged in. If so, you'll have to configure sshd to store keys in a second place, outside the encrypted directory using "AuthorizedKeysFile" in sshd_config.
Good point. Yes, my filesystem is encrypted. That might be the problem.

I have copied authorized_keys in /etc/ssh/me/ and added the following line in /etc/ssh/sshd_config:
Code:
AuthorizedKeysFile /home/%u/.ssh/authorized_keys /etc/ssh/%u/authorized_keys
I set the following access rights:
Code:
drwxr-xr-x 22 root root 4096 juil. 21 23:55 /
drwxr-xr-x 157 root root 12288 nov.   6 13:21 /etc/
drwxr-xr-x 3 root root 4096 nov.   6 10:41 /etc/ssh/
drwx------ 2 me me 4096 nov.   6 10:43 /etc/ssh/me/
-rw------- 1 me me 398 nov.   6 10:43 authorized_keys
I rebooted to make sure I had no open sessions left and that all the changes had been taken into account.

Now, it seems to work.
 
Old 11-10-2013, 03:29 AM   #21
ericson007
Member
 
Registered: Sep 2004
Location: Japan
Distribution: CentOS 7.1
Posts: 735

Rep: Reputation: 154Reputation: 154
Quote:
Originally Posted by voleg View Post
An issue becomes interesting.

Are you sure that /home/me/.ssh/authorized_keys exist on server side ?
As I see, user "me" has UID/GID 1000/1000:

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.
I don't agree with this advice. Editing the file may very likely cause selinux issues so it is better to run

Code:
 restorecon -Rv ~/.ssh
 
Old 11-12-2013, 11:29 AM   #22
remslug
LQ Newbie
 
Registered: Nov 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Guys, this has been working consistently since I moved the authorized_keys file out of my encrypted home directory. I'm marking this as resolved.

Thanks a lot for the help.
 
  


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 08:26 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