授予用户完全 root 权限

Sco*_*ion -2 users root permissions

/etc/sudoers我补充说:
%myuser ALL=(ALL) NOPASSWD:ALL

现在,如果我输入,sudo apt update我不需要输入密码。
但我想要完整的 root 权限:即,我只想使用apt update.
apt 是我想要 FULL ROOT PERMISSIONS 的一个例子,另一个例子是能够在任何地方创建/修改文件。

我试图root ALL=(ALL:ALL) ALL在 myuser 行中使用根行 ( ) 但什么也没用:
%myuser ALL=(ALL:ALL) ALL

这是我的/etc/sudoers文件:

#
# 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        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
scorpion  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

%scorpion ALL=(ALL) NOPASSWD:ALL
Run Code Online (Sandbox Code Playgroud)

Tim*_*edy 7

apt update使用root特权运行而不输入的更安全的方法sudo apt update是为apt您的用户配置文件添加别名:

  • alias apt='sudo apt'

然后,无论何时运行apt update, or apt upgrade, or apt install <pkg>, apt 命令都会以 root 权限运行。但是其他命令将仅以您的普通用户身份运行,具有普通用户权限。


现在,承认有正当理由为什么我们不只运行具有 root 权限的所有用户,以下是一种可以为用户提供与 root 相同的权限的方法,不使用 sudo。

  • 将用户的 UID 和 GID 更改为 0 usermod -ou 0 -g 0 <username>

这将更改您的<username>用户使用 root 权限运行的所有操作。一切。

是的。我知道这是非常不安全的。 但是,它确实回答了这个问题。

如果您选择这条路线,请在您不介意不时重新安装的系统上进行。以 root 身份运行所有内容最终可能会产生不可预见的后果。

  • `usermod` 建议是 OP 要求的永久解决方案,因此是赞成票。我很快就会看到另一个关于如何在意外 oops 后恢复系统的问题。 (3认同)
  • 我已经多次告诉我的员工,除非您完全破坏了至少一个系统,通常是生产服务器,否则您不是真正的系统管理员。:) (2认同)