I want to enable root login via ssh. So I add the ligne 'PermitRootLogin yes' to ssh config file '/etc/ssh/sshd_config' :

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes

But the access is denied.
thanks in advance

  • did you restart the service? – Jakuje Mar 23 '17 at 20:49

It could be a couple of things:

1)If you are trying to log in using a password you will need to add:

PasswordAuthentication yes

in the config file. (Should only use this method for setting up ssh keys initially)

2)You have not properly set up your SSH keys.

3)The ssh port is being blocked by the firewall.

  • add "PasswordAuthentication yes" doesn't work the port is open because I can login with simple user but not with the root – Ridae HAMDANI Mar 23 '17 at 19:40
  • 1
    Have you restarted the ssh server after modifying the config? – diametralpitch Mar 23 '17 at 19:43
  • yes I did but it's not working – Ridae HAMDANI Mar 23 '17 at 20:20
  • On the client side, are you using an ssh config file? What does your ssh command look like? – diametralpitch Mar 24 '17 at 7:05
  • In the root users' ~/.ssh/authorized_keys is the key you are attempting to use there? – linuxdev2013 Mar 25 '17 at 4:55

In ubuntu 20.04 root has no default password causing SSH connection to fail with "Permission denied, please try again".

To solve this you must set a password. Run

sudo passwd

and enter your password twice.

  • While this is a valid reason why just enabling PermitRootLogin alone doesn't help, I invite everybody to think why in Ubuntu was a decision to not to set root password by default but require a use of sudo, and why OpenSSH has a default setting to not to permit root login with password even if it's set. Anyway, best solution is to not to use password auth at all, but use ssh keys to auth, and that works right away with default settings. You just deploy an authorized_keys file and voila. – Nikita Kipriyanov Jan 14 at 18:52

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.