Как копировать файл или папку для другого пользователя. Новый файл или папка должны иметь свое имя.
У меня есть sudo-доступ для команды cp
USER1 ALL=(ALL) NOPASSWD: /bin/cp
Я пытаюсь выполнить следующую команду:
USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2
I получил ошибку:
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 в SERVERNAME.При использовании sudo -i -u USER2 cp Вы выполняете команду /bin/bash -c cp, для которой у вас нет разрешений sudo. Поскольку вы ограничены командой, которой у вас есть sudo разрешение для: /bin/cp.
Дополнительная информация: man 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.
Решение:
Вы должны удалить -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.
Дополнительная информация: man 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.