This guide provides a simple method to install OpenVPN on Ubuntu using an automated script. The script handles most of the configuration for you.
Step 1: Update Your System
Ensure your system packages are up-to-date.
sudo apt update && sudo apt upgrade -y
Step 2: Download the OpenVPN Installation Script
We'll use a trusted script that automates the OpenVPN installation process.
wget https://git.io/vpn -O openvpn-install.sh
This script is maintained by Nyr on GitHub.
Step 3: Make the Script Executable
chmod +x openvpn-install.sh
Step 4: Run the Installation Script
sudo ./openvpn-install.sh
Step 5: Follow the Prompts
The script will ask you a few simple questions:
- IP Address Detection:
- It will automatically detect your server's public IP address. Press
Enter
to accept or enter a different IP if needed.
- It will automatically detect your server's public IP address. Press
- Protocol Selection:
- Choose the protocol (UDP or TCP). UDP is recommended. Type
1
for UDP and pressEnter
.
- Choose the protocol (UDP or TCP). UDP is recommended. Type
- Port Number:
- Enter the port number for OpenVPN. The default is
1194
. PressEnter
to accept the default.
- Enter the port number for OpenVPN. The default is
- DNS Provider:
- Select a DNS provider for the VPN clients. You can choose from a list (e.g., Google, Cloudflare). Enter the corresponding number and press
Enter
.
- Select a DNS provider for the VPN clients. You can choose from a list (e.g., Google, Cloudflare). Enter the corresponding number and press
- Client Name:
- Enter a name for the first VPN client (e.g.,
client1
). This will generate a configuration file for this client.
- Enter a name for the first VPN client (e.g.,
- Confirm Installation:
- Press any key to start the installation.
Step 6: Installation Complete
Once the script finishes:
- The OpenVPN server is set up and running.
- A client configuration file (e.g.,
client1.ovpn
) is generated in your home directory.
Step 7: Transfer the Client Configuration File
Transfer the .ovpn
file to the device you want to use as a VPN client. You can use secure methods like scp
, sftp
, or a USB drive.
Example using scp:
scp ~/client1.ovpn your_username@client_ip:/path/to/destination
Step 8: Connect to the VPN from the Client
- Install OpenVPN Client:
- For Windows: Download and install the OpenVPN client.
- For macOS: Use Tunnelblick or the official OpenVPN Connect client.
- For Linux: Install OpenVPN using your package manager.
sudo apt install openvpn -y
- Import the Configuration File:
- Open the OpenVPN client application.
- Import the
client1.ovpn
file.
- Connect to the VPN:
- Use the client application to connect using the imported profile.
Managing OpenVPN After Installation
You can manage OpenVPN by re-running the installation script:
sudo ./openvpn-install.sh
Options include:
- Add a new client: Generate additional client configuration files.
- Revoke existing clients: Remove client access.
- Uninstall OpenVPN: Completely remove OpenVPN from your server.
Security Considerations
- Review the Script: It's good practice to review any script before running it. Open the script with a text editor to inspect it.
nano openvpn-install.sh
- Keep Your System Updated: Regularly update your server to patch security vulnerabilities.
sudo apt update && sudo apt upgrade -y
- Firewall Configuration: Ensure that the OpenVPN port (
1194
by default) is open in your firewall settings.
sudo ufw allow 1194/udp
Additional Resources
- OpenVPN Installation Script Repository: https://github.com/Nyr/openvpn-install
- OpenVPN Community Documentation: https://community.openvpn.net/openvpn/wiki
This method provides a quick and easy way to set up OpenVPN on your Ubuntu server with minimal configuration. If you need further assistance, feel free to consult the additional resources or reach out to the community.