AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / ubuntu / Perguntas / 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

Qual é a diferença entre "sudo -u" e "sudo -U"?

  • 772

man sudonão me deixa entender as diferenças.

sudo
  • 1 1 respostas
  • 41 Views

1 respostas

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

    Da página sudode manual :

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

    E:

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

    Então -Ué exclusivamente para uso com -l. sudo -lverifica o que seu usuário pode fazer usando sudo, e sudo -lU <some-user>verifica o que <some-user>pode fazer usando sudo. Usar -Ucom qualquer outra coisa resultará em erro.

    Por outro lado, -u <some-user>é usado para executar comandos como <some-user>.

    Exemplo:

    % 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

relate perguntas

  • Como adiciono um usuário ao grupo "sudo"?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

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

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve