Как я могу скопировать файл или папку для другого пользователя. Новый файл или папка должны иметь его имя.
У меня есть 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.
Как я могу решить его?
Решение:
Необходимо удалить -i
от sudo
команда:
sudo -u USER2 cp file1 file2
Объяснение:
Проблема, с которой Вы сталкиваетесь, состоит в том что Ваш sudo
доступ ограничен /bin/cp
и использование sudo -i
необходимый дополнительный sudo
полномочия, которые Вы не имеете.
Как указывают в ошибка:
Извините, пользователю USER1 не разрешают выполнить '/bin/bash-c cp file1 file2' как USER2 на ИМЕНИ СЕРВЕРА.
При использовании sudo -i -u USER2 cp
Команда, которую Вы выполняете, /bin/bash -c cp
который Вы не имеете sudo
полномочия для. Поскольку Вы ограничены командой, которую Вы имеете sudo
разрешение для: /bin/cp
.
Подробнее: человек 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.