LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Passwordless SSH setup not working, any ideas? (https://www.linuxquestions.org/questions/linux-software-2/passwordless-ssh-setup-not-working-any-ideas-559628/)

nperrins 01-18-2012 02:42 PM

AuthorizedKeysFile setting
 
Found it. It should be

AuthorizedKeysFile /home/%u/.ssh/authorized_keys

Dark_Helmet 01-18-2012 03:26 PM

I realize you have a working solution, but (in a slight defense of the OpenSSH developers) I took a look at the code.

If the value AuthorizedKeysFile does not use an absolute path, the program does some manipulation to convert it to an absolute path. Among other things (like the '%u' substitution you found), it converts the non-absolute file to an absolute file by prepending the user's home directory.

From what I saw, it gets the user's home directory by calling getpwnam(). The getpwnam() function is a system-wide function--not written by the OpenSSH developers. The information getpwnam() provides is most/all the information in /etc/passwd. Basically, ssh then does this:

absolute_path = user_home_path_from_getpwnam + '/' + ssh_config_file_AuthorizedKeysFile

Now, given that your debug messages show that the path being checked for the authorized keys file was "//.ssh/authorized_keys" indicates to me that whatever account you were using to start ssh does not have a home directory listed in /etc/passwd or the home directory is listed as '/'. If neither of those is the case, then the OpenSSH developers would probably like for you to file a bug and work with them to find out what the core problem is.

Also, as a side note, the OpenSSH code does take into account the '~' notation. In fact, what I saw indicates that the filename would be properly handled if either the '~/' or '~username/' form were used.

elkali 01-18-2012 11:32 PM

The correct format for this setting should be:

Code:

AuthorizedKeysFile    %h/.ssh/authorized_keys
And, at least on all the SLES and debian/ubuntu that I have, that should be the default value if you comment it out.

Specifying as I've read before:

Code:

AuthorizedKeysFile    /home/%u/.ssh/authorized_keys
won't work for root, only for normal users as long as they have their homes under /home/ (which could be a safe setup, but that's another story).


Ssh, at least on the referred distros, and while from OpenSSH packages, should be absolutely 0 trouble to set up for passwordless authentication, unless you mess up something with the server config beforehand, while trying to "fix" a problem that you created by placing the wrong file name or the wrong dir/file permissions/ownership.

In case of doubt, always use the debug config for both server (sshd_config) and client (-vvv parameter), debugging is there for a reason.


Cheers,

-k-

Quote:

Originally Posted by nperrins (Post 4578173)
We have had two of us working on getting ssh keys working on a Fedora Core 13 server. We have done this kind of thing many times before and truly believe the ssh set up to be a real pain. For one reason or another you can waste days of time getting it to work.

I have to post this one because the previous poster has almost hit the nail on the head - and we have spent all this time not seeing it here because we weren't searching for the right thing. So for all others out there I think it only right to add a few terms for searching here:

putty keys do not connect
cannot ssh connect to linux server
Fedora Core 13 cannot ssh
linux ssh drops key
sshd bugs

OK, the problem is inside the sshd_config file. There is a setting

AuthorizedKeysFile .ssh/authorized_keys

This is a real bad bug because you look at it and you think it is OK. The problem is that the only way you can find this problem is to see where it looks. You do this by putting sshd into debug logging (by changing another setting in sshd_config - LogLevel INFO to LogLevel DEBUG). When you do that, /var/log/secure shows that sshd is looking for //.ssh/authorized_keys.

So, the previous poster is correct in saying that changing it to /root/.ssh/authorized_keys works. But, of course, you then have to use the same public key for every users (not good). So, the answer is to amend the sshd_config file to look in all users .ssh folders. I haven't done this yet, but it should be straight forward (~/ won't cut it. root sees this as its own home)

So, I have just lost about 20 hours of my life just for that. Thanks guys.


dsmrtr 02-11-2017 08:45 PM

Thanks for the fix _anonymous!
 
Quote:

Originally Posted by _anonymous (Post 4522244)
I used absolute path in sshd_config as "AuthorizedKeysFile /root/.ssh/authorized_keys".
file permissions were made 700 for .ssh & authorized_keys.

Restarted sshd and then it worked.

I know this is a few years old, but I just wanted to thank-you for this post. I spent the last 2 hours trying to get this to work and finally this was the solution :-D.


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