How do I run a script as sudo at boot time?
I need to run ethtool --offload <net> rx off
to disable the annoying jme udp checksum error message.
How do I run a script as sudo at boot time?
I need to run ethtool --offload <net> rx off
to disable the annoying jme udp checksum error message.
You can create a systemd service.
Create a file /etc/systemd/system/ethtool.service
:
[Unit]
Description=ethtool script
[Service]
ExecStart=/path/to/yourscript.sh
[Install]
WantedBy=multi-user.target
And script /path/to/yourscript.sh
(don't forget to chmod +x
it)
#!/bin/bash
ethtool --offload <net> rx off
Enable your service
systemctl enable ethtool
It will run on boot as root.
sudo systemctl start ethtool
to start the service immediately. systemctl status ehttool
to display status (running, enabled and log). Learn more with man systemctl
– Victor Lamoine
Dec 02 '19 at 10:18
Put your commands in /etc/rc.local or create that file if it does not exist:
touch /etc/rc.local
chmod +x /etc/rc.local
All these actions have to be done as root.
/etc/rc.local
is to be seen as legacy measure.
– steffres
Jul 29 '20 at 08:03
root
(the all-powerful user with$UID=0
)".sudo
is a tool for allowing a regular user to run a command asroot
. "at boot" - everything involved with system startup runs asroot
– waltinator Jun 14 '19 at 17:45ethtool
via sudo from something that had dropped privileges (like the wording of this question suggest) would be a really bad idea vs. sticking it in/etc/rc.local
or any more "modern" way to get things run as root during boot. – Peter Cordes Jun 15 '19 at 02:41