0

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
RhostsRSAAuthentication
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

1
  • did you restart the service?
    – Jakuje
    Commented Mar 23, 2017 at 20:49

2 Answers 2

1

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.

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

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.

4
  • 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. Commented Jan 14, 2021 at 18:52
  • @NikitaKipriyanov there are two things being mixed here: sshd (PermitRootLogin), and system-wide config (passwd). They are independent and one doesn't control the other. Sshd is just for enabling network logins: you must still actually have a password on the OS. Separate responsibilities is the UNIX philosophy; if you want a more monolithic system, unix won't make you happy.
    – hraban
    Commented Aug 30, 2023 at 6:19
  • @hraban In fact, SSH can authenticate against PAM (by the way, this is how system-wide authentication in Linux is called, not "passwd"). If it does, it may or may not use the "shadow" passwords database, which is usually used for local logins. If you are going to enable two-factor authentication for SSH, you will use PAM inevitably. And, you can not have any password in the "OS" (shadow) for that to work. I deployed systems where no "system-wide passwords" were set for any users; only SSH keys were used, even for "local" logins, and that was all PAM magic. Commented Aug 30, 2023 at 15:21
  • @NikitaKipriyanov for sure, I was trying to keep this simple and linux-101 level because I thought you were a novice but you clearly know what you mean :) my bad. I didn't think a novice would enjoy learning about PAM.
    – hraban
    Commented Aug 30, 2023 at 17:20

You must log in to answer this question.

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