Make sudo command not need sudo?

https://sh.itjust.works/post/20444169

Make sudo command not need sudo? - sh.itjust.works

I would like to set a specific command to not require sudo privileges, is there a way to accomplish this? I know you can add commands to the sudoer file to allow certain commands to be used by non root accounts, so maybe there is something similar for adding commands to allow regular users to use?

What do you mean by “not require sudo privileges”?

You mean not require root permissions? then you need the program to not modify anything that requires root permissions.

If what you mean is that you want it to still require root permissions, but you don’t want to need to type"sudo" every time, then there’s multiple ways to do this:

  • Add an alias such as alias command=‘sudo command’ and then change the sudores file so that you dont need to enter a password when running sudo for that command.

  • set the SUID bit of the file so that every time the file is executed (by anyone) it will always execute as the user who owns the file (so if the owner is root, the file will always be executed as root)… this is not something I’d recommend though, since it can lead to security vulnerabilities.

  • since it can lead to security vulnerabilities.

    Most software isn’t written to be hardened for that kind of invocation.

    Also, IIRC you can also do the same thing with the sgid bit.

    goes to check

    Yeah.

    $ mkdir test $ cd test $ cp /bin/id ./ $ ls -ln id -rwxr-xr-x 1 1000 1000 48144 Jun 6 10:56 id $ ./id -g 1000 $ sudo chgrp 1001 id $ sudo chmod g+s id $ ./id -g 1001 $ ./id -gr 1000 $

    True, SGID would affect the group it runs as whereas SUID affects the user.

    You could set up things so that a specific group has permissions, instead of the root user. But then this also depends on the usecase, I’m not sure if the group might be enough in all cases.