0

I want to run a bash command at startup (~/.config/autostart/myCommand.desktop) that requires sudo, but rather than it prompting me every time, I would like to include the password in the command, something like:

sudo --some-flag [PASSWORD] [command]

I have seen answers suggesting to change sudoers, etc. but I am wondering if something more like what I said is possible.

Joe D
  • 63
  • 4
    That would be horrible, as then the password would then be exposed e.g. to ps(1) that any user on the system might snoop on. – thrig Sep 02 '15 at 16:03
  • cant you run the script as root and avoid that? from within /etc/rc.d/ for example – Recct Sep 02 '15 at 16:05
  • Run the entire script under sudo so you only need to provide the password once, when you start the script. If you don't want to provide a password at all, update the question to say so. – Chris Davies Sep 02 '15 at 16:20
  • It's in autostart, more specifically, one command in a .desktop file – Joe D Sep 02 '15 at 16:29
  • 1
    if it's a single command your best bet is to give permissions to run only that command using sudo without a password – Centimane Sep 02 '15 at 17:04

1 Answers1

0

Running your startup script with sudo wouldn't make any sense. sudo is for running commands that require root privileges as a regular user without needing to login as root. It's not meant for startup scripts, that's what systemd or init.d scripts are for.

A relatively easy solution would be to add your script to the root user's crontab like so:

sudo crontab -e

Add this line:

@reboot /path/to/your/script.sh

This will run at startup as the root user, bypassing any need for interactive authentication.