Page 1 of 1

sudo commands in /etc/rc.local

Posted: Wed May 14, 2025 10:14 am
by MXRobo
Hello folks,

Just curious, per this post: viewtopic.php?p=819252#p819252
D.O. says to put this command, that requires sudo to run, "put this command in /etc/rc.local, just above the "exit 0" that is in the file by default."

I don't know scripts, and I usually put commands in Session and Startup - or Keyboard Shortcut, but can ALL, MOST, and/or only SPECIFIC commands be place in
/etc/rc.local?
Or, any general comments regarding placing sudo commands in "/etc/rc.local", or any other relatively easy methods of "automatically" running sudo commands?.

Again, just curious.

Thanks

Re: sudo commands in /etc/rc.local

Posted: Wed May 14, 2025 10:19 am
by dolphin_oracle
Session and Startup processes commands at user level, at login to the Xfce desktop. (other desktop environments have similar)

rc.local processes commands as root. There is a difference between sysVinit and systemd when that file is processed. sysVinit processes that file before login. systemd *might* process the file after login, because systemd does things in parallel and it sort of depends how fast you login when that file gets processed. Still processes as root, just may happen later in the startup than one might otherwise expect.

So it depends on what you want to do what is appropriate.

Re: sudo commands in /etc/rc.local

Posted: Wed May 14, 2025 11:29 am
by CharlesV
MXRobo wrote: Wed May 14, 2025 10:14 am
Or, any general comments regarding placing sudo commands in "/etc/rc.local", or any other relatively easy methods of "automatically" running sudo commands?.

Again, just curious.

Thanks
I dont know if this qualifies for your "automatically running" but the following certainly makes my life easier. There are a number of things I run daily, or multiple times daily, that 'require' sudo and I use the following to remove that requirement.

1) Create a new file in the /etc/sudoers.d folder for your application you want to run. (In this example I created: crashplanservice

2) In that file, enter the path to the application your trying to launch, formatted as follows:

Code: Select all

# sudoers file.
 
%users ALL=(root) NOPASSWD: /usr/local/crashplan/bin/CrashPlanService

3) In your ~/bash.rc file, create an alias to that application. ( note you dont NEED this, but it makes it SO much easier! ) At the end of your bash.rc, you would enter the following:

Code: Select all

alias CrashPlanService='sudo /usr/local/crashplan/bin/CrashPlanService'

Now, the next time I want to restart or start the CrashPlan service, all I need to do is run in a terminal (or script)

Code: Select all

CrashPlanService

And this also provides the ability to just add it to the Session and Startup as a script too.

I use this to restart services that get high on ram over time, or to start some applications that require sudo.

There are always some security risks to doing this when your talking about automating 'sudo' rights, but using restraint and understanding WHAT your running is the key imo.