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?


You need console/out of band access. Contact your hosting provider or schedule a visit or whatever.

  • Thanks. I'm not sure if there is any console access available, the server is actually a VPS running on a cloud-based server cluster. I've enquired with my server support to see if there is anything available. – Rick Curran Feb 18 '14 at 17:16

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
  • Thanks, I'll keep that in mind once I get back into the server :) – Rick Curran Feb 18 '14 at 17:18

I looked online and there are VPS consoles that will enable you access to your server. Your cloud provider should be able to help you with this. After you get back into the server copy a "known good" copy of the sshd_config file, over top your existing file. Are you sure you disabled all other methods of connecting to your server?

  • Thanks, unfortunately there was no other means for me to get into the server, but fortunately my VPS provider had the ability to roll back the change for me so I'm back in now. – Rick Curran Feb 21 '14 at 9:33
  • I'm glade you are now able to get back on. I guess they had your VM backed up and just did a restore. If I where you I would work on setting up remote consoles on your servers. – Cyberninja Feb 21 '14 at 21:27
  • My VPS provider uses the Microsoft Hyper V platform for their servers so I think this gives them some way of rolling back changes. I have asked them to explain how they were able to revert the change I'd made to the sshd_config file. Most importantly in future I will avoid closing my existing SSH window when editing any of these configs to avoid locking myself out again. :) – Rick Curran Feb 24 '14 at 10:04
  • I don't know much about Hyper V as I'm a UNIX/Linux admin. I'm sure there is a way to get console, you can get one with VMware. In the future you always have a console window up when making changes, because even if you had a window up you can still be boot off the server after making changes to SSH or any other communication service. – Cyberninja Feb 24 '14 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.