root ユーザーでログインし、以下のコマンドを実行します。
visudo
cp
コマンドを sudo
で実行できないようにするには、以下を最後の行に追加します。
Cmnd_Alias MYCMD = /usr/bin/cp
%wheel ALL=(ALL) ALL, !MYCMD
設定後、:wq
でエディタを終了します。
この設定後、root ではないユーザーで cp
コマンドを実行してみると以下のようにパスワードを聞かれます。
$ sudo cp sample.txt rename.txt
[sudo] password for ec2-user:
正しいパスワードを入力すると以下のように実行できない旨が表示されます。
$ sudo cp sample.txt rename.txt
[sudo] password for ec2-user:
Sorry, user ec2-user is not allowed to execute '/bin/cp sample.txt rename.txt' as root on ip-172-31-15-131.ap-northeast-1.compute.internal.
パスワードの設定を行うためには以下のコマンドを実行します。
passwd ec2-user
その後、新しいパスワードを設定します。
Changing password for user ec2-user.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
参考記事