To execute commands on Linux startup, add them to /etc/rc.local:
sudo nano /etc/rc.local
The default content of this file starts with:
#!/bin/sh
And ends with:
exit 0
Any commands you want to execute must be placed between these two lines.
If the file does not exist, create it and make sure it is owned by root with permissions set to 755:
sudo chown root: /etc/rc.local sudo chmod 755 /etc/rc.local
Verify that rc-local.service is running and enabled to start at boot:
sudo systemctl status rc-local.service sudo systemctl enable rc-local.service
This procedure applies to most Debian-based Linux distributions, but if you are using something other than Ubuntu 20.04 or Raspberry Pi OS, check for any distribution-specific differences.