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

General support questions
Post Reply
SunFulong
Posts: 6
Joined: 2011/07/13 06:51:29
Location: Dalian, Liaoning, China
Contact:

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

Post by SunFulong » 2011/07/13 07:07:06

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

r_hartman
Posts: 706
Joined: 2009/03/23 15:08:11
Location: Netherlands
Contact:

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

Post by r_hartman » 2011/07/13 07:32:37

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]

SunFulong
Posts: 6
Joined: 2011/07/13 06:51:29
Location: Dalian, Liaoning, China
Contact:

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

Post by SunFulong » 2011/07/13 08:10:53

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?

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

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

Post by pschaff » 2011/07/13 20:55:33

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].

SunFulong
Posts: 6
Joined: 2011/07/13 06:51:29
Location: Dalian, Liaoning, China
Contact:

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

Post by SunFulong » 2011/07/14 23:55:09

Thank you, it works, I did this as root user:
[code]restorecon -R -v /root/.ssh[/code]

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

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

Post by pschaff » 2011/07/15 14:17:40

Thanks for reporting back. Marking this thread [SOLVED] for posterity.

Post Reply

Return to “CentOS 6 - General Support”