0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linux 特定のコマンドをsudoで実行できないようにする

Posted at

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.

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?