Are the commands in /etc/rc.local
ran by su
by default?
Do I need to specific sudo
before each command or will they be ran by su
regardless?
2 Answers
su
is not a user it's program to run subsequent commands/programs under an alternate identity of another user than the one executing the command. It is very similar to sudo
in that regard.
Unless another user is specified both commands will default to running the command under the alternate identity of the root
user, the superuser/administrator.
The main difference between su
and sudo
is that:
su
requires you to know the password of that alternate user, wheresudo
will prompt for the password of the user running thesudo
command and requires setup so that the user is allowed to run the requested commands/programs.
(When root
runs either su
or sudo
no password is required.)
Like any init script, the /etc/rc.local
script is executed by the root
user and you do not need to prepend either su
or sudo
to the commands/programs that need to run as root.
You may still need to use su
or sudo
in your init scripts if those commands need to be executed not as root
but another user/service-account...
su -
oracle
/do/something/as/oracle/user
-
What do I do if I put su - user /path/to/script.sh in rc.local, and when sourcing it it prompts me for the user password (and closes the terminal afterwards). How do I make it not ask me for the user's password?– alonso sJan 3, 2018 at 1:40
Yes, all the scripts and programs are directly called by root.
The /etc/rc.local
file is called directly by the init process.
-
1So then, we didn't need to add
sudo
before commands in/etc/rc.local
? Jun 5, 2018 at 14:59