Копировать файл, используя доступ sudo

Копировать файл, используя доступ sudo

Как скопировать файл или папку для другого пользователя. Новый файл или папка должны иметь его имя.

У меня есть доступ sudo для команды cp

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

Я пробую следующую команду:

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

У меня возникла ошибка:

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

Как мне решить эту проблему?

решение1

Решение:

Вам следует удалить -iиз sudoкоманды:

sudo -u USER2 cp file1 file2

Объяснение:

Проблема, с которой вы столкнулись, заключается в том, что ваш sudoдоступ ограничен /bin/cpи требует использования sudo -iдополнительных sudoразрешений, которых у вас нет.

Как указано в ошибке:

Извините, пользователю USER1 не разрешено выполнять «/bin/bash -c cp file1 file2» от имени USER2 на SERVERNAME.

При использовании sudo -i -u USER2 cpКоманда, которую вы запускаете, /bin/bash -c cp не имеет sudoна нее разрешения. Поскольку вы ограничены командой, sudoна которую у вас есть разрешение: /bin/cp.

Больше информации:человек судо

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

Связанный контент