Page 1 of 1

[SOLVED] How to use PuTTY login with SSH key for root user?

Posted: 2011/07/13 07:07:06
by SunFulong
I want to use PuTTY login with SSH key, so I generated public and private key, copied the public key to /home//.ssh/authorized_keys, and also edited /etc/sshd_config. After that, I can login successfully for each users, but, when I try copied it to /root/.ssh/authorized_keys, and try to login as root, it fails, and tips: "Server refused our key".

How to resolve this problem? Thanks.

Sun Fulong

Re: How to use PuTTY login with SSH key for root user?

Posted: 2011/07/13 07:32:37
by r_hartman
Welcome to the CentOS fora. New users are encouraged to do the recommended reading as link in my signature.

You do not specify what change you made to sshd_config, but commonly
[code]PermitRootLogin yes[/code]
is changed to
[code]PermitRootLogin without-password[/code]
Should you put 'no', root logins will be rejected.

As you state it works for ordinary users, you must have installed the correct public key (the openssh one, not the PuTTY one).
Have you set permissions correctly on the home directory, the .ssh directory and the authorized_keys file?
Ideally they should be
[code]# ls -la ~/.ssh
total 108
drwx------ 2 root root 4096 Jun 24 12:40 .
drwxr-xr-x 24 root root 4096 Jul 13 09:24 ..
-rw------- 1 root root 416 Nov 3 2008 authorized_keys[/code]

Re: How to use PuTTY login with SSH key for root user?

Posted: 2011/07/13 08:10:53
by SunFulong
Thanks a lot, but it NOT works either.

At first time, I've uncomment these lines below:
[code]PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys[/code]

And then, changed to
[code]PermitRootLogin without-password[/code]

But when I try to login as root, it also tips:
[code]Server refused our key[/code]

That's why?

[SOLVED] How to use PuTTY login with SSH key for root user?

Posted: 2011/07/13 20:55:33
by pschaff
Be sure that /root/.ssh has only rwx permissions for user root, and that /root/.ssh/authorized_keys has only rw.[code]
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys[/code]
See also the [url=http://wiki.centos.org/Manuals/ReleaseNotes/CentOS6.0#head-710e17fe8ed8c98a1fe4faee4e11e2135df09fff]6.0 Release Notes Section 4[/url].

Re: How to use PuTTY login with SSH key for root user?

Posted: 2011/07/14 23:55:09
by SunFulong
Thank you, it works, I did this as root user:
[code]restorecon -R -v /root/.ssh[/code]

Re: [SOLVED] How to use PuTTY login with SSH key for root user?

Posted: 2011/07/15 14:17:40
by pschaff
Thanks for reporting back. Marking this thread [SOLVED] for posterity.