client-connect not working

How to customize and extend your OpenVPN installation.

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

Post Reply
john_paul
OpenVpn Newbie
Posts: 6
Joined: Sun Oct 20, 2019 10:04 am

client-connect not working

Post by john_paul » Sun Oct 20, 2019 11:16 am

I am trying to figure out what I'm doing wrong. I have the following lines in my server.conf file

script-security 2
client-connect /etc/openvpn/scripts/connect.sh

and the connect.sh file has the following content

#!/bin/bash
/usr/bin/touch /tmp/connected

with chmod 755 permissions on the script file. Yet when a client connects nothing appears in the /tmp/ directory.
The openvpn.log file has no mention of running a client-connect script. How can I diagnose this problem?

Here is my full config file (minus sensitive information)

server.conf
dev tun
proto udp
port 1194
ca /etc/openvpn/easy-rsa/pki/ca.crt
cert /etc/openvpn/easy-rsa/pki/issued/********.crt
key /etc/openvpn/easy-rsa/pki/private/********.key
dh none
topology subnet
server 10.8.0.0 255.255.255.0
# Set your primary domain name server address for clients
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
# Prevent DNS leaks on Windows
push "block-outside-dns"
# Override the Client default gateway by using 0.0.0.0/1 and
# 128.0.0.0/1 rather than 0.0.0.0/0. This has the benefit of
# overriding but not wiping out the original default gateway.
client-config-dir ccd
script-security 2
client-connect /etc/openvpn/scripts/connect.sh
client-to-client
keepalive 1800 3600
remote-cert-tls client
tls-version-min 1.2
tls-crypt /etc/openvpn/easy-rsa/pki/ta.key
cipher AES-256-CBC
auth SHA256
user nobody
group nogroup
persist-key
persist-tun
crl-verify /etc/openvpn/crl.pem
status /var/log/openvpn-status.log 20
status-version 3
syslog
verb 3
#DuplicateCNs allow access control on a less-granular, per user basis.
#Remove # if you will manage access by user instead of device.
#duplicate-cn
# Generated for use by PiVPN.io

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

Re: client-connect not working

Post by TinCanTech » Sun Oct 20, 2019 5:43 pm

What operating system ?

john_paul
OpenVpn Newbie
Posts: 6
Joined: Sun Oct 20, 2019 10:04 am

Re: client-connect not working

Post by john_paul » Sun Oct 20, 2019 10:24 pm

Raspbian 9.1 (stretch).
I installed OpenVPN with PiVPN.

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

Re: client-connect not working

Post by TinCanTech » Mon Oct 21, 2019 12:32 am

Take a look at the systemd unit file.

john_paul
OpenVpn Newbie
Posts: 6
Joined: Sun Oct 20, 2019 10:04 am

Re: client-connect not working

Post by john_paul » Mon Oct 21, 2019 2:29 pm

This is the contents of /lib/systemd/system/openvpn.service

Code: Select all

[Unit]
Description=OpenVPN service
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecReload=/bin/true
WorkingDirectory=/etc/openvpn

[Install]
WantedBy=multi-user.target
Is there something wrong with this?
Thanks for the suggestion.

john_paul
OpenVpn Newbie
Posts: 6
Joined: Sun Oct 20, 2019 10:04 am

Re: client-connect not working

Post by john_paul » Mon Oct 21, 2019 3:22 pm

OK, I found it. There were several other systemd files including:
/lib/systemd/system/openvpn@.service
/lib/systemd/system/openvpn-server@.service
which had the setting

Code: Select all

PrivateTmp=true
This was causing the problem.
Thanks for making me double check!

Post Reply