Copiar archivo usando acceso sudo

Copiar archivo usando acceso sudo

Cómo puedo copiar un archivo o carpeta para otro usuario. El nuevo archivo o carpeta debe tener su nombre.

Tengo acceso sudo para el comando cp

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

Estoy intentando el siguiente comando:

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

Recibí un error:

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

¿Cómo puedo resolverlo?

Respuesta1

Solución:

Deberías eliminar el -idel sudocomando:

sudo -u USER2 cp file1 file2

Explicación:

El problema al que se enfrenta es que su sudoacceso está limitado /bin/cpy utiliza permisos sudo -iadicionales necesarios sudoque no tiene.

Como se especifica en el error:

Lo sentimos, el usuario USUARIO1 no puede ejecutar '/bin/bash -c cp file1 file2' como USUARIO2 en SERVERNAME.

Al usar sudo -i -u USER2 cpEl comando que estás ejecutando es para /bin/bash -c cp el cual no tienes sudopermisos. Como está limitado al comando sudopara el que tiene permiso: /bin/cp.

Más información:hombre 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.

información relacionada