超级用户和 root 之间的区别

Difference between superuser and root

我正在使用一些在线教程来学习 Unix 系统中的终端。

貌似root到处都是全权限,但是不方便suroot,做你需要做的,然后exit回到你的普通用户名。

sudo 显然绕过了这个,但我有一些问题。

当您使用 sudo 时,它不会要求您输入 root 的密码,它会要求您输入 您的 密码。

那么,是什么阻止了您仅 sudo 访问所有内容并模仿使用 root 密码直接登录 root 的相同功能?

sudo的目的是让某些用户以某些方式运行某些程序,所有这些都可以由/etc/sudoers文件and/or文件控制在 /etc/sudoers.d。它记录了这些用途。因此,例如,系统操作员可以进行备份,或者更高级的管理员可以终止 运行 离开的进程,但他们都无法获得 su 给予他们的完整、无限制的访问权限。

root 用户是内置用户,在此应用程序中具有管理权限。 root 是系统的超级用户,这意味着它可以无限制地访问文件。

root 用户具有以下附加角色:

创建应用程序的多个管理员并向他们发送消息。

root 用户可以限制和管理管理员用户的访问权限及其权限。

When you use sudo, it doesn't ask you for root's password, it asks for your password.

您最近必须进行身份验证。这可以很容易地改变这一点,以便它每次都对您进行身份验证:

sudo visudo
# that will open /etc/sudoers in vi/vim

# type the following to search the file:
/Defaults
# hit n to go to next result

# Find line that says:
Defaults        env_reset
# and change it to:
Defaults        env_reset,timestamp_timeout=0
# 0 is time in minutes

如果您更喜欢 nano,您也可以使用 nano /etc/sudoers,不过我建议您查看 vim。 nano 和 vim 之间的区别就像微软记事本和 sublime/caret 之间的区别一样。

# Vim cheat sheet for this tutorial
i    # insert mode
ESC  # exit insert mode (and other modes)
:wq  # write changes (w) quit (q)

# a little more advanced:
:%s/search/replace/gc
# replace all instances of search and ask for confirmation: 

http://vim.wikia.com/wiki/Search_and_replace

So what stops you from just sudo'ing everything and mimicking the same functionality of having logged directly into root using the root password?

好问题!您显然是 sudoers 组的成员。大多数发行版(linux\unix 的发行版)都将这个组作为轮子。查看 usermod 为用户更改此设置。

您可以在/etc/sudoers中确认群组名称:

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
# ^^^ ENSURE THAT THIS IS COMMENTED OUT (or not present) ^^^

不给用户 sudo 访问权限会阻止这种情况。

这也是一件好事:

每个人和他们的兄弟在他们的系统上都有一个 root 帐户,许多脚本小子试图暴力破解 root 帐户以及其他常见用户名,如 postgres。锁定根帐户以减轻 ssh 蛮力攻击符合您的最佳利益。这可以通过 passwd -l (运行 AS ROOT) 来完成。

拥有 sudo 用户后,您仍然可以执行管理任务,例如安装软件和创建新用户。

Apparently root has full permissions everywhere, but it is inconvenient to su to root, do what you need to do, and then su back to your normal username.

如果您要以 root 身份执行扩展任务,我建议:

sudo -i
# do whatever you need to do
^D 
# CTRL+D This will terminate your current shell and take you back 
# to your previous shell whereas su root and su username will take 
# you two shells away from your initial session.  This probably won't 
# effect you besides MAYBE session history (I am not sure about that).

一如既往地小心,因为作为超级用户,你真的可以搞砸你的系统。

关于你的标题问题:

Difference between superuser and root

Ubuntu99 很好地总结了这一点:

https://askubuntu.com/a/592838/212470