User Tools

Site Tools


networking:openvpn:openvpn-setup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
networking:openvpn:openvpn-setup [2026/11/28 09:18] – [3. Create Server Certificate & Key] oscarnetworking:openvpn:openvpn-setup [2026/11/28 10:08] (current) – [Deploy Certificates & Keys] oscar
Line 2: Line 2:
  
 ---- ----
 +===== Install Packages =====
 +Install easy-rsa package on your Debian system with the following command:
 +  # apt install easy-rsa
 +  # apt install openvpn
 +**Note:** Debian's easy-rsa package installs the script and support files under ///usr/share/easy-rsa/// rather than placing an easyrsa binary in /usr/bin or /usr/local/bin. Be aware that /usr/share/easy-rsa is not in your default PATH.
  
-===== 1. Install Easy-RSA =====+===== Setup Easy-RSA =====
 The first step in building an OpenVPN configuration is to establish a PKI (public key infrastructure). The PKI consists of: The first step in building an OpenVPN configuration is to establish a PKI (public key infrastructure). The PKI consists of:
  
   * a separate certificate (also known as a public key) and private key for the server and each client, and   * a separate certificate (also known as a public key) and private key for the server and each client, and
   * a master Certificate Authority (CA) certificate and key which is used to sign each of the server and client certificates.   * a master Certificate Authority (CA) certificate and key which is used to sign each of the server and client certificates.
- 
-Install easy-rsa package on your Debian system with the following command: 
-  # apt install easy-rsa 
-**Note:** Debian's easy-rsa package installs the script and support files under ///usr/share/easy-rsa/// rather than placing an easyrsa binary in /usr/bin or /usr/local/bin. Be aware that /usr/share/easy-rsa is not in your default PATH. 
  
 Create a directory where whole key structure will be stored: Create a directory where whole key structure will be stored:
Line 51: Line 52:
  
 </code>   </code>  
-===== 2. Create own CA certificate =====+===== Create own CA certificate =====
 Create CA certificate by running `easyrsa build-ca`. It asks to enter information that will be incorporated into your certificate request. Create CA certificate by running `easyrsa build-ca`. It asks to enter information that will be incorporated into your certificate request.
 <code> <code>
Line 69: Line 70:
  
 </code> </code>
-===== 3. Create Server Certificate & Key ===== +===== Create Server Certificate & Key ===== 
-Creating a server key and certificate is a 2-step easyrsa:+Creating a server key and certificate is done in 2-steps with `easyrsa`:
   - `gen-req` generates a private key and a sign request (CSR)   - `gen-req` generates a private key and a sign request (CSR)
   - `sign-req` uses the CA key and certificate to issue a signed public certificate   - `sign-req` uses the CA key and certificate to issue a signed public certificate
