sudo commands in /etc/rc.local

Message
Author
MXRobo
Posts: 1835
Joined: Thu Nov 14, 2019 12:09 pm

sudo commands in /etc/rc.local

#1 Post 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

User avatar
dolphin_oracle
Developer
Posts: 22460
Joined: Sun Dec 16, 2007 12:17 pm

Re: sudo commands in /etc/rc.local

#2 Post 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.
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.
Live system help document: https://mxlinux.org/wiki/help-antix-live-usb-system/

User avatar
CharlesV
Global Moderator
Posts: 7655
Joined: Sun Jul 07, 2019 5:11 pm

Re: sudo commands in /etc/rc.local

#3 Post 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.
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

Post Reply

Return to “Software / Configuration”