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
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1531121
Accepted
Mario Palumbo
Mario Palumbo
Asked: 2024-10-25 17:45:53 +0800 CST2024-10-25 17:45:53 +0800 CST 2024-10-25 17:45:53 +0800 CST

“sudo -u”和“sudo -U”有什么区别?

  • 772

man sudo不让我理解其中的区别。

sudo
  • 1 1 个回答
  • 41 Views

1 个回答

  • Voted
  1. Best Answer
    muru
    2024-10-25T17:59:06+08:002024-10-25T17:59:06+08:00

    来自手册页sudo:

    -U user, --other-user=user
         Used in conjunction with the -l option to list the privileges for user instead of
         for the invoking user.  The security policy may restrict listing other users'
         privileges.  When using the sudoers policy, the -U option is restricted to the root
         user and users with either the “list” priviege for the specified user or the ability
         to run any command as root or user on the current host.
    

    和:

    -l, --list
         If no command is specified, list the privileges for the invoking user (or the user
         specified by the -U option) on the current host.  A longer list format is used if
         this option is specified multiple times and the security policy supports a verbose
         output format.
    
         If a command is specified and is permitted by the security policy for the invoking
         user (or the, user specified by the -U option) on the current host, the fully-
         qualified path to the command is displayed along with any args. If -l is specified
         more than once (and the security policy supports it), the matching rule is displayed
         in a verbose format along with the command.  If a command is specified but not
         allowed by the policy, sudo will exit with a status value of 1.
    

    因此,-U专门用于-l。sudo -l检查用户可以使用 做什么sudo,并sudo -lU <some-user>检查<some-user>使用 可以做什么sudo。-U与其他任何方式一起使用都会导致错误。

    另一方面,-u <some-user>用于以 身份运行命令<some-user>。

    例子:

    % sudo -l
    Matching Defaults entries for muru on pi:
        secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/bin, env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, env_keep+=PATH
    
    Runas and Command-specific defaults for muru:
        Defaults!/usr/bin/visudo env_keep+="SUDO_EDITOR EDITOR VISUAL"
    
    User muru may run the following commands on pi:
        (ALL : ALL) NOPASSWD: ALL
    
    % sudo -lU nobody
    User nobody is not allowed to run sudo on pi.
    
    % sudo -l id
    /usr/sbin/id
    
    % sudo -lU nobody id
    % echo $?
    1
    
    % sudo -u nobody id
    uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)
    
    • 3

相关问题

  • GUI sudo 不工作?

  • 如何在 sudo 下只运行一次桌面图形应用程序?

  • 如何将用户添加到“sudo”组?

  • Nautilus 自动以 root 身份浏览

  • 为什么我需要 root 权限才能在命令行中卸载驱动器,而不是在 Nautilus 中?如何改变它?

Sidebar

Stats

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

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve