Run a sudo command at boot / startup

I am trying to figure out a way to send ssh sudo commands to my raspberry pi osmc at boot.

I am not trying to create new scripts i am only trying to execute existing scripts.

I have a VPN service which has to be started manually through ssh because I have had no luck trying to run it through all different openvpn addons out there.

Thus means that I have to ssh into the PI every time I reboot OSMC.

is there a simple way to add the sudo command booting my vpn connection at osmc boot time? It is a simple commandline such as:

sudo openvpn --daemon --cd /etc/openvpn --config UK.ovpn

How do i do that?

I have tried to make systemctl to do it for me but it does not work:

sudo systemctl enable openvpn@UK

Even in sudo su

Thank you for your help.

Try adding the command to /etc/rc.local
which will get executed after bootup. You will need to add the full path to rc.local.
So run

which openvpn

Get the full path and add to rc.local:

/path/openvpn --daemon --cd /etc/openvpn --config UK.ovpn

Hi,

Systemctl should work, try this:

sudo cp /etc/openvpn/UK.ovpn /etc/openvpn/UK.conf

sudo nano /etc/default/openvpn

in the AUTOSTART section add:

AUTOSTART=UK

Now try

sudo systemctl start openvpn@UK

If it connects, issue the following:

sudo systemctl disable openvpn@UK
sudo systemctl enable openvpn

Then reboot and confirm the vpn tunnel is up.

Thanks Tom.

Hi. Thank you for your input.
I was not able to transfer the config file into /etc/openvpn folder i could only copy it into /home/osmc/openVPN-Config/

Do I have to use that path in autostart and in the following sudo command ?

I have tried several combinations but with no luck:

Error: failed to start openvpn connection to UK
Openvpn@uk.service: unit entered failed state
Openvpn@uk.service: Failed with result ‘exit-code’

As stated before vpn connection works when I ssh sudo it manually

Thank you for any input

Do you realize how difficult it is to help someone when they give a vague description of a problem like that? How about a telling us what happened when you tried to copy the file?

Did you sudo when you tried the copy?

1 Like

Thank you. It worked perfectly.