Ubuntu – Make an application require root permission


How do I force an application to always require root permission?
For example, if I run nautilus, it should tell me permission denied and have me run it as root.
Is there a way to do this in Ubuntu? Force-require root permission?

Best Answer

I would assume you would need to set the owner of the bin file (of the program) to be root, and make it executable only by the root.

So, as an example, this is the current permissions on my nautilus, which is located in /usr/bin/nautilus:

alaa@aa-UBUNTU:~$ ls -l /usr/bin | grep nautilus
-rwxr-xr-x 1 root   root       1542692 Feb 20 23:13 nautilus

In case you need to read more about permissions, click here. Also, before doing anything, remember the permissions of your program before you execute any commands, so that you can change back to those permissions should anything go wrong.

Notice that there are three "x"s, which means that the owner, group, and other (basically meaning everyone) have access to execute it. If we want the application to require root permission, we need to set it up so that the root is the only one able to execute it, hence we need to remove the "x"s (which is the executable permission) from "group" and "other", and only leave the first "x". To do this, you would do:

sudo chmod go-x /usr/bin/nautilus

This command means:

  • chmod: change mode/permissions
  • go: apply the following to "group" and "other"
  • -x: remove (because of the minus sign) the executable permission from "group" and "other"
  • /usr/bin/nautilus: the file to apply this to

So we are removing the "x" from "group" and "other". Now, the permissions looks like this:

alaa@aa-UBUNTU:~$ ls -l /usr/bin | grep nautilus
-rwxr--r-- 1 root   root       1542692 Feb 20 23:13 nautilus

If I try to run nautilus with my username, I get this:

alaa@aa-UBUNTU:~$ nautilus
bash: /usr/bin/nautilus: Permission denied

To be able to run nautilus, I would have to do sudo nautilus.