19

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 2

21

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, where
  • sudo will prompt for the password of the user running the sudo 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

1
  • 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 s
    Jan 3, 2018 at 1:40
12

Yes, all the scripts and programs are directly called by root.

The /etc/rc.local file is called directly by the init process.

1
  • 1
    So then, we didn't need to add sudo before commands in /etc/rc.local? Jun 5, 2018 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .