AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 471946
Accepted
Scorpion
Scorpion
Asked: 2018-09-28 13:49:51 +0800 CST2018-09-28 13:49:51 +0800 CST 2018-09-28 13:49:51 +0800 CST

向用户授予完全 root 权限

  • 772

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

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

我尝试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
permissions users
  • 3 3 个回答
  • 4967 Views

3 个回答

  • Voted
  1. Best Answer
    Tim Kennedy
    2018-09-28T15:03:12+08:002018-09-28T15:03:12+08:00

    无需键入即可apt update使用root特权运行的更安全的方法是为您的用户配置文件添加别名:sudo apt updateapt

    • alias apt='sudo apt'

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


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

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

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

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

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

    • 7
  2. RalfFriedl
    2018-09-28T13:54:09+08:002018-09-28T13:54:09+08:00

    您可以键入sudo -i,然后您将获得一个交互式 root shell,并且不必sudo在每个命令之前键入。

    • 0
  3. eyoung100
    2018-09-28T19:27:33+08:002018-09-28T19:27:33+08:00

    默认使用 Gentoo 的/etc/sudoers文件,你有两个选择:

    选项1:


    ## sudoers file.
    .. snip ..
    ## User privilege specification
    ##
    root ALL=(ALL) ALL
    ## Add your user here.  This allows you to run all commands as root, 
    ## not just the update commands.
    scorpion ALL=(ALL) ALL
    .. snip ..
    

    选项 2:


    ## sudoers file.
    .. snip ..
    ## User alias specification
    ##
    ## Groups of users.  These may consist of user names, uids, Unix groups,
    ## or netgroups.
    # User_Alias    ADMINS = millert, dowdy, mikef
    User_Alias  UPDATERS = scorpion
    ##
    ## Cmnd alias specification
    ##
    ## Groups of commands.  Often used to group related commands together.
    # Cmnd_Alias    PROCESSES = /usr/bin/nice, /bin/kill, /usr/bin/renice, \
    #               /usr/bin/pkill, /usr/bin/top
    # Cmnd_Alias    REBOOT = /sbin/halt, /sbin/reboot, /sbin/poweroff
    Cmnd_Alias  UPDATE = /path/to/apt-get, /path/to/apt
    .. snip ..
    ##
    ## User privilege specification
    ##
    root ALL=(ALL) ALL
    UPDATERS ALL=NOPASSWD: UPDATE
    

    笔记

    1. 此示例假设您的用户名是scorpion。
    2. apt我假设所有命令的路径都在/sbin但 Gentoo 不使用apt,apt-get所以不要忘记编辑。
    3. 这可以在不添加命令别名和用户别名的情况下完成,但恕我直言,别名可以更容易地添加命令,并在需要时进行调试。
    • 0

相关问题

  • 组权限如何工作?

  • Redis日志文件权限错误,但是权限已经是777

  • 以 root 权限启动 zypper 命令

  • 以非特权用户身份运行时,meld 无法访问 /dev/fd/* 的可能原因是什么?

  • 另一个用户的非空子目录是否可以安全地从我的目录中删除?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve