Ask / Submit

autostart bash script as root

asked 2014-01-16 22:36:00 +0200

jayki gravatar image

updated 2014-01-18 14:05:52 +0200

lk gravatar image

Hey ;) Does somebody know how to autostart a bash script as root? If i put a .desktop in /etc/xdg/autostart which runs the script it only works as nemo user.. I search for a way to start my script as root, so that i don't need to start it every time i reboot in terminal... I need thsi, because bind mount only works as root :/ Thanks :)

edit retag flag offensive close delete


Did you consider creating a systemd service which would run your script?

strnous ( 2014-01-17 00:15:24 +0200 )edit

I'll try this in /lib/systemd

jayki ( 2014-01-17 01:10:51 +0200 )edit

@jayki It is not just placing your script in /lib/systemd which needs to be done. Please, see i.e. here and/or here

strnous ( 2014-01-17 09:01:22 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2014-02-25 23:59:45 +0200

alex gravatar image

updated 2014-02-26 00:22:37 +0200

I wrote a simple service with a small explanation for another answer to another question in this forum. See here:

You can use it as an example or starting point for creating your own service file and starting your own shell script with root required commands. Perhaps it helps ...

edit flag offensive delete publish link more

answered 2015-06-19 22:12:06 +0200

V10lator gravatar image

updated 2015-06-19 22:16:05 +0200

Another way could be to use sudo.

  1. Install sudo (as root): pkcon install sudo
  2. Install some editor (as root), for example: pkcon install nano
  3. Open visudo with your editor (as root): EDITOR="nano" visudo
  4. Add a line like this: nemo ALL=(ALL) NOPASSWD: /home/nemo/
  5. Create the script /home/nemo/ root) and make it executable (chmod +x). This file will be executed as root later on.
  6. Create another script, like for example /home/nemo/ with the following content:

# Add some code which should be executed as nemo here if you like...
echo "Gaining root rights..."

# Finally become root:
sudo /home/nemo/

That's it. Now execute /home/nemo/ however you like (directly, by /etc/xdg/autostart/something.desktop / as systemd user service / ...).

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools



Asked: 2014-01-16 22:36:00 +0200

Seen: 1,076 times

Last updated: Jun 19 '15