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 -i追加の権限を使用していることです。sudo

エラーに指定されているとおり:

申し訳ありませんが、ユーザー 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.

関連情報