I need another sudo user on the system, but I need to create a blacklist of the command that this user can't execute for example: I don't want this user will remove ufw so I add this line in the sudoers file username ALL=!/usr/bin/apt-get remove ufw,!/usr/bin/apt-get autoremove

but suddenly I noticed that if I run the command like this in the terminal I will get blocked and it's perfect but then I created a script, and it is not blocking the command in the script.

sudo nano gg.sh

Inside the script: #!/bin/bash sudo apt-get remove ufw

and then I will run the script like this sudo bash gg.sh It will execute the command regularly. So is there any way to block specific commands from other sudo users like create a blacklist of command or something smarter way to limit permissions of sudo users. Or there is a way to fix this issue?

  1. Don't give root permissions to users you can't trust.

  2. Add the user to groups that have the permissions to do only what you want to allow.

  3. Give the user sudo permission to run only commands you want to allow.

    username        ALL = /bin/ls
  • I must use the root user; there is no way to block the "sudo bash XX.sh"? – pisoto Jun 6 at 18:07
  • Can you explain what you need this sudo user to do? – xiota Jun 6 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.