3

I just got a dedicated server with ubuntu 14.04 on it. I haven't received root details in my server info email, but instead for a different user. So I wanted root access and tried to change the password.

I tried:

sudo -i
passwd

and

sudo passwd root

And I entered my new root password, but when I try to login as root I still get denied access.

If anybody can help me it would be greatly appreciated. Thanks.

abear
  • 33
  • 1
  • 1
  • 3
  • Do you get any error messages when you run sudo passwd root? – Arronical Sep 15 '15 at 11:07
  • Check the output of sudo getent shadow root | cut -d: -f2 ..does it start with $ or something else like ! ....DON'T POST THE OUTPUT HERE.. – heemayl Sep 15 '15 at 11:07
  • @Arronical No I don't get any errors, it just asks me to enter the new password twice – abear Sep 15 '15 at 11:12
  • It's probably because you are trying to log in as root via ssh using the password, and that is disabled for security reasons - just don't do it. Either stick to sudo or - if you really must log in directly as root - set up key-based authentication. – steeldriver Sep 15 '15 at 11:13
  • @heemayl Yeah it starts with a $, what do I do to fix that? – abear Sep 15 '15 at 11:14
  • That means the password is correctly saved and root account is activated..how are you logging into the root account i mean the procedure ? – heemayl Sep 15 '15 at 11:16
  • @heemayl logging in with SSH via PuTTY – abear Sep 15 '15 at 11:19

1 Answers1

5

By default in Ubuntu the /etc/ssh/sshd_config file of the openssh-server has the following line:

PermitRootLogin without-password

this prevents to login into the ssh-server as root using password which is for security reasons, you can use key based authentication (and any other not using password) mechanism to login as root directly.

So you have two options:

  • First the bad option, avoid this one. Make the line of /etc/ssh/sshd_config as:

      PermitRootLogin password
    
  • The good option is to login as another user who has access to the server, then switch to the root account by:

      su - root  ## Will need root's password.
    

or

    sudo su -  ## Will need calling user's password. The calling user needs to be able to use sudo.
fooquency
  • 107
heemayl
  • 91,753
  • Good advice, I always edit the PermitRootLogin line to no to be extra safe! – Arronical Sep 15 '15 at 11:46
  • I wanted to do this just temporarily, in order to change a different account. However, PermitRootLogin password is invalid configuration - the correct way would be PermitRootLogin yes (which is the default, so just commenting out the line entirely works too). See https://askubuntu.com/a/449372/18112 – Tomas Aschan Apr 20 '17 at 06:59