{"id":1776,"date":"2017-02-18T22:45:15","date_gmt":"2017-02-18T21:45:15","guid":{"rendered":"http:\/\/www.itayemi.com\/blog\/?p=1776"},"modified":"2017-02-20T18:12:44","modified_gmt":"2017-02-20T17:12:44","slug":"setting-up-an-openvpn-access-server","status":"publish","type":"post","link":"https:\/\/www.itayemi.com\/blog\/2017\/02\/18\/setting-up-an-openvpn-access-server\/","title":{"rendered":"Setting up an OpenVPN access server"},"content":{"rendered":"<p>This post is strictly geeky stuff so feel free to skip and check out the poetry and short stories instead (don&#8217;t leave until you do! Thanks!)<\/p>\n<p>A friend\/colleague contacted me a couple of days ago and asked if I know how to set up an OpenVPN server. He said he took a look at the website (openvpn.net) and that the instructions there are not that easy to follow. Nothing challenges me more than getting IT-related stuff to work &#8211; figuring stuff out. And also, he said there might be some $$ involved.<br \/>\nI knew what OpenVPN was but had never set up a server before. It took 2 days and nights to figure the stuff out completely. One thing I don&#8217;t like is having to repeat the same process for the same thing in future, so I almost always &#8220;document&#8221; the procedure(s).<\/p>\n<p>Once it is nicely summarized (as below), it then looks quite easy, but it is not! (stroking my own ego a little :-).<\/p>\n<p>Let&#8217;s go!<\/p>\n<p><strong>Setting up an OpenVPN access server on Linux (with a Windows Client)<\/strong><\/p>\n<p>1. Install Open-VPN server<br \/>\nNOTE: The \/etc\/init.d\/openvpn service control script comes from the openvpn-AS server package but it&#8217;s easy<br \/>\nto create one. I have attached a copy (should be in the same directory as this howto)<\/p>\n<p># yum install openssl-devel lzo-devel pam-devel<br \/>\n# yum install rpm-build<br \/>\n# rpmbuild -tb openvpn-2.4.0.tar.gz<br \/>\n# rpm -Uvh \/root\/rpmbuild\/RPMS\/x86_64\/openvpn-2.4.0-1.x86_64.rpm<\/p>\n<p>2. Copy or create \/etc\/init.d\/openvpn (so you can use the service command to control the service)<\/p>\n<p>3. Install\/download EasyRSA for creating the CA (Ceritification Authority) as well as certificates for clients:<\/p>\n<p>download scripts package from https:\/\/github.com\/OpenVPN\/easy-rsa<\/p>\n<p>cd \/tmp<br \/>\nunzip easy-rsa-master.zip<br \/>\ncp -R \/tmp\/easy-rsa-master\/easyrsa3 \/etc\/openvpn\/<\/p>\n<p>4. Copy the sample config files folder to \/etc\/openvpn<br \/>\ncp \/usr\/share\/doc\/openvpn-2.4.0\/sample\/sample-config-files\/server.conf \/etc\/openvpn\/<br \/>\ncp \/usr\/share\/doc\/openvpn-2.4.0\/sample\/sample-config-files\/client.conf \/etc\/openvpn\/<br \/>\ncp \/usr\/share\/doc\/openvpn-2.4.0\/sample\/sample-config-files\/openvpn-startup.sh \/etc\/openvpn\/openvpn-startup<br \/>\ncp \/usr\/share\/doc\/openvpn-2.4.0\/sample\/sample-config-files\/openvpn-shutdown.sh \/etc\/openvpn\/openvpn-shutdown<\/p>\n<p>5. You should edit openvpn-shutdown and change the line &#8220;killall -TERM openvpn&#8221; to &#8220;killall -TERM \/usr\/sbin\/openvpn&#8221;<br \/>\n(reason is that when you use &#8220;service openvpn restart|shutdown&#8221;, killall kills the service command as well)<\/p>\n<p>6. You have to edit the server.conf to reflect the location of files relative to the \/etc\/opevpn folder.<br \/>\nFor example, the entry &#8220;dh dh2048.pem&#8221; in server.conf needs to reflect where you actually put the dh2048.pem file.<br \/>\nIf you put the files directly in \/etc\/openvpn then nothing needs to change, but if you decide for management<br \/>\npurposes to put the file in a subfolder (e.g., in \/etc\/openvpn\/keys\/ then the entry in server.conf would be &#8220;dh keys\/dh2048.pem&#8221;) the entries would have to change. Same applies to entries for &#8220;ca&#8221;, &#8220;cert&#8221;, and &#8220;key&#8221;.<\/p>\n<p>7. This option in server.conf is to protected against DDoS (either follow the instructions or comment it out)<br \/>\ntls-auth ta.key 0 # This file is secret<\/p>\n<p>8. The 3 lines below are at the bottom of file openvpn-startup. Comment them out or create the vpn*.conf files.<br \/>\nI don&#8217;t think they are needed unless you have a need to have deamons with different configs e.g., say a deamon for different companies connecting to your server.<br \/>\nopenvpn &#8211;cd $dir &#8211;daemon &#8211;config vpn1.conf<br \/>\nopenvpn &#8211;cd $dir &#8211;daemon &#8211;config vpn2.conf<br \/>\nopenvpn &#8211;cd $dir &#8211;daemon &#8211;config vpn2.conf<\/p>\n<p>9. Creating the various certificates:<\/p>\n<p># cd \/etc\/openvpn\/easyrsa3\/<\/p>\n<p>[root@gfs2 easyrsa3]# cp vars.example vars<\/p>\n<p>10. Edit the vars file and set the following variables according to your needs:<\/p>\n<p>[root@gfs2 easyrsa3]# vi vars<\/p>\n<p>set_var EASYRSA_REQ_COUNTRY &#8220;NG&#8221;<br \/>\nset_var EASYRSA_REQ_PROVINCE &#8220;LA&#8221;<br \/>\nset_var EASYRSA_REQ_CITY &#8220;Lagos&#8221;<br \/>\nset_var EASYRSA_REQ_ORG &#8220;Samson Inc.&#8221;<br \/>\nset_var EASYRSA_REQ_EMAIL &#8220;sam@company.net&#8221;<br \/>\nset_var EASYRSA_REQ_OU &#8220;IT Organizational Unit&#8221;<br \/>\nset_var EASYRSA_REQ_CN=gfs2.company.com<br \/>\nset_var EASYRSA_REQ_NAME=server<\/p>\n<p>[root@gfs2 easyrsa3]#<\/p>\n<p>11. Initialize the PKI (you only need to do this once for a fresh setup):<\/p>\n<p>[root@gfs2 easyrsa3]# .\/easyrsa init-pki<\/p>\n<p>12. Create the CA:<br \/>\nAnswer 2 questions below (Common Name e.g., the name of the server, and the PEM passphrase &#8211; use any phrase)<\/p>\n<p>[root@gfs2 easyrsa3]# .\/easyrsa build-ca<\/p>\n<p>13. Remove the passphrase (because we are running openvpn daemon non-interactively so no way to enter the phrase)<br \/>\nYou will be prompted for the same passphrase you entered above when creating the certificate:<\/p>\n<p># cd \/etc\/openvpn\/easyrsa3\/pki\/private<br \/>\n# openssl rsa -in ca.key -out ca.key2<br \/>\n[root@gfs2 private]# mv ca.key ca.key.org<br \/>\n[root@gfs2 private]# mv ca.key2 ca.key<br \/>\n[root@gfs2 private]# cd \/etc\/openvpn\/easyrsa3\/<\/p>\n<p>14. Generate the Diffie hellman parameters (DH):<br \/>\n[root@gfs2 easyrsa3]# .\/easyrsa gen-dh<\/p>\n<p>15. Generate the CRL:<br \/>\n[root@gfs2 easyrsa3]# .\/easyrsa gen-crl<\/p>\n<p>16. Generate a certificate for the server (use any passphrase. We will remove it):<br \/>\nIn the example below, gfs2 is the name of my server.<\/p>\n<p>[root@gfs2 easyrsa3]# .\/easyrsa build-server-full gfs2<br \/>\n# cd \/tmp\/easy-rsa-master\/easyrsa3\/pki\/private\/<br \/>\n# openssl rsa -in gfs2.key -out gfs2.key2<br \/>\n# mv gfs2.key gfs2.key.org<br \/>\n# mv gfs2.key2 gfs2.key<\/p>\n<p>17. Copy all the files to your \/etc\/openvpn\/ folder<br \/>\n[root@gfs2 easyrsa3]# cd \/etc\/openvpn\/<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/crl.pem .<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/dh.pem .<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/ca.crt .<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/private\/ca.key .<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/private\/gfs2.key .<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/issued\/gfs2.crt .<br \/>\n[root@gfs2 openvpn]# cp easyrsa3\/pki\/ca.crt \/etc\/openvpn\/clients\/<\/p>\n<p>18. Edit server.conf in \/etc\/openvpn\/ and make the necessary changes. The 3 lines in server.conf show below reflects the files created above:<br \/>\nca ca.crt<br \/>\ncert gfs2.crt<br \/>\nkey gfs2.key<\/p>\n<p>19. Generate certificates for your clients (repeat for various clients using unique names in the process):<br \/>\nYou will be prompted for a passphrase. Use any, we will remove it. In the example below, remoteclient1 is the name of a unique CN (Common Name) I am using for a client. Note that this does not have to be the actual name on the client.<br \/>\nBut it is this name you will enter in the configuration of your VPN client on your remote client. This will then<br \/>\nallow the OpenVPN server to match the name to a specific configuration (if any) and client certificates on the server.<\/p>\n<p># cd \/etc\/openvpn\/easyrsa3<br \/>\n[root@gfs2 easyrsa3]# .\/easyrsa build-client-full remoteclient1<br \/>\n[root@gfs2 easyrsa3]# cd pki\/private\/<\/p>\n<p>20. Remove the passphrase on the certificate (you will be prompted for the same passphrase you used above):<br \/>\n[root@gfs2 private]# openssl rsa -in remoteclient1.key -out remoteclient1.key2<br \/>\n[root@gfs2 private]# mv remoteclient1.key remoteclient1.key.org<br \/>\n[root@gfs2 private]# mv remoteclient1.key2 remoteclient1.key<br \/>\n[root@gfs2 private]# cp remoteclient1.key \/etc\/openvpn\/clients\/<br \/>\n[root@gfs2 private]# cp ..\/issued\/remoteclient1.crt \/etc\/openvpn\/clients\/<\/p>\n<p>21. Copy\/Send the necessary certificates to the client (should be done as securely as possible)<br \/>\nca.crt, remoteclient1.crt and remoteclient1.key (for my sample client)<\/p>\n<p>22. On my sample Windows client. I am using SecurePoint SSL VPN v2<br \/>\n&#8211; I downloaded version 2.0.18 from https:\/\/sourceforge.net\/projects\/securepoint\/<br \/>\n&#8211; Install it and run it.<br \/>\n&#8211; In the system-tray, right-click on the icon and choose &#8220;show window&#8221; from the menu<br \/>\n&#8211; Click on the settings icon (gear wheel in the lowe right-hand corner of the application window) and choose &#8220;New&#8221; fro the menu.<br \/>\n&#8211; Follow the wizard to create a new VPN connection.<br \/>\n&#8211; give the config a name; next;<br \/>\n&#8211; enter the IP address of FQDN of the VPN access server and change the port and protocol if necessary (must match the one on the server as defined in server.conf); next<br \/>\n&#8211; you are prompted for the location of 3 files you transferred to the client above: &#8220;Root CA:&#8221;; &#8220;Certificate:&#8221;; and &#8220;Key:&#8221;<br \/>\n&#8220;Root CA:&#8221; = ca.crt; &#8220;Certificate:&#8221; = remoteclient1.crt; and &#8220;Key:&#8221; = remoteclient1.key<br \/>\n&#8211; the &#8220;Advanced Settings&#8221; screen is next. IMPORTANT: You have to change the cipher (defaul is &#8220;Standard&#8221;) to the one configured in the server.conf file on the VPN access server. Current default is AES-256-CBC. If you don&#8217;t change it, you will still get connected but no real traffic will flow over the VPN (you won&#8217;t get any service or connectivity). You can also &#8220;Comp-LZO&#8221; compression; next<br \/>\n&#8211; Conclusion screen shows you a summary of your choices. Click the &#8220;Finish&#8221; button if everything looks OK<br \/>\n&#8211; Your new VPN connection config will appear in the Window of the VPN client. Right-click on it and choose &#8220;Connect&#8221;<br \/>\n&#8211; The next 2 screens will ask for your username and password. Both answers are the name of the client we used to create the certificate which is remoteclient1. You can also select the &#8220;Save Data&#8221; on both questions to have the VPN client remember your answers.<br \/>\n&#8211; The VPN connection to the server should be established once you press OK for the 2 questions above.<\/p>\n<p>23. Suggested optional step: to configure OpenVPN to log into it&#8217;s own log file and not \/var\/log\/messages (especially if you are debugging issues.)<br \/>\nEdit server.conf and change the log-append line (it is likely to be commented out. So remove the &#8220;;&#8221; at the begining of the line).<\/p>\n<p>log-append \/var\/log\/openvpn.log<\/p>\n<p>24. Optionally install Web-pased connection monitor<\/p>\n<p>&#8211; Download it from https:\/\/github.com\/furlongm\/openvpn-monitor\/<\/p>\n<p>&#8211; You need to install the semanticversion package to run the openvpn-monitor successfully<\/p>\n<p>&#8211; Use pip to install the semantic_version package:<br \/>\n# yum install python-pip<br \/>\n# pip install semantic_version<\/p>\n<p>Alternatively if for some reason you can&#8217;t install pip, you can install the semantic_version &#8220;manually&#8221; with python:<\/p>\n<p># cd \/tmp<br \/>\n# git clone git:\/\/github.com\/rbarrois\/python-semanticversion.git<br \/>\n# cd python-semanticversion<br \/>\n# python setup.py install<\/p>\n<p>&#8211; Then continue with installation instructions on the openvpn-monitor webpage above (start from the section for your Operating System)<\/p>\n<p>NOTE: on RHEL\/CentOS 6.x, you may need to edit \/var\/www\/html\/openvpn-monitor\/openvpn-monitor.conf and enter the coordinates of your starting point (probably the location of your server). You can get the &#8220;DD coordinates&#8221; (for longitude and latitude) for your location (I was able to get the coords for my campus) from http:\/\/latitude.to\/ for example. You can also try https:\/\/www.distancesto.com\/coordinates.php<\/p>\n<p>25. Restart (start) the OpenVPN service (any errors will be in file \/var\/log\/messages)<br \/>\n# service openvpn restart<\/p>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nNOTES:<\/p>\n<p>1. You may need to enable ipv4 forwarding if you want the remote clients to connect to other systems on the network of the VPN access server. The community version seems to do this by default but not sure of the commercial version (&#8220;sysctl -w net.ipv4.ip_forward=1&#8221; )<br \/>\nYou will also need to edit server.conf and use the &#8220;push route&#8221; option so that the routes to (private) subnets &#8220;behind&#8221; the VPN server is sent to the clients if required (so the clients can reach other systems on those private subnets)<\/p>\n<p>2. GUI for OpenVPN server on Windows:<br \/>\ndownload from https:\/\/github.com\/OpenVPN\/openvpn-gui<\/p>\n<p>3. Alternative GUI-based way to control OpenVPN via Webmin module. Not worth the trouble as the developer&#8217;s website is not in English and not sure how up to date the module is. Not recommended.<\/p>\n<p>yum install perl<br \/>\nyum install perl-Net-SSLeay<br \/>\nwget http:\/\/prdownloads.sourceforge.net\/webadmin\/webmin-1.831-1.noarch.rpm<br \/>\nrpm -Uvh wget webmin-1.831-1.noarch.rpm<br \/>\ndownload openvpn-2.6.wbm.gz from http:\/\/www.openit.it\/index.php\/it\/openvpnadmin and use Webmin to install it.<br \/>\nThe module can generate certificates but I found it much more troublesome than the direct approach I used above.<\/p>\n<p>4. There are various other options you may need to change in server.conf (and which must match on the client as well) to further optimize your setup.<\/p>\n<p>5. Systems used in the config above (3x VMs running on VMWare workstation 12.5.2 on a HP EliteBook 840 &#8211; Windows 7, 16GB RAM, Intel Core i7 vPro):<br \/>\na. Red Hat Enterprise Linux Server release 6.3 &#8211; OpenVPN 2.4.0 access server<br \/>\nb. Windows 8 (VPN client)<br \/>\nc. Windows XP (system &#8220;behind&#8221; VPN server on a private subnet)<\/p>\n<p>6. Some other install guide:<br \/>\nhttp:\/\/www.ciscopress.com\/articles\/article.asp?p=605499<br \/>\nhttps:\/\/help.ubuntu.com\/lts\/serverguide\/openvpn.html<br \/>\nhttps:\/\/openvpn.net\/index.php\/open-source\/documentation\/howto.html#security<br \/>\nhttps:\/\/openvpn.net\/index.php\/access-server\/docs\/quick-start-guide.html<br \/>\nhttps:\/\/openvpn.net\/index.php\/open-source\/documentation\/howto.html#install<br \/>\nhttps:\/\/www.digitalocean.com\/community\/tutorials\/how-to-setup-and-configure-an-openvpn-server-on-centos-6<\/p>\n<p>7. There several other clients for Windows, MAC, etc on the Internet. Some are free (open source\/closed-source) and some are commercial\/proprietary. Each has it&#8217;s own idiosyncrasies. I found it difficult getting the OpenVPN client to work with the OpenVPN server I set up above, but it worked seamlessly with their own OpenVPN AS VPN server (the commercial version of the OpenVPN server that comes with a management GUI).<\/p>\n<p>8. Keywords or Tags: PKI,SecurePoint,OpenVPN,VPN,Diffie hellman,EasyRSA,RedHat,rpmbuild,github,Linux<\/p>\n<p>9. The content of the \/etc\/init.d\/openvpn service control script. You can add the service to run-levels 345 so it starts automatically whenever you (re)start the server (command &#8220;chkconfig &#8211;add openvpn&#8221;).<\/p>\n<p>#!\/bin\/sh<br \/>\n#<br \/>\n# openvpn This shell script takes care of starting and stopping<br \/>\n# openvpn on RedHat or other chkconfig-based system.<br \/>\n#<br \/>\n# chkconfig: 345 24 76<br \/>\n#<br \/>\n# description: OpenVPN is a robust and highly flexible tunneling application \\<br \/>\n# that uses all of the encryption, authentication, and \\<br \/>\n# certification features of the OpenSSL library to securely \\<br \/>\n# tunnel IP networks over a single UDP port.<br \/>\n#<\/p>\n<p># Contributed to the OpenVPN project by<br \/>\n# Douglas Keller &lt;doug_at_voidstar.dyndns.org&gt;<br \/>\n# 2002.05.15<\/p>\n<p># To install:<br \/>\n# copy this file to \/etc\/rc.d\/init.d\/openvpn<br \/>\n# shell&gt; chkconfig &#8211;add openvpn<br \/>\n# shell&gt; mkdir \/etc\/openvpn<br \/>\n# make .conf or .sh files in \/etc\/openvpn (see below)<\/p>\n<p># To uninstall:<br \/>\n# run: chkconfig &#8211;del openvpn<\/p>\n<p># Author&#8217;s Notes:<br \/>\n#<br \/>\n# I have created an \/etc\/init.d init script and enhanced openvpn.spec to<br \/>\n# automatically register the init script. Once the RPM is installed you<br \/>\n# can start and stop OpenVPN with &#8220;service openvpn start&#8221; and &#8220;service<br \/>\n# openvpn stop&#8221;.<br \/>\n#<br \/>\n# The init script does the following:<br \/>\n#<br \/>\n# &#8211; Starts an openvpn process for each .conf file it finds in<br \/>\n# \/etc\/openvpn.<br \/>\n#<br \/>\n# &#8211; If \/etc\/openvpn\/xxx.sh exists for a xxx.conf file then it executes<br \/>\n# it before starting openvpn (useful for doing openvpn &#8211;mktun&#8230;).<br \/>\n#<br \/>\n# &#8211; In addition to start\/stop you can do:<br \/>\n#<br \/>\n# service openvpn reload &#8211; SIGHUP<br \/>\n# service openvpn reopen &#8211; SIGUSR1<br \/>\n# service openvpn status &#8211; SIGUSR2<br \/>\n#<br \/>\n# Modifications:<br \/>\n#<br \/>\n# 2003.05.02<br \/>\n# * Changed == to = for sh compliance (Bishop Clark).<br \/>\n# * If condrestart|reload|reopen|status, check that we were<br \/>\n# actually started (James Yonan).<br \/>\n# * Added lock, piddir, and work variables (James Yonan).<br \/>\n# * If start is attempted twice, without an intervening stop, or<br \/>\n# if start is attempted when previous start was not properly<br \/>\n# shut down, then kill any previously started processes, before<br \/>\n# commencing new start operation (James Yonan).<br \/>\n# * Do a better job of flagging errors on start, and properly<br \/>\n# returning success or failure status to caller (James Yonan).<br \/>\n#<br \/>\n# 2005.04.04<br \/>\n# * Added openvpn-startup and openvpn-shutdown script calls<br \/>\n# (James Yonan).<br \/>\n#<\/p>\n<p># Location of openvpn binary<br \/>\nopenvpn=&#8221;&#8221;<br \/>\nopenvpn_locations=&#8221;\/usr\/sbin\/openvpn \/usr\/local\/sbin\/openvpn&#8221;<br \/>\nfor location in $openvpn_locations<br \/>\ndo<br \/>\nif [ -f &#8220;$location&#8221; ]<br \/>\nthen<br \/>\nopenvpn=$location<br \/>\nfi<br \/>\ndone<\/p>\n<p># Lockfile<br \/>\nlock=&#8221;\/var\/lock\/subsys\/openvpn&#8221;<\/p>\n<p># PID directory<br \/>\npiddir=&#8221;\/var\/run\/openvpn&#8221;<\/p>\n<p># Our working directory<br \/>\nwork=\/etc\/openvpn<\/p>\n<p># Source function library.<br \/>\n. \/etc\/rc.d\/init.d\/functions<\/p>\n<p># Source networking configuration.<br \/>\n. \/etc\/sysconfig\/network<\/p>\n<p># Check that networking is up.<br \/>\nif [ ${NETWORKING} = &#8220;no&#8221; ]<br \/>\nthen<br \/>\necho &#8220;Networking is down&#8221;<br \/>\nexit 0<br \/>\nfi<\/p>\n<p># Check that binary exists<br \/>\nif ! [ -f $openvpn ]<br \/>\nthen<br \/>\necho &#8220;openvpn binary not found&#8221;<br \/>\nexit 0<br \/>\nfi<\/p>\n<p># See how we were called.<br \/>\ncase &#8220;$1&#8243; in<br \/>\nstart)<br \/>\necho -n $&#8221;Starting openvpn: &#8221;<\/p>\n<p>\/sbin\/modprobe tun &gt;\/dev\/null 2&gt;&amp;1<\/p>\n<p># From a security perspective, I think it makes<br \/>\n# sense to remove this, and have users who need<br \/>\n# it explictly enable in their &#8211;up scripts or<br \/>\n# firewall setups.<\/p>\n<p>#echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward<\/p>\n<p># Run startup script, if defined<br \/>\nif [ -f $work\/openvpn-startup ]; then<br \/>\n$work\/openvpn-startup<br \/>\nfi<\/p>\n<p>if [ ! -d $piddir ]; then<br \/>\nmkdir $piddir<br \/>\nfi<\/p>\n<p>if [ -f $lock ]; then<br \/>\n# we were not shut down correctly<br \/>\nfor pidf in `\/bin\/ls $piddir\/*.pid 2&gt;\/dev\/null`; do<br \/>\nif [ -s $pidf ]; then<br \/>\nkill `cat $pidf` &gt;\/dev\/null 2&gt;&amp;1<br \/>\nfi<br \/>\nrm -f $pidf<br \/>\ndone<br \/>\nrm -f $lock<br \/>\nsleep 2<br \/>\nfi<\/p>\n<p>rm -f $piddir\/*.pid<br \/>\ncd $work<\/p>\n<p># Start every .conf in $work and run .sh if exists<br \/>\nerrors=0<br \/>\nsuccesses=0<br \/>\nfor c in `\/bin\/ls *.conf 2&gt;\/dev\/null`; do<br \/>\nbn=${c%%.conf}<br \/>\nif [ -f &#8220;$bn.sh&#8221; ]; then<br \/>\n. .\/$bn.sh<br \/>\nfi<br \/>\nrm -f $piddir\/$bn.pid<br \/>\n$openvpn &#8211;daemon &#8211;writepid $piddir\/$bn.pid &#8211;config $c &#8211;cd $work<br \/>\nif [ $? = 0 ]; then<br \/>\nsuccesses=1<br \/>\nelse<br \/>\nerrors=1<br \/>\nfi<br \/>\ndone<\/p>\n<p>if [ $errors = 1 ]; then<br \/>\nfailure; echo<br \/>\nelse<br \/>\nsuccess; echo<br \/>\nfi<\/p>\n<p>if [ $successes = 1 ]; then<br \/>\ntouch $lock<br \/>\nfi<br \/>\n;;<br \/>\nstop)<br \/>\necho -n $&#8221;Shutting down openvpn: &#8221;<br \/>\nfor pidf in `\/bin\/ls $piddir\/*.pid 2&gt;\/dev\/null`; do<br \/>\nif [ -s $pidf ]; then<br \/>\nkill `cat $pidf` &gt;\/dev\/null 2&gt;&amp;1<br \/>\nfi<br \/>\nrm -f $pidf<br \/>\ndone<\/p>\n<p># Run shutdown script, if defined<br \/>\nif [ -f $work\/openvpn-shutdown ]; then<br \/>\n$work\/openvpn-shutdown<br \/>\nfi<\/p>\n<p>success; echo<br \/>\nrm -f $lock<br \/>\n;;<br \/>\nrestart)<br \/>\n$0 stop<br \/>\nsleep 2<br \/>\n$0 start<br \/>\n;;<br \/>\nreload)<br \/>\nif [ -f $lock ]; then<br \/>\nfor pidf in `\/bin\/ls $piddir\/*.pid 2&gt;\/dev\/null`; do<br \/>\nif [ -s $pidf ]; then<br \/>\nkill -HUP `cat $pidf` &gt;\/dev\/null 2&gt;&amp;1<br \/>\nfi<br \/>\ndone<br \/>\nelse<br \/>\necho &#8220;openvpn: service not started&#8221;<br \/>\nexit 1<br \/>\nfi<br \/>\n;;<br \/>\nreopen)<br \/>\nif [ -f $lock ]; then<br \/>\nfor pidf in `\/bin\/ls $piddir\/*.pid 2&gt;\/dev\/null`; do<br \/>\nif [ -s $pidf ]; then<br \/>\nkill -USR1 `cat $pidf` &gt;\/dev\/null 2&gt;&amp;1<br \/>\nfi<br \/>\ndone<br \/>\nelse<br \/>\necho &#8220;openvpn: service not started&#8221;<br \/>\nexit 1<br \/>\nfi<br \/>\n;;<br \/>\ncondrestart)<br \/>\nif [ -f $lock ]; then<br \/>\n$0 stop<br \/>\n# avoid race<br \/>\nsleep 2<br \/>\n$0 start<br \/>\nfi<br \/>\n;;<br \/>\nstatus)<br \/>\nif [ -f $lock ]; then<br \/>\nfor pidf in `\/bin\/ls $piddir\/*.pid 2&gt;\/dev\/null`; do<br \/>\nif [ -s $pidf ]; then<br \/>\nkill -USR2 `cat $pidf` &gt;\/dev\/null 2&gt;&amp;1<br \/>\nfi<br \/>\ndone<br \/>\necho &#8220;Status written to \/var\/log\/messages&#8221;<br \/>\nelse<br \/>\necho &#8220;openvpn: service not started&#8221;<br \/>\nexit 1<br \/>\nfi<br \/>\n;;<br \/>\n*)<br \/>\necho &#8220;Usage: openvpn {start|stop|restart|condrestart|reload|reopen|status}&#8221;<br \/>\nexit 1<br \/>\n;;<br \/>\nesac<br \/>\nexit 0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is strictly geeky stuff so feel free to skip and check out the poetry and short stories instead (don&#8217;t leave until you do! Thanks!) A friend\/colleague contacted me a couple of days ago and asked if I know &hellip; <a href=\"https:\/\/www.itayemi.com\/blog\/2017\/02\/18\/setting-up-an-openvpn-access-server\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1137,1138,1141,1142,1135,1133,1139,1140,1134,1136],"class_list":["post-1776","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-diffie-hellman","tag-easyrsa","tag-github","tag-linux","tag-openvpn","tag-pki","tag-redhat","tag-rpmbuild","tag-securepoint","tag-vpn"],"_links":{"self":[{"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/posts\/1776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/comments?post=1776"}],"version-history":[{"count":6,"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/posts\/1776\/revisions"}],"predecessor-version":[{"id":1784,"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/posts\/1776\/revisions\/1784"}],"wp:attachment":[{"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/media?parent=1776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/categories?post=1776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itayemi.com\/blog\/wp-json\/wp\/v2\/tags?post=1776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}