116

I want to login as root, but when I enter

sudo -s

and enter password, this message is shown: "you are not in sudoers file", and when I enter

su

and enter password, this is shown: "authentication failure".

My os has one account only. about past1 hours ago I log on as root and do some commands , when I logout , I can't login another time!

Jorge Castro
  • 73,717
ava
  • 1,163

5 Answers5

84

The su command requires you to put in root password. Root user on Ubuntu in general is locked so no user can login as root thus su is not likely to work.

For sudo -s to work you will have to be part of the admin group on an Ubuntu machine, which apparently you are not.

If you are the only user on the system that is concerning and may be quite involved to fix. If not I would suggest you talk to the System Administrator or owner of the system to see if you even can get root privileges.

Karlson
  • 1,649
82

Be aware that the root account is not active by default.

You will need to do:

sudo passwd root

Then go ahead to set password. Use the root user using

su root
Eric Carvalho
  • 55,453
Ronald
  • 821
29

The https://help.ubuntu.com/community/RootSudo suggests:

If you really need a persistent Root login, the best alternative is to simulate a Root login shell using the following command...

sudo -i
Zanna
  • 72,312
user26687
  • 15,174
7

First of all you need to have admin privileges. If you don't have admin privileges then while booting press and hold the shift key. You will enter the GRUB menu. Here select recovery mode. When you see the list of options like dpkg etc, choose to start a root shell and type:

adduser username sudo

(where username is your username :-) )

this will add you to the sudoers group! Then type exit and boot normally. when you enter your account, type:

sudo passwd root

Then enter your password and type the new root password

After that you can type su and enter the 'root' password.

If you don't want to change the root password then you can use:

sudo -i

to start a root shell, using your own password.

Zanna
  • 72,312
Jatttt
  • 2,367
  • 12
  • 33
  • 43
0

Current best practices recommend using an unprivileged user for normal operations, mainly to minimize possible mistakes that could damage the system. That being said, is common to use the sudo command to give temporary root privileges to normal users for doing administrative tasks, like reconfiguring or installing packages, like this example (installing and configuring an ntpd daemon for network time sync):

sudo apt install ntp
sudo nano /etc/ntp.conf
sudo systemctl restart ntp

If the user has authorization, sudo asks for the user's password before executing the command indicated (this validation is cached some time so we haven't to insert the password at every sudo command).

For this to work, the normal user has to be directly authorized in the file /etc/sudoers or must be a member of a group authorized in that file. To see the actual configuration, use less /etc/sudoers. To edit the file, we should use the command visudo with root privileges, which will check for possible syntax errors or if the file is being edited right now in another shell (To find the visudo configuration sentences, use the man sudoers command).

A lot of modern Linux distros (in particular those Debian based) have this file preconfigured with the user indicated in the installation process, and the root user disabled and without a password assigned, precisely to highlight the more secure practice of system administration.

In any case, there are situations where all the activities in some session will be admin-related, and having to insert sudo in all commands could be a hassle. In that case, use:

sudo su -

to execute a login shell as root after auhenticating sudo, and that shell will not need sudo to run admin commands. To return to the normal user shell, insert the command exit. You can have several terminals, one of them as root, and the rest as normal user, but you have always to be careful when making changes to the system and read the relevant documentation to be aware of possible caveats.

Of course, if your system/distro does not have the /etc/sudoers file configured (or if it hasn't the sudo command installed), you cannot use sudo, so it should have a root account and you must know its password.

Some systems allow to enter some kind of 'recovery mode' at boot, but new distros can ask for the root password (or the password of a sudo user) to enter a shell or even to select GRUB options to protect against unauthorized access. In that case, is necessary to use some other root recovery method.

Fjor
  • 314
  • 2
  • 10