Copie o arquivo usando acesso sudo

Copie o arquivo usando acesso sudo

Como posso copiar arquivo ou pasta para outro usuário. O novo arquivo ou pasta deve ter o nome dele.

Eu tenho acesso sudo para o comando cp

USER1 ALL=(ALL) NOPASSWD: /bin/cp

Estou tentando o seguinte comando:

USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2

Recebi um erro:

Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.

Como posso resolver isso?

Responder1

Solução:

Você deve remover o -ido sudocomando:

sudo -u USER2 cp file1 file2

Explicação:

O problema que você está enfrentando é que seu sudoacesso é limitado /bin/cpe usa permissões sudo -iextras necessárias sudoque você não possui.

Conforme especificado no erro:

Desculpe, o usuário USER1 não tem permissão para executar '/bin/bash -c cp file1 file2' como USER2 em SERVERNAME.

Ao usar sudo -i -u USER2 cpO comando que você está executando é para /bin/bash -c cp o qual você não tem sudopermissão. Como você está limitado ao comando sudopara o qual tem permissão: /bin/cp.

Mais informações:cara sudo

  -i, --login
                 Run the shell specified by the target user's password
                 database entry as a login shell.  This means that login-
                 specific resource files such as .profile or .login will be
                 read by the shell.  If a command is specified, it is passed
                 to the shell for execution via the shell's -c option.  If no
                 command is specified, an interactive shell is executed.  sudo
                 attempts to change to that user's home directory before
                 running the shell.  The command is run with an environment
                 similar to the one a user would receive at log in.  The
                 Command environment section in the sudoers(5) manual
                 documents how the -i option affects the environment in which
                 a command is run when the sudoers policy is in use.

informação relacionada