Ubuntu – How to give permissions to specific command

command linepermissionssudo

I would like to run fastboot command without sudo. it's working if I put sudo in front of it, otherwise it wont.

like this:

$ sudo fastboot devices
2738006a    fastboot

$ fastboot devices
no permissions  fastboot

How do I solve this?

Best Answer

Using sudoers file

The correct way is to add a line into your /etc/sudoers file similar to:

username     ALL = NOPASSWD: /bin/path/to/fastboot

which means this specific 'username' is able to run fastboot command using sudo without providing any password as anyone.

Now when you run it using sudo fastboot it won't ask you for password and is a little bit faster to work with.

Then simply add a simple alias to your .bashrc:

alias fastboot='sudo fastboot'

Using SUID bit

I highly recommend the above solution over this one;

If your fastboot program is a binary file you can do as follow:

sudo chown root:$(id -gn) /path/to/fastboot
sudo chmod 4750 /path/to/fastboot

First we make sure that root is the owner of this file and also it belongs to your primary group, then we make it possible for the owner and group to run this file while adding the SUID bit (4) which means file will be run with the owner's rights (root).

Now it should work without sudo, however only root and you are able to run it.

Related Question