Disabled root login for SSH in Centos 5.9, key login no longer working

Rick Curran asked:

I have a Centos 5.9 server which I have previously configured to access via SSH key login and this has been working fine for many months. I recently had to have an issue resolved remotely which required me re-enabling the root login temporarily. After this was resolved I then disabled root login by setting “PermitRootLogin no” in the sshd_config file, however, I also set “Password authentication no” and I think this is where I’ve messed things up. After doing this I can no longer log in to the server, I just get the message:

Permission denied (publickey,gssapi-with-mic).

I’ve basically got no other way of accessing the server via SSH so I’ve come unstuck! I’m fairly certain it’s because I’ve set the Password authentication to no that is the problem, I haven’t changed any other settings on the server which should be affecting the keys that previously worked fine.

How can I regain access to the server via SSH?

My answer:


Login via your remote console, rescue disk, etc, depending on what your provider gives you.

If you only want to be able to ssh to root with keys, and not with passwords, then set:

PermitRootLogin without-password

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.