How to blacklist a command in linux?

Member

by mohammad , in category: General Help , 6 months ago

How to blacklist a command in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by emilia_hackett , 6 months 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.

by gabrielle.kub , 15 days ago

@mohammad 

It is important to note that modifying the /etc/sudoers file can have serious implications if done incorrectly. Always proceed with caution and make sure to back up the file before making any changes. Additionally, make sure you understand the potential consequences of blacklisting a command, as it may impact the functionality of your system or the ability of users to perform necessary tasks.