PermitRootLogin Causes Login Problems

July 20, 2015 944 views

It's been some time dealing with the loveliness of the nix command line. Much of it starting to come back to me now after several years away from the art. Anyways. I followed this post by Etel to sort of get my feet wet again and revive some of those creaky old mental boxes of knowledge about nix platform. Here's the problem I'm having.

At the end of the post Etel says to modify the SSH config (definitely worth doing) to make adjustments to port used, etc. One of the parameters listed involves denying a login using the root account over SSH.

Ok, that sounds great! But, here's the problem I'm running into with this.

Normally, when I logged in using the root acount, I would get something like this ...


Using username "root".
Authenticating with public key "example-key-name"
Passphrase for key "example-key-name":


So, I would type the password and off I went!

When you apply the "PermitRootLogin" and "AllowUsers example-username" configuration (and restarting the ssh server of course) you are presented with this ...


Using username "root".
Server refused our key
root@example-ip's password:


Perfectly normal I guess. That's the restriction we wanted. So, we switch to the new added user in our SSH client. But, what's this?


Using username "demo".
Server refused our key
demo@example-ip's password:


I am able to type the pw in and successfully login. But, HOLD ON! What happened to our nicely setup encrypted connection using those SSH keys!!!! This will not do.

We are missing a step in Etel's page or I'm blind, which as it happens I am LOL :), no really - I'm visually impaired :).

But, alas! Can someone explain the fix? Why was this step missed?

I did some poking around and came to the conclusion it has something to do with teh ~/.ssh folder.

chdown maybe? The question is--- how does DigitalOcean inject the ssh keys into the distro so it's ready for the root user?

3 Answers
mkdir /home/demo/.ssh
cp /root/.ssh/authorized_keys /home/demo/.ssh/authorized_keys
chown -R demo:demo /home/demo/.ssh

So, from what I can see in that script -- the authenticated_keys file exists in two places by default? /root/.ssh and /home/root/.ssh or does root not have a home folder? How many copies of this file are there by default?

Anyhow, I will try this in the meantime. if this works, it should be added to that page for completeness.

P.S. @woat, thanks for the help and the entertainment »

As the default Apache page says -- It Works! :) Much thanks!

Can I safely delete "/root/.ssh/authenticated_keys file? There's no reason to have the public key in two places (even though I REALIZE it's the public key and can be shareable without issue). I won't be able to loogin using root anyway. Should I leave it for debugging purposes? My OCD (I call it detail-oriented personality) must know.

Have another answer? Share your knowledge.