如何为其他用户复制文件或文件夹。新文件或文件夹必须有他的名字。
我有 cp 命令的 sudo 权限
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 不允许以 USER2 身份在 SERVERNAME 上执行‘/bin/bash -c cp file1 file2’。
使用时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.