Ubuntu – Create a custom sudo command without password

command linepasswordpermissionsscriptssudo

I want to implement a script to execute any command with root privileges, but without having to put any password.
At the terminal I would like to see it like this:

./newsudo "comand with root privileges" 

I think, the way to go would be to use the "comand with root privileges" as an argument inside the script with and exec or similar, to execute it.

The truth is, I'm very noob in all this area and I don't know where to start.

Thanks!!

Best Answer

Create a generic command to run any (sub-) command as sudo, without password; is it possible?

Theoretically, what you ask is possible. Since it is possible to set an application in the sudoers file to run with arguments, we can make a command (script) to call, that runs with sudo, with the command in question as argument.

Should we do it?

NEVER, since it will break the principle of being an administrator. ANY malicious process could run code to destroy your system.

The bottom line is that I even won't post how to do that.


More do's and don'ts on running software without password

As mentioned by @Groundzero, you can add specific applications or scripts to the sudoers file, to run without password, as described here. However, keep in mind:

  • Do not add applications to the sudoers file which can be used to harm your system or do harmfull things in general. Especially if the application has extensive cli- options.
  • Do not store scripts to run with sudo (without password) in a location where they can be edited without administrator's privileges. A simple edit by anyone (or any process) can make it do anything.
Related Question