How can I log into Ubuntu-9.04 as administrator or root?

2

My problem is that whenever I try using sudo, I get an error message saying: shawn is not in the sudoers file. This incident will be reported. How can I add my user to the sudoers file? Or how can I log in as a user that is in the sudoers file?

I also noticed, using the "users" command, that there are two users called shawn... How can I tell which shawn I am logged in as? How can I delete one of them to retain only the user that has administrative "powers"?

Thanks for any help

Shawn

Posted 2009-09-10T15:49:34.803

Reputation: 1 219

1The user created during the Ubuntu setup is added to the 'admin' group, which has sudo rights by default. Another option is logging in as root using the password (if it was setup).

This question makes me think you aren't the owner/installer of the system, and I won't provide advice on how to workaround system security if you aren't. – baumgart – 2009-09-10T16:04:30.187

shawn is the user I created upon installing Ubuntu, which I installed only a couple of days ago... I don't know what I did that broke the sudo, nor am I aware if it ever worked..

How can I log in as root?

b.t.w: I am the owner/installer of the system, don't worry – Shawn – 2009-09-10T16:07:58.137

Answers

5

Ubuntu locks the root password by default, so you cannot login as root or su into it. Normally your userid would belong to the admin group and the admin group has sudo permissions granted via /etc/sudoers.

Find out which id you're logged in as using the id command. This is obviously the wrong "shawn" id as you don't have sudo permissions.

Now, reboot the system. At the GRUB screen, press Esc to boot into recovery mode. In recovery mode, you are root. Delete the unwanted id (userdel) or just modify it to a different name (usermod). Reboot. You should be able to log into the correct id now (id command should show a different uid). If this doesn't work, just reboot again into recovery mode. Delete the other id too. Create a new id and add it to the admin group.

Edit: I just realized that SU had a very similar question in the sidebar, and following that led me to this answer that has a meticulously detailed write-up on booting into recovery mode (and editing the /etc/sudoers file).

user4358

Posted 2009-09-10T15:49:34.803

Reputation:

3

In a terminal, execute the following command:

grep ^admin /etc/group

That will give you the names of all "admin" users. Log in as one of those, then "sudo" should work perfectly well. Then you can enable the root user, or simply "sudo bash" if you need a root terminal.

I'm guessing you've created a second user since installing, that isn't part of the admin group. Alternatively, you've somehow removed yourself from the admin group, in which case you're pretty much lost without finding another way to modify your system (e.g. using a bootable CD).

Jeremy Smyth

Posted 2009-09-10T15:49:34.803

Reputation: 354

1Ubuntu requires the creation of another user during installation. You effectively never had access to the root account. – eleven81 – 2009-09-10T17:00:12.680

0

If you want to directly allow root logins, you first need to solve the problem of getting root access in the first place. Jeremy's answer above covers that.

Once you can run sudo commands, set the root password: sudo passwd. Now you will be able to login as root.

Jerry P

Posted 2009-09-10T15:49:34.803

Reputation: 236

1I dislike having a root account that can be logged into. I always use "sudo su - root" or something like that. – David Thornley – 2009-09-10T17:51:02.110

I don't think the OP wants to login as root; merely to be able to run admin commands which require sudo permissions. – None – 2009-09-10T17:57:26.870

0

Using sudo su will sidestep the "Ubuntu locks the root password by default" thing that nagul writes about.

This effectively takes the place of simply using su to become root.

eleven81

Posted 2009-09-10T15:49:34.803

Reputation: 12 423

2The OP's current id is effectively barred from using sudo, so I don't think sudo su is an option in this case. – None – 2009-09-10T17:56:04.393

-1

To edit the sudoers file, you have to run sudo visudo. Though obviously you would need to be able to use sudo to do this, so you still have to fix your other problem....

Mike Cooper

Posted 2009-09-10T15:49:34.803

Reputation: 2 036

Having a typo in your sudoers file is rather a hilarious accident to have in ubuntu... – Jeremy Smyth – 2009-09-10T23:47:16.367

1visudo CHECKS for typos. – LiraNuna – 2009-09-11T05:16:01.233