108

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
  • 70,934
  • 124
  • 466
  • 653
ava
  • 1,083
  • 2
  • 8
  • 5
  • We'd need to know what commands you ran when you were root. You might need to reset your password: http://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrativeroot-password – Jorge Castro Dec 31 '11 at 21:47
  • Do you want to change user in terminal as you used su command? if you want to then you need to have the root password – Jatttt Mar 05 '14 at 14:45

4 Answers4

80

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,609
  • 1
  • 16
  • 24
  • 9
    and if it is your machine, and you've somehow lost root privileges, you'll have to fix it by booting into recovery mode. – ams Dec 30 '11 at 20:19
  • 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! – ava Dec 30 '11 at 20:28
  • What commands did you do? – Karlson Dec 30 '11 at 20:29
  • I don't know exactly. that was some simple commands such as changing umask – ava Dec 30 '11 at 20:32
  • and some shell programming, add group – ava Dec 30 '11 at 20:35
  • Is any way to restore? – ava Dec 30 '11 at 20:36
  • Did you by chance used `usermod`, `groupmod`, `groupdel`, `visudo`, `userdel`, or changed permissions on anything in /etc? – Karlson Dec 30 '11 at 20:36
  • yes .I use usermod -g .... – ava Dec 30 '11 at 20:38
  • Rule 1: Unless you know what you're doing stay out of SuperUser mode. In the mean time take a look at: http://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrativeroot-password – Karlson Dec 30 '11 at 20:40
  • not any way for me? – ava Dec 30 '11 at 20:41
  • No. you need to boot into `rescue` mode and then add yourself back to admin group. Personally I would suggest you get someone who is an expert to help you because if you are not careful you might wind up with a full system reinstall. – Karlson Dec 30 '11 at 20:43
  • 1
    This link explains how to fix sudo: http://www.psychocats.net/ubuntu/fixsudo – Steven C. Howell Jun 12 '15 at 20:22
74

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
  • 53,609
  • 102
  • 137
  • 162
Ronald
  • 741
  • 5
  • 2
  • 1. It won't work, if user isn't in `admin` group. 2. Please, **[don't enable login via root](https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root).** – Boolean_Type Feb 02 '23 at 21:45
27

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
  • 69,223
  • 56
  • 216
  • 327
user26687
  • 14,874
  • 1
  • 38
  • 43
6

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
  • 69,223
  • 56
  • 216
  • 327
Jatttt
  • 2,287
  • 12
  • 31
  • 43