Run binary automatically as root

permissionsrootsudo

I have root access.

How can I let a general user with little permissions run a binary file as root without a password?

I tried giving it root:wheel with chown, but that did not let a general user do what I wanted.

Best Answer

chown changes the owner, it doesn't make the binary run as the file owner. chmod u+s will do that however. chmod g+s will make the binary run with the file group permission on some systems as well (you don't mention what system you're running). These flags have very different effects on other files and especially folders. You should take a good long look at man chmod and man chown before diving in.

Also you should strongly consider using sudo instead of making the binary suid. When a binary is suid, anyone who can access the binary can run it as the file's owner. If you accidentally give a normal user write permissions to the binary, then they could replace it with anything that want and run it as root. sudo solves these security problems at the cost of requiring the user to prepend sudo to commands they want to run as root. You also have to setup the sodoers file with approproiate permissions.