Line 107: Line 108:
   * Signs with the CA using your CA private key and CA certificate (//pki/ca.crt//), producing the signed server certificate at //pki/issued/myvpnserver.crt//. (Easy-RSA usually prompts you to confirm the request details and enter your CA passphrase, if one is set.)   * Signs with the CA using your CA private key and CA certificate (//pki/ca.crt//), producing the signed server certificate at //pki/issued/myvpnserver.crt//. (Easy-RSA usually prompts you to confirm the request details and enter your CA passphrase, if one is set.)
  
-===== 4. Generating Diffie-Hellman (DH) params =====+===== Generating Diffie-Hellman (DH) params =====
 The Diffie–Hellman (DH) Algorithm is a key-exchange protocol that enables two parties communicating over public channel to establish a mutual secret without it being transmitted over the Internet. DH enables the two to use a public key to encrypt and decrypt their conversation or data using symmetric cryptography. The Diffie–Hellman (DH) Algorithm is a key-exchange protocol that enables two parties communicating over public channel to establish a mutual secret without it being transmitted over the Internet. DH enables the two to use a public key to encrypt and decrypt their conversation or data using symmetric cryptography.
 After initializing a PKI, any entity can create DH params that needs them.  After initializing a PKI, any entity can create DH params that needs them. 
 DH key params can be generated with: DH key params can be generated with:
-  $ ./easyrsa gen-dh+<code> 
 +$ ./easyrsa gen-dh 
 +------------------ 
 + 
 +Notice 
 +------ 
 +DH parameters of size 2048 created at: 
 + /tmp/certs/pki/dh.pem 
 +</code>
 This may take a few minutes to complete.  This may take a few minutes to complete. 
  
-===== 5. TLS-AUTH =====+===== TLS-AUTH =====
 The tls-auth directive adds an additional HMAC signature to all SSL/TLS handshake packets for integrity verification. Any UDP packet not bearing the correct HMAC signature can be dropped without further processing. The tls-auth HMAC signature provides an additional level of security above and beyond that provided by SSL/TLS. It can protect against:DoS attacks, port flooding, Port scanning, Buffer overflow vulnerabilities, etc. The tls-auth directive adds an additional HMAC signature to all SSL/TLS handshake packets for integrity verification. Any UDP packet not bearing the correct HMAC signature can be dropped without further processing. The tls-auth HMAC signature provides an additional level of security above and beyond that provided by SSL/TLS. It can protect against:DoS attacks, port flooding, Port scanning, Buffer overflow vulnerabilities, etc.
  
 Using tls-auth requires that you generate a shared-secret key that is used in addition to the standard RSA certificate/key. Generate an HMAC signature to strengthen the server’s TLS integrity verification capabilities: Using tls-auth requires that you generate a shared-secret key that is used in addition to the standard RSA certificate/key. Generate an HMAC signature to strengthen the server’s TLS integrity verification capabilities:
      
-  $ openvpn --genkey secret pki/ta.key+  $ /usr/sbin/openvpn --genkey secret pki/ta.key
  
 This command will generate an OpenVPN static key and write it to the file ta.key. This key should be copied over a pre-existing secure channel to the server and all client machines. It can be placed in the same directory as the RSA .key and .crt files. This command will generate an OpenVPN static key and write it to the file ta.key. This key should be copied over a pre-existing secure channel to the server and all client machines. It can be placed in the same directory as the RSA .key and .crt files.
Line 129: Line 138:
   tls-auth ta.key 1   tls-auth ta.key 1
  
-===== 6. Create Client Certificate and Key Pair =====+===== Create Client Certificate and Key Pair ===== 
 +Creating a Client key and certificate is done in 2-steps with `easyrsa`: 
 +  - `gen-req` generates a private key and a sign request (CSR) 
 +  - `sign-req` uses the CA key and certificate to issue a signed public certificate
  
-n this step, you will first generate the client key and certificate pair. If you have more than one client, you can repeat this process for each one. Please note, though, that you will need to pass a unique name value to the script for every client. Throughout this tutorial, the first certificate/key pair is referred to as MyVPNClient.+=== Generate client private key === 
 +In this step, you will first generate the client key and certificate pair. If you have more than one client, you can repeat this process for each one. Please note, though, that you will need to pass a unique name value to the script for every client. Throughout this tutorial, the first certificate/key pair is referred to as `myvpnclient`. 
 +<code> 
 +$ /usr/share/easy-rsa/easyrsa gen-req myvpnclient nopass 
 +--------------------------------------------------------
  
-  $ easyrsa gen-req MyClientName nopass+Notice 
 +------ 
 +Private-Key and Public-Certificate-Request files created. 
 +Your files are: 
 +* req: /tmp/certs/pki/reqs/myvpnclient.req 
 +* key: /tmp/certs/pki/private/myvpnclient.key 
 +</code> 
 +This will: 
 +  * Generate a private key (//pki/private/myvpnclient.key//) for the entity named //myvpnclient//. 
 +  * Creates a certificate signing request (//pki/reqs/myvpnclient.req//) containing the corresponding public key and requested identity fields (such as Common Name). 
 +  * nopass skips key encryption: Leaves the private key unencrypted on disk so automated services (like a VPN server daemon) can start unattended without prompting for a passphrase. Omit nopass if you want a passphrase-protected key (common for client keys or sensitive CA keys).
  
-This will create a private key for the client and a certificate request file called MyClientName.req. Then sign the request by running easyrsa with the sign-req option, followed by the request type and the common name. The request type can either be client or server, so for the OpenVPN server’s certificate request, be sure to use the server request type. +=== Sign client key === 
- +This will create a private key for the client and a certificate request file called myvpnclient.req. Then sign the request by running easyrsa with the sign-req option, followed by the request type and the common name. The request type can either be client or server, so for the OpenVPN client certificate request, be sure to use the client request type. 
-  $ easyrsa sign-req server MyClientName+<code> 
 +$ /usr/share/easy-rsa/easyrsa sign-req client myvpnclient 
 +---------------------------------------------------------
  
 +Notice
 +------
 +Certificate created at:
 +* /tmp/certs/pki/issued/myvpnclient.crt
 +</code>
 In the output, you’ll be asked to verify that the request comes from a trusted source. Type yes and press ENTER to confirm this.  In the output, you’ll be asked to verify that the request comes from a trusted source. Type yes and press ENTER to confirm this. 
 +This will:
 +  * Reads the request from //pki/reqs/myvpnclient.req//.
 +  * Applies the client profile/extension set, marking the resulting certificate for client authentication (and typically setting EKU attributes appropriate for a TLS/VPN server rather than a client).
 +  * Signs with the CA using your CA private key and CA certificate (//pki/ca.crt//), producing the signed server certificate at //pki/issued/myvpnclient.crt//. (Easy-RSA usually prompts you to confirm the request details and enter your CA passphrase, if one is set.)
 +
      
-   +===== Deploy Certificates & Keys =====
-===== 7. Deploy Certificates & Keys =====+
 With that, all the certificate and key files needed by your server have been generated. You’re ready to deploy the corresponding certificates and keys to both OpenVPN Server and Client systems. With that, all the certificate and key files needed by your server have been generated. You’re ready to deploy the corresponding certificates and keys to both OpenVPN Server and Client systems.
  
Line 150: Line 187:
 |ca.key |key signing machine only |Root CA key |YES| |ca.key |key signing machine only |Root CA key |YES|
 |dh2048.pem |server only |Diffie Hellman parameters |NO| |dh2048.pem |server only |Diffie Hellman parameters |NO|
-|MyServerName.crt |server only |Server Certificate |NO| +|myvpnserver.crt |server only |Server Certificate |NO| 
-|MyServerName.key |server only |Server Key |YES| +|myvpnserver.key |server only |Server Key |YES| 
-|MyClientName.crt |client1 only |Client1 Certificate |NO| +|myvpnclient.crt |client1 only |Client1 Certificate |NO| 
-|MyClientName.key |client1 only |Client1 Key |YES|+|myvpnclient.key |client1 only |Client1 Key |YES|
  
 === Server Deployment === === Server Deployment ===
Line 169: Line 206:
  
   - **ca.cert** --> insert contents --> between the <ca></ca>. Including the "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" lines.   - **ca.cert** --> insert contents --> between the <ca></ca>. Including the "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" lines.
-  - **MyClientName.key** --> insert contents --> between the <key></key>. Including the "-----BEGIN PRIVATE KEY-----" and "-----END PRIVATE KEY-----" lines. +  - **myvpnclient.key** --> insert contents --> between the <key></key>. Including the "-----BEGIN PRIVATE KEY-----" and "-----END PRIVATE KEY-----" lines. 
-  - **MyClientName.crt** --> insert contents --> between the <cert></cert>. Including everything.+  - **myvpnclient.crt** --> insert contents --> between the <cert></cert>. Including everything.
   - **ta.key** --> insert contents --> between the <tls-auth></tls-auth>. Including everything.   - **ta.key** --> insert contents --> between the <tls-auth></tls-auth>. Including everything.
  
networking/openvpn/openvpn-setup.1795857512.txt.gz · Last modified: by oscar