How to recover root user [duplicate]

Solution 1:

Assuming you have not actually changed the root user but removed the first user from the list of administers then this is relatively easy to fix.

Press CTRL+ALT+T and enter id

You should see something similar to.

~$ id
uid=1000(warren) gid=1000(warren)groups=1000(warren),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),124(sambashare)

If this shows sudo you should be an administrator. In Ubuntu prior to 12.04 the group was admin If not this is the problem.


First you need to boot to a root shell if you don't normally see grub when you boot hold SHIFT.

You should see something like this:

grub

Select recovery mode, then drop to root shell.

grub2

Finally mount the file system read write

mount -o rw,remount /

If the problem was that you were not in the sudo group it can be fixed with

usermod -aG sudo warren

replacing warren with your user name. If you are not sure what the user name should be it was the uid= field from the id command you ran earlier.

replace sudo with admin if you are using a version of Ubuntu prior to 12.04.


Another less likely possibility is that you have changed the sudoers file

If this is the problem then enter

visudo

Edit this file to look like this (12.04 default):

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

Solution 2:

At the grub boot selection screen (if this doesn't show up hold shift at boot) select ubuntu recovery mode and press enter, then select root terminal (or something similar it may be called root shell) from the list of options. Then type mount -o rw,remount / to gain read/write access to the filesystem. Then type adduser adminusernamehere sudo to give the admin user that you changed to standard sudo (root) privileges.