19

I'm trying to follow Slicehost Document to setup my server. I reached SSH section. I made it as written, but when i logged out from root, i cant access root@IP_ADDRESS -p 30000 again! but i can access user@IP_ADDRESS -p 30000.

So, the question is, how to set a public SSH key for root user?

1
  • 1
    This question should be on ServerFault, not on StackOverflow.
    – Henning
    May 10, 2010 at 20:14

4 Answers 4

19

I'm not sure what you mean. You mean you can't login as root with your public_key? If so check /root/.ssh/authorized_keys

Have also look at /etc/ssh/sshd_config It should contain:

PermitRootLogin yes
1
  • i figured it out early! but yeah was some problems in the sshd_config. thanks but only PremitRootLogin doesnt make the trick
    – amrnt
    May 10, 2010 at 18:47
4

Have a look in the logs. sshd usually gives helpful messages. Try /var/log/auth.log or /var/log/messages or /var/log/syslog (or something else) depending on your platform.

Sounds like a permissions problem to me though. Try these commands (as root): chmod 700 ~root ~root/.ssh && chmod 600 ~root/.ssh/authorized_keys

0
3

Caveat: You will need direct physical access to the machine, or an already functional ssh login (via password authentication or super-user key-pair).

In order to get this to work on my Debian box (my SSH host), I needed to generate a new key-pair (I used Putty on Windows 10; my SSH client), then ensure the following as already discussed by editing 'sshd_config':

$ sudo nano /etc/ssh/sshd_config

And putting these lines in, or uncommenting as required, and saving / write-out:

# Authentication:
PermitRootLogin yes

Then I needed to access the root account, so I issue:

$ sudo su

...and then make the necessary folders for ssh and a file for authorized_keys:

# cd /root
# mkdir .ssh
# cd .ssh
# nano authorized_keys

Then put the relevant public key in here, I pasted mine in from near the top of Putty-Gen, and save / write-out.

Then restart the sshd daemon, still as root, with:

# systemctl restart sshd
# exit
# exit

Then after I'd added the relevant .ppk file in my SSH Auth within Putty, it worked like a charm!

The key to this is that all users (root and other users) all share the same config in /etc/ssh/sshd_config, but they don't all share the same 'authorized_keys' files, so I needed to make root specific ones for this to work.

You can't simply add the public key generated for the root account in the /home/yournameuser/.ssh/authorized_keys file - it seems that the system doesn't look there for root access.

1

This /etc/ssh/sshd_config works fine!

# Package generated configuration file
# See the sshd(8) manpage for details

# What ports, IPs and protocols we listen for
Port 30000
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

UsePAM yes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .