359 lines
16 KiB
Raw Permalink Normal View History

2018-09-20 17:16:04 +02:00
# openvpn-install
2020-10-19 12:03:44 +02:00
2022-01-31 01:40:10 +01:00
[![Say Thanks!](!-1EAEDB.svg)](
2021-08-27 15:24:53 +02:00
OpenVPN installer for Debian, Ubuntu, Fedora, CentOS, Arch Linux, Oracle Linux, Rocky Linux and AlmaLinux.
This script will let you setup your own secure VPN server in just a few seconds.
You can also check out [wireguard-install](, a simple installer for a simpler, safer, faster and more modern VPN protocol.
2019-01-27 17:33:18 +01:00
## Usage
2020-04-27 15:42:47 +02:00
First, get the script and make it executable:
curl -O
chmod +x
2020-04-27 15:42:47 +02:00
Then run it:
2018-09-20 17:16:04 +02:00
You need to run the script as root and have the TUN module enabled.
The first time you run it, you'll have to follow the assistant and answer a few questions to setup your VPN server.
2020-04-27 15:42:47 +02:00
When OpenVPN is installed, you can run the script again, and you will get the choice to:
- Add a client
- Remove a client
- Uninstall OpenVPN
In your home directory, you will have `.ovpn` files. These are the client configuration files. Download them from your server and connect using your favorite OpenVPN client.
2020-04-04 11:55:08 +02:00
If you have any question, head to the [FAQ](#faq) first. Please read everything before opening an issue.
2020-04-03 11:13:57 +02:00
2020-05-15 22:06:18 +02:00
**PLEASE do not send me emails or private messages asking for help.** The only place to get help is the issues. Other people may be able to help and in the future, other users may also run into the same issue as you. My time is not available for free just for you, you're not special.
2018-09-17 01:23:39 +02:00
### Headless install
It's also possible to run the script headless, e.g. without waiting for user input, in an automated manner.
Example usage:
2020-04-27 15:31:36 +02:00
# or
A default set of variables will then be set, by passing the need for user input.
If you want to customise your installation, you can export them or specify them on the same line, as shown above.
- `DNS=1`
- `CLIENT=clientname`
- `PASS=1`
If the server is behind NAT, you can specify its endpoint with the `ENDPOINT` variable. If the endpoint is the public IP address which it is behind, you can use `ENDPOINT=$(curl -4` (the script will default to this). The endpoint can be an IPv4 or a domain.
2019-03-04 15:26:48 +01:00
Other variables can be set depending on your choice (encryption, compression). You can search for them in the `installQuestions()` function of the script.
2019-02-26 13:36:25 +01:00
Password-protected clients are not supported by the headless installation method since user input is expected by Easy-RSA.
The headless install is more-or-less idempotent, in that it has been made safe to run multiple times with the same parameters, e.g. by a state provisioner like Ansible/Terraform/Salt/Chef/Puppet. It will only install and regenerate the Easy-RSA PKI if it doesn't already exist, and it will only install OpenVPN and other upstream dependencies if OpenVPN isn't already installed. It will recreate all local config and re-generate the client file on each headless run.
### Headless User Addition
It's also possible to automate the addition of a new user. Here, the key is to provide the (string) value of the `MENU_OPTION` variable along with the remaining mandatory variables before invoking the script.
The following Bash script adds a new user `foo` to an existing OpenVPN configuration
2020-04-27 15:31:36 +02:00
export MENU_OPTION="1"
export CLIENT="foo"
export PASS="1"
2018-09-20 17:16:04 +02:00
## Features
2018-09-20 17:16:04 +02:00
- Installs and configures a ready-to-use OpenVPN server
- Iptables rules and forwarding managed in a seamless way
- If needed, the script can cleanly remove OpenVPN, including configuration and iptables rules
- Customisable encryption settings, enhanced default settings (see [Security and Encryption](#security-and-encryption) below)
- OpenVPN 2.4 features, mainly encryption improvements (see [Security and Encryption](#security-and-encryption) below)
2018-09-28 16:36:00 +02:00
- Variety of DNS resolvers to be pushed to the clients
- Choice to use a self-hosted resolver with Unbound (supports already existing Unbound installations)
2018-09-20 17:16:04 +02:00
- Choice between TCP and UDP
- NATed IPv6 support
- Compression disabled by default to prevent VORACLE. LZ4 (v1/v2) and LZ0 algorithms available otherwise.
2018-09-20 17:16:04 +02:00
- Unprivileged mode: run as `nobody`/`nogroup`
- Block DNS leaks on Windows 10
- Randomised server certificate name
2018-09-20 17:16:04 +02:00
- Choice to protect clients with a password (private key encryption)
- Many other little things!
## Compatibility
The script supports these Linux distributions:
| | Support |
| ------------------ | ------- |
2023-11-20 21:21:51 +01:00
| AlmaLinux 8 | ✅ |
| Amazon Linux 2 | ✅ |
| Arch Linux | ✅ |
| CentOS 7 | ✅ 🤖 |
| CentOS Stream >= 8 | ✅ 🤖 |
| Debian >= 10 | ✅ 🤖 |
| Fedora >= 35 | ✅ 🤖 |
| Oracle Linux 8 | ✅ |
| Rocky Linux 8 | ✅ |
| Ubuntu >= 18.04 | ✅ 🤖 |
2018-09-20 17:16:04 +02:00
To be noted:
- The script is regularly tested against the distributions marked with a 🤖 only.
2023-11-20 21:21:51 +01:00
- It's only tested on `amd64` architecture.
- It should work on older versions such as Debian 8+, Ubuntu 16.04+ and previous Fedora releases. But versions not in the table above are not officially supported.
- It should also support versions between the LTS versions, but these are not tested.
2018-09-20 17:16:04 +02:00
- The script requires `systemd`.
2018-09-20 17:16:04 +02:00
## Fork
This script is based on the great work of [Nyr and its contributors](
Since 2016, the two scripts have diverged and are not alike anymore, especially under the hood. The main goal of the script was enhanced security. But since then, the script has been completely rewritten and a lot a features have been added. The script is only compatible with recent distributions though, so if you need to use a very old server or client, I advise using Nyr's script.
2018-09-16 18:07:05 +02:00
## FAQ
More Q&A in [](
2018-09-20 17:16:04 +02:00
**Q:** Which provider do you recommend?
**A:** I recommend these:
2023-01-22 01:55:06 +01:00
- [Vultr]( Worldwide locations, IPv6 support, starting at \$5/month
- [Hetzner]( Germany, Finland and USA. IPv6, 20 TB of traffic, starting at 4.5€/month
- [Digital Ocean]( Worldwide locations, IPv6 support, starting at \$4/month
2018-09-20 17:16:04 +02:00
**Q:** Which OpenVPN client do you recommend?
**A:** If possible, an official OpenVPN 2.4 client.
- Windows: [The official OpenVPN community client](
- Linux: The `openvpn` package from your distribution. There is an [official APT repository]( for Debian/Ubuntu based distributions.
- macOS: [Tunnelblick](, [Viscosity](, [OpenVPN for Mac](
- Android: [OpenVPN for Android](
2018-09-24 00:03:07 +02:00
- iOS: [The official OpenVPN Connect client](
2018-09-26 20:55:27 +02:00
**Q:** Am I safe from the NSA by using your script?
**A:** Please review your threat models. Even if this script has security in mind and uses state-of-the-art encryption, you shouldn't be using a VPN if you want to hide from the NSA.
2018-09-28 16:36:00 +02:00
2018-09-26 20:55:27 +02:00
**Q:** Is there an OpenVPN documentation?
2018-09-18 14:26:00 +02:00
**A:** Yes, please head to the [OpenVPN Manual](, which references all the options.
More Q&A in [](
2020-04-27 15:31:36 +02:00
## One-stop solutions for public cloud
Solutions that provision a ready to use OpenVPN server based on this script in one go are available for:
2020-04-27 15:31:36 +02:00
- AWS using Terraform at [`openvpn-terraform-install`](
- Terraform AWS module [`openvpn-ephemeral`](
2020-05-10 22:27:57 +02:00
## Contributing
## Discuss changes
Please open an issue before submitting a PR if you want to discuss a change, especially if it's a big one.
2020-05-10 22:27:57 +02:00
### Code formatting
We use [shellcheck]( and [shfmt]( to enforce bash styling guidelines and good practices. They are executed for each commit / PR with GitHub Actions, so you can check the configuration [here](
## Security and Encryption
2023-01-21 23:40:01 +01:00
> **Warning**
> This has not been updated for OpenVPN 2.5 and later.
OpenVPN's default settings are pretty weak regarding encryption. This script aims to improve that.
OpenVPN 2.4 was a great update regarding encryption. It added support for ECDSA, ECDH, AES GCM, NCP and tls-crypt.
If you want more information about an option mentioned below, head to the [OpenVPN manual]( It is very complete.
Most of OpenVPN's encryption-related stuff is managed by [Easy-RSA]( Defaults parameters are in the [vars.example]( file.
2020-04-27 15:31:36 +02:00
### Compression
By default, OpenVPN doesn't enable compression. This script provides support for LZ0 and LZ4 (v1/v2) algorithms, the latter being more efficient.
2020-06-27 12:29:43 +02:00
However, it is discouraged to use compression since the [VORACLE attack]( makes use of it.
### TLS version
OpenVPN accepts TLS 1.0 by default, which is nearly [20 years old](
With `tls-version-min 1.2` we enforce TLS 1.2, which the best protocol available currently for OpenVPN.
TLS 1.2 is supported since OpenVPN 2.3.3.
### Certificate
OpenVPN uses an RSA certificate with a 2048 bits key by default.
OpenVPN 2.4 added support for ECDSA. Elliptic curve cryptography is faster, lighter and more secure.
This script provides:
- ECDSA: `prime256v1`/`secp384r1`/`secp521r1` curves
- RSA: `2048`/`3072`/`4096` bits keys
2018-09-23 17:06:15 +02:00
It defaults to ECDSA with `prime256v1`.
OpenVPN uses `SHA-256` as the signature hash by default, and so does the script. It provides no other choice as of now.
### Data channel
2018-09-28 16:36:00 +02:00
By default, OpenVPN uses `BF-CBC` as the data channel cipher. Blowfish is an old (1993) and weak algorithm. Even the official OpenVPN documentation admits it.
> The default is BF-CBC, an abbreviation for Blowfish in Cipher Block Chaining mode.
2020-10-21 13:59:49 +02:00
> Using BF-CBC is no longer recommended, because of its 64-bit block size. This small block size allows attacks based on collisions, as demonstrated by SWEET32. See <> for details.
> Security researchers at INRIA published an attack on 64-bit block ciphers, such as 3DES and Blowfish. They show that they are able to recover plaintext when the same data is sent often enough, and show how they can use cross-site scripting vulnerabilities to send data of interest often enough. This works over HTTPS, but also works for HTTP-over-OpenVPN. See <> for a much better and more elaborate explanation.
> OpenVPN's default cipher, BF-CBC, is affected by this attack.
2020-04-27 15:31:36 +02:00
Indeed, AES is today's standard. It's the fastest and more secure cipher available today. [SEED]( and [Camellia](<>) are not vulnerable to date but are slower than AES and relatively less trusted.
> Of the currently supported ciphers, OpenVPN currently recommends using AES-256-CBC or AES-128-CBC. OpenVPN 2.4 and newer will also support GCM. For 2.4+, we recommend using AES-256-GCM or AES-128-GCM.
2020-04-27 15:42:47 +02:00
AES-256 is 40% slower than AES-128, and there isn't any real reason to use a 256 bits key over a 128 bits key with AES. (Source: [1](,[2]( Moreover, AES-256 is more vulnerable to [Timing attacks](
AES-GCM is an [AEAD cipher]( which means it simultaneously provides confidentiality, integrity, and authenticity assurances on the data.
The script supports the following ciphers:
- `AES-128-GCM`
- `AES-192-GCM`
- `AES-256-GCM`
- `AES-128-CBC`
- `AES-192-CBC`
- `AES-256-CBC`
And defaults to `AES-128-GCM`.
2020-04-27 15:31:36 +02:00
OpenVPN 2.4 added a feature called "NCP": _Negotiable Crypto Parameters_. It means you can provide a cipher suite like with HTTPS. It is set to `AES-256-GCM:AES-128-GCM` by default and overrides the `--cipher` parameter when used with an OpenVPN 2.4 client. For the sake of simplicity, the script set both the `--cipher` and `--ncp-cipher` to the cipher chosen above.
### Control channel
OpenVPN 2.4 will negotiate the best cipher available by default (e.g ECDHE+AES-256-GCM)
The script proposes the following options, depending on the certificate:
- RSA:
It defaults to `TLS-ECDHE-*-WITH-AES-128-GCM-SHA256`.
### Diffie-Hellman key exchange
OpenVPN uses a 2048 bits DH key by default.
OpenVPN 2.4 added support for ECDH keys. Elliptic curve cryptography is faster, lighter and more secure.
Also, generating a classic DH keys can take a long, looong time. ECDH keys are ephemeral: they are generated on-the-fly.
The script provides the following options:
- ECDH: `prime256v1`/`secp384r1`/`secp521r1` curves
- DH: `2048`/`3072`/`4096` bits keys
2018-09-23 17:06:15 +02:00
It defaults to `prime256v1`.
### HMAC digest algorithm
From the OpenVPN wiki, about `--auth`:
> Authenticate data channel packets and (if enabled) tls-auth control channel packets with HMAC using message digest algorithm alg. (The default is SHA1 ). HMAC is a commonly used message authentication algorithm (MAC) that uses a data string, a secure hash algorithm, and a key, to produce a digital signature.
2019-06-30 23:06:33 +02:00
> If an AEAD cipher mode (e.g. GCM) is chosen, the specified --auth algorithm is ignored for the data channel, and the authentication method of the AEAD cipher is used instead. Note that alg still specifies the digest used for tls-auth.
The script provides the following choices:
- `SHA256`
- `SHA384`
- `SHA512`
It defaults to `SHA256`.
### `tls-auth` and `tls-crypt`
From the OpenVPN wiki, about `tls-auth`:
> Add an additional layer of HMAC authentication on top of the TLS control channel to mitigate DoS attacks and attacks on the TLS stack.
2019-06-30 23:06:33 +02:00
> In a nutshell, --tls-auth enables a kind of "HMAC firewall" on OpenVPN's TCP/UDP port, where TLS control channel packets bearing an incorrect HMAC signature can be dropped immediately without response.
About `tls-crypt`:
> Encrypt and authenticate all control channel packets with the key from keyfile. (See --tls-auth for more background.)
2019-06-30 23:06:33 +02:00
> Encrypting (and authenticating) control channel packets:
2020-04-27 15:31:36 +02:00
> - provides more privacy by hiding the certificate used for the TLS connection,
> - makes it harder to identify OpenVPN traffic as such,
> - provides "poor-man's" post-quantum security, against attackers who will never know the pre-shared key (i.e. no forward secrecy).
So both provide an additional layer of security and mitigate DoS attacks. They aren't used by default by OpenVPN.
`tls-crypt` is an OpenVPN 2.4 feature that provides encryption in addition to authentication (unlike `tls-auth`). It is more privacy-friendly.
The script supports both and uses `tls-crypt` by default.
## Say thanks
2022-01-31 01:36:59 +01:00
You can [say thanks]( if you want!
## Credits & Licence
2018-09-28 16:36:00 +02:00
Many thanks to the [contributors]( and Nyr's original work.
This project is under the [MIT Licence](
2023-01-22 16:42:48 +01:00
## Star History
[![Star History Chart](](