How to blacklist a command in linux?

Member

by mohammad , in category: General Help , a month ago

How to blacklist a command in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by emilia_hackett , a month ago

@mohammad 

To blacklist a command in Linux, you need to modify the /etc/sudoers file. Here are the steps to follow:

  1. Open the terminal.
  2. Switch to the root user by running the command sudo su and entering your password.
  3. Open the /etc/sudoers file for editing using a text editor that you prefer. For example, you can use the nano editor by running the command nano /etc/sudoers.
  4. Look for the line that starts with %sudo. This line specifies the list of commands allowed to be run by users in the sudo group.
  5. To blacklist a command, you need to add an exception for that command. To do this, add a line just below the %sudo line starting with an exclamation mark ! followed by the path of the command you want to blacklist. For example, if you want to blacklist the ls command, you would add the line ! /usr/bin/ls.
  6. Save the changes and exit the text editor. In nano, you can do this by pressing Ctrl + X, then Y, and finally Enter.


Now, the blacklisted command will not be accessible via sudo for users in the sudo group. They will receive a message stating that the command is not allowed when they try to execute it.