War*_*ill 12
假设您实际上并没有更改root用户,而是从管理员列表中删除了第一个用户,那么这相对容易解决。
按CTRL+ ALT+T并输入id
你应该看到类似的东西。
~$ id
uid=1000(warren) gid=1000(warren)groups=1000(warren),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),124(sambashare)
Run Code Online (Sandbox Code Playgroud)
如果这显示sudo您应该是管理员。在 12.04 之前的 Ubuntu 中,组是admin如果不是,这就是问题所在。
首先,如果您在引导时通常看不到 grub ,您需要引导到root shellSHIFT。
您应该会看到如下内容:

选择恢复模式,然后降到 root shell。

最后挂载文件系统读写
mount -o rw,remount /
Run Code Online (Sandbox Code Playgroud)
如果问题是您不在sudo组中,则可以使用
usermod -aG sudo warren
Run Code Online (Sandbox Code Playgroud)
替换warren为您的用户名。如果您不确定用户名应该是什么,那就是您之前运行uid=的id命令中的字段。
更换sudo用admin,如果你之前的12.04使用版本的Ubuntu。
另一种不太可能的可能性是您更改了sudoers文件
如果这是问题,请输入
visudo
Run Code Online (Sandbox Code Playgroud)
将此文件编辑为如下所示(默认为 12.04):
#
# 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
Run Code Online (Sandbox Code Playgroud)
在 grub 启动选择屏幕(如果在启动时没有显示按住 shift),选择 ubuntu 恢复模式并按 Enter,然后从选项列表中选择 root 终端(或类似的东西,它可能被称为 root shell)。然后键入mount -o rw,remount /以获得对文件系统的读/写访问权限。然后键入adduser adminusernamehere sudo以授予您更改为标准 sudo (root) 权限的管理员用户。