sudo 액세스를 사용하여 파일 복사

sudo 액세스를 사용하여 파일 복사

다른 사용자를 위해 파일이나 폴더를 복사하는 방법 새 파일이나 폴더에는 해당 이름이 있어야 합니다.

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

오류에 지정된 대로:

죄송합니다. USER1 사용자는 SERVERNAME에서 USER2로 '/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.

관련 정보