1

is it possible to to have a sudo command executed with the admin password?

example :

sudo apt-get update -password is 'root' 

this is to put a command into an application on the startup of Ubuntu which needs root access

3
  • 1
    You could modify the sudoers file to disable the password prompt for the user that runs the program. – Cas Nov 26 '16 at 14:25
  • @cascer1 no its important to have the password enabled – Suhayb Nov 26 '16 at 14:29
  • 3
    Having password enabled but written in clear text somewhere is what you want? May you did not understand that @cascer1 is speaking about a way to selectively allow password-less execution for specific (user/command) pair which appears to be a quite good idea. The user will still need to enter password for any other sudo commands. You can have a look at sudoer file documentations. – A. Loiseau Nov 26 '16 at 17:57
1

If you want a particilar process to be run at startup as root then I'd suggest that you wrap it in a systemd/init.d script. For systemd something like this would probably work:

[Unit]
Description=Some command

[Service]
User=root
Type=oneshot
ExecStart=/usr/bin/whateverprogram and associated arguments

[Install]
WantedBy=multi-user.target

Although in the above example I believe the User directive is superfluous.

Alternatively, without implementing some secrets management tool (see hashicorps vault, ansible has a similar feature etc) you're pretty much stuck with two options:

Create a /etc/sudoers.d/somefile with an entry to all a program to be run with elevated privileges without the password. Ie.

ALL ALL=/usr/bin/theprogramtorun NOPASSWD

Or you if you dont care in the slightest about the security of the system and your user is a sudoer you could try scripting up something like:

echo "thisisaterribleidea" | sudo -S /usr/bin/command

To pass the password in cleartext over the commandline

-1

Well,best practice is:

echo "your password" | sudo --stdin command 

This will execute command first then fills the password you entered in the echo statement.

4
  • 1
    This solution has two negative effects. One is that the password will be in history of the shell and the second that you can't enter anything while the command executes. – pbies Nov 26 '16 at 18:38
  • @pbies well the first is a real threat ,i dont care about the second since i am trying to run a script bash on system startup – Suhayb Nov 26 '16 at 18:53
  • You can do that in /etc/rc.local file. – pbies Nov 26 '16 at 18:54
  • 1
    To lower a bit the first fact you may want to cat a private hidden read-only file. Another downside is that you need to review all your scripts when you change your password. – A. Loiseau Nov 26 '16 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.