I can't ssh with root or setup keys properly

  • Posted on September 30, 2014
  • hensansiAsked by hensansi

I was trying to following this tutorial about ssh keys and security, but the server kept me asking password for the user.

So I tried to do it with the root,(to follow the tutorial integrally) Since I had disable the root for remote login (PermitRootlogin No), I tried to re-enable it but it doesn’t me allow to ssh with the root. so I have this problem and I don’t know were to look (logs or errors).

I can sudo and su - without problems and I login trough ssh with a created user. I did “sudo systemctl reload sshd.service” and rebooted after changing (PermitRootlogin yes) with no avail, I simply can’t ssh with root nor I can setup the keys for the user right.

laptop:~ username$ ssh -v root@XXX.XXX.XXX.XXX
OpenSSH_5.2p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to XXX.XXX.XXX.XXX[XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug1: identity file /Users/username/.ssh/identity type -1
debug1: identity file /Users/username/.ssh/id_rsa type 1
debug1: identity file /Users/username/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.4
debug1: match: OpenSSH_6.4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'XXX.XXX.XXX.XXX' is known and matches the RSA host key.
debug1: Found key in /Users/username/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/username/.ssh/identity
debug1: Offering public key: /Users/username/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /Users/username/.ssh/id_dsa
debug1: Next authentication method: password
root@XXX.XXX.XXX.XXX's password: 
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

The log indicates that public key authentication failed, so it tried your password next.

Sudo has literally nothing to do with SSH, so there’s no point in changing its config to resolve this.

As for permit root login, there’s no difference in how public key authentication works for users and root, other than where sshd will look for the authorized_keys file (their home directories)

So you need to go look in the authentication logs on the server, /var/log/auth.log usually, and read the error there that will indicate why log in failed.