26

I'm connecting using VPNBook servers and it works fine with this command:

 sudo openvpn --config /etc/openvpn/vpnbook-udp-53.ovpn --auth-user-pass /etc/openvpn/password.txt

but I just can't seem to figure out how to stop it without a reboot.

I've tried service openvpn stop and /etc/init.d/vpnbook stop, but that doesn't seem to affect it.

  • How exactly with ifconfig? – Adam May 23 '13 at 13:59
  • Which one would it be? eth0, lo, tun2, or wlan0 – Adam May 23 '13 at 14:13
  • simply do > sudo /etc/init.d/network-manager restart < – Qasim May 23 '13 at 15:06
  • I am curious, when a VPN is started this way does it not show up in the network manager. I have only always used the network manager connect and disconnect and don't currently have a VPN to test but wondered. – Dennis Feb 19 '14 at 12:49
41

This command definitely works for me, and it should work for you too.

sudo killall openvpn
  • Might require sudo apt-get install psmisc on some builds – geotheory Oct 29 '15 at 22:51
  • I had to kill -9 it on Ubuntu 16.04 (yes I know...) – Gregor Apr 5 at 8:09
11

The successful steps in my case were:

# stop the service    
$ sudo /etc/init.d/openvpn stop

# find the process if for some reason it keeps running
$ lsof -i | grep openvpn

# kill the proccess(s) by its PID
$ kill -9 <PID>

# if necessary restart the service again
$ sudo /etc/init.d/openvpn start


For some reason killall -SIGIN openvpn did not work for me, but the steps above did.

  • Well, this is the best answer in my opinion. Killing process is the weird method, but requesting the service to stop should do things as it must. – Sopalajo de Arrierez Jul 27 '15 at 22:21
  • In general, you shouldn't "kill -9" things until you've tried an interrupt or otherwise cleanly existing it first. Programs can catch an interrupt and do cleanup, but can't catch signal nine (term). Particularly in the case of openvpn, killing it with -9 does not allow the post scripts to run, and very likely will leave now-invalid routes laying around. Ideally, you'd kill -SIGINT, then wait a few seconds for the pid to end, and only go with -SIGTERM / -9 if it didn't exit before that. – dannysauer Aug 16 '18 at 19:44
3

Try this

killall -SIGINT openvpn

You can get more info on different signals you can send here: http://openvpn.net/index.php/open-source/documentation/howto.html#control

  • killall -SIGINT openvpn openvpn(15360): Operation not permitted openvpn: no process found sudo killall -SICINT openvpn SICINT: unknown signal; killall -l lists signals. – Adam May 23 '13 at 13:57
  • 1
    sudo killall openvpn in a new terminal worked for me. – Adam May 24 '13 at 18:09
  • @Adam: it's SIGINT, not SICINT – Dzamo Norton Jul 24 '17 at 10:23
  • The kill and killall commands send SIGTERM by default, which the documentation says has the same effect as SIGINT. So, either would work equivalently - if spelled properly. ;) – dannysauer Aug 16 '18 at 19:47
2

Just hit CTRL+C in the terminal you just started OpenVPN.

  • 2
    What if it was started w/the -daemon (background) flag? It's not possible in this case. – mr-sk Sep 25 '15 at 22:40
  • 1
    Also this leaves 'tun0' as an interface, so it's not possible to restart without rebooting or doing some system config file editing while running. – Dennis Oct 17 '15 at 0:04
  • 1
    What if teh terminal was closed accidentally. ? – varun Apr 21 '16 at 11:43
  • @Dennis ifconfig tun0 down helps in this case. – gnysek Sep 20 '18 at 16:04
2

In case sudo killall openvpn does not finish the job (I experienced it a few times) then a sharp and fatal solution would be:

pgrep openvpn | xargs sudo kill -9
0

after running sudo killall openvpn or service openvpn stop the virtual interface "tun0" would remain opened and referenced in route table, so actually related connections would be lost since openvpn service is killed.

the solution is to delete this virtual connection after killing openvpn service, as it is created everytime when openvpn service gets connected.

so you need to run below commands for disconnecting openvpn:

$ sudo killall openvpn
$ sudo ip link delete tun0
-1

sudo update-rc.d openvpn disable

Or edit the config file in /etc/default/openvpn

sudo nano /etc/default/openvpn

And uncomment the line:

#AUTOSTART="none"

So it looks like:

AUTOSTART="none"

Then you'll have to run:

sudo service openvpn start < vpn-name > to manually start the VPN.

sudo service openvpn stop < vpn-name > to manually stop the VPN.

< vpn-name > is the config file name without .conf extension

located in /etc/openvpn and without the < >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.