无需以 root 身份登录即可获得 Sudoers 权限

无需以 root 身份登录即可获得 Sudoers 权限

我是 Ubuntu 10.10 的新用户,
我的问题是,当我启动机器时,它会带我进入 Ubuntu 的登录屏幕
,但我没有获得以用户或 root 身份登录的选项,
我知道我的 root 密码,甚至
无法发出 ssh 请求,
我搜索了一下,我知道按Alt+ Ctrl+F1 它会带我登录用户

在此用户登录后我无法写入sudo命令

搜索了一段时间后,我发现 sudo 的权限可能会产生问题,
我认为 sudo 的权限必须是 440,也就是现在是 777

如何以 root 权限启动

答案1

首先,如果你还没有接触过 sudo 或更改过任何东西,/etc那么这只是你的恐惧,你应该阅读 Sergey 所说的内容。除此之外,检查文件权限部分是否正确。只需执行ls -l /etc | grep sudoers并查看输出是否如下所示:

-r--r-----  1 root    root       574 2011-03-25 20:34 sudoers

其中-r--r-----部分显示您的权限为 440,据我所知,除此以外的任何权限都应更改为此。如果您可以在救援模式下以 root 身份登录,则可以使用 chmod 440 /etc/sudoers命令轻松更改文件权限。如果您根本不允许sudo使用命令,则可能需要外部 live-usb 进行恢复。/etc/sudoers或的内容visudo应如下所示[至少在我的情况下]:

#
# 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

# 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

#includedir /etc/sudoers.d

答案2

在 Ubuntu 中,您通常不会直接以 root 身份登录 - 尤其是您不会以 root 身份启动 X 会话。此外,默认情况下 root 密码未设置或未知,因此您无法直接以 root 身份登录。

在 Ubuntu 安装期间创建的初始用户具有“sudo”权限 - 即

sudo apt-get update

然后 sudo 会要求你输入你的密码,不是root密码。

在终端会话中,如果你想以 root 身份执行许多命令(或者甚至以 root 身份启动一些图形程序),请输入

sudo su

然后再次输入您的密码。这将启动 root 终端会话。

“原始” Ubuntu 用户可以让其他用户成为“管理员”,以便他们也可以以 root 身份执行命令。

它解决了你的问题吗?

答案3

我不知道你的 sudo 权限是怎么弄乱的。这是我的 sudo 和 ls 权限:

-rwsr-xr-x 1 root root 168800 2011-04-15 21:32 /usr/bin/sudo
-rwxr-xr-x 1 root root 105776 2011-02-23 19:54 /bin/ls

这里的关键是拥有 setuid 位 - 它允许应用程序更改用户 ID:http://en.wikipedia.org/wiki/Setuid可能已被禁用。

如果您需要恢复 sudo,您可以将 Ubuntu 启动到“恢复模式”,在该模式下它应该使您能够打开 root shell。

如果您觉得您的权限可能被搞乱了,我认为dpkg-reconfigure sudo在恢复模式下运行可能会有所帮助。

之后,您可以运行visudo打开 sudoers 文件并编辑它以添加您的用户。

答案4

假设您已经通过在提示符中输入“man sudo”阅读了 sudo 手册,并且它确实坏了,那么新用户修复几乎所有问题的最简单方法就是重新安装。如果您没有时间或已经安装了很多东西,我建议不要使用我的答案。

相关内容