To blacklist a command in Linux, you need to modify the
/etc/sudoers file. Here are the steps to follow:
- Open the terminal.
- Switch to the root user by running the command sudo su and entering your password.
- 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.
- 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.
- 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.
- 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.