Starting a torrent client automatically via route-up, sudo: Permission denied

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
Ter
OpenVpn Newbie
Posts: 2
Joined: Thu Apr 01, 2021 9:53 am

Starting a torrent client automatically via route-up, sudo: Permission denied

Post by Ter » Thu Apr 01, 2021 10:18 am

I have a route-up script that checks for dnsleaks via the ipleak.net/json api and if everything is fine then starts another script that should run qbittorrent on my Kubuntu 20.04 VirtualBox. I had a few problems with starting qbittorrent because a few environment variables were missing but I managed to find them using `env` and then just apply them inside the script. The script now runs fine whenever OpenVPN is started via the following command:

Code: Select all

sudo openvpn --config /etc/openvp/file.conf
When I configured /etc/default/openvpn to start the .conf file and restarted the machine or just ran

Code: Select all

sudo service openvpn restart
I have noticed that qbittorrent has not started and decided to check /var/log/syslog. To my surprise the script couldn't open qbittorrent because /home/vbox doesn't exist when the script runs. I checked it by adding the following to the script:

Code: Select all

/bin/ls -ldt /home/vbox
The directory exists when I check it via Konsole/Terminal and start openvpn via --config, but it doesn't when OpenVPN is started as a service.

The following lines are shown in syslog

Code: Select all

Apr  1 11:47:28 vbox openvpn[3770]: /bin/ls: cannot access '/home/vbox': No such file or directory
Apr  1 11:47:28 vbox openvpn[3772]: sudo: unable to change directory to /home/vbox: Permission denied
Apr  1 11:47:28 vbox openvpn[3771]: sudo: unable to execute /bin/bash: Permission denied
The first error is when I run the /bin/ls command to check if the directory exist and the two other are when the qbittorrent start-up script is supposed to start as the user via the following command:

Code: Select all

sudo -i -u vbox /etc/openvpn/qbit-startup &
/etc/openvpn/qbit-startup:

Code: Select all

#!/bin/bash
# This script starts qbittorrent as vbox user from root executed script (OpenVPN)
# It has to be started as the user via `sudo -i -u USER`

echo "Starting qbittorrent"
export XDG_RUNTIME_DIR=/run/user/1000
export DISPLAY=:0
export KDE_FULL_SESSION=true
setsid qbittorrent &>/dev/null
This script doesn't run at all. Would anyone know why /home/vbox does not exist in the script when OpenVPN is started as a service?

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: Starting a torrent client automatically via route-up, sudo: Permission denied

Post by TinCanTech » Thu Apr 01, 2021 1:06 pm

When you start openvpn via systemctl the systemd-unit file imposes many security restrictions,
which is probably why --route-up cannot execute the script.

Ter
OpenVpn Newbie
Posts: 2
Joined: Thu Apr 01, 2021 9:53 am

Re: Starting a torrent client automatically via route-up, sudo: Permission denied

Post by Ter » Thu Apr 01, 2021 5:23 pm

would there be a way around that?

Post Reply