This guide will teach you how to install WireGuard VPN on your VPS server using a simplified installation script. WireGuard is a modern, fast, and secure VPN that will allow you to create your own private virtual network.
📋 Prerequisites
- A VPS server with root or sudo access
- An active SSH connection
- Ubuntu/Debian (the script works with these distributions)
- UFW installed and configured (see the tutorial Install UFW)
📥 WireGuard Installation
Download the installation script
We will use the automatic installation script that greatly simplifies the configuration:
Bash# Download the installation script curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh # Make the script executable chmod +x wireguard-install.sh
Run the installation script
Bashsudo ./wireguard-install.sh
Interactive configuration
The script will ask you a few questions. Here are the recommended answers:
- Public address: IPv4 or IPv6 address detected automatically; press
Enterto keep it - Public interface: detected from the default route (often
eth0); pressEnterto keep it - WireGuard interface name:
wg0(default) - Server WireGuard IPv4:
10.66.66.1(default), i.e. the10.66.66.0/24subnet - Server WireGuard IPv6:
fd42:42:42::1(default) - Server WireGuard port: a random port between 49152 and 65535 is proposed; keep it or enter your own (1-65535), and note it down: you will need it for the firewall
- DNS resolvers:
1.1.1.1then1.0.0.1(Cloudflare, default) - Allowed IPs:
0.0.0.0/0,::/0(default): all of the client's traffic goes through the VPN - Client name: name of your first client: letters, digits,
_or-, 15 characters maximum (e.g.,my-pc,laptop,smartphone) - Client WireGuard IPv4 and IPv6: proposed automatically (
10.66.66.2andfd42:42:42::2for the first client); pressEnter
The script will:
- Install WireGuard automatically
- Generate private and public keys
- Configure the server
- Create your first client
📱 Client Configuration
Retrieve the configuration file
After installation, the script generates a client configuration file. To retrieve it:
Bash# Display the configuration file content sudo cat ~/wg0-client-[client-name].conf # Example: if you named your client "my-pc" sudo cat ~/wg0-client-my-pc.conf # Or download it to your own computer (run this on your computer) scp user@your-vps-ip:wg0-client-my-pc.conf .
The file is named wg0-client-<name>.conf (WireGuard interface name, then client name) and is written in the home directory of the user who ran the script: /home/<user> if you used sudo from a regular account, /root if you are root. The script prints its exact path at the end, and also displays the configuration as a QR code in the terminal (if qrencode is installed), ready to scan from the mobile app.
Configuration file example
The file will look like this:
[Interface]
PrivateKey = [your-private-key]
Address = 10.66.66.2/32,fd42:42:42::2/128
DNS = 1.1.1.1,1.0.0.1
[Peer]
PublicKey = [server-public-key]
PresharedKey = [preshared-key]
Endpoint = [your-vps-ip]:<PORT>
AllowedIPs = 0.0.0.0/0,::/0
Install the client on your device
On Windows
- Download WireGuard from wireguard.com
- Install the application
- Open WireGuard and click "Add Tunnel" > "Add empty tunnel"
- Copy-paste the content of the
.conffile - Save and activate the connection
On macOS
- Download WireGuard from the App Store or wireguard.com
- Install the application
- Open WireGuard and click "Add Tunnel" > "Create from file" or "Create from clipboard"
- Import your configuration file
- Activate the connection
On Linux (Ubuntu/Debian)
Bash# Install WireGuard sudo apt update sudo apt install wireguard -y # Copy the configuration file sudo cp wg0-client-my-pc.conf /etc/wireguard/wg0.conf # Enable WireGuard sudo wg-quick up wg0 # Enable on boot sudo systemctl enable wg-quick@wg0
On Android/iOS
- Install the WireGuard app from Google Play Store or App Store
- Open the app and click the "+" button
- Choose "Create from file" or "Create from QR code"
- Import your configuration file
- Activate the connection
🔐 Add a new client
To add a new client later (e.g., for another device):
Bashsudo ./wireguard-install.sh
When the script asks what you want to do, choose option 1) Add a new user.
Enter a name for the new client, and the script will automatically generate a new configuration file named wg0-client-<name>.conf in the same home directory (e.g., ~/wg0-client-laptop.conf)
The same menu also offers 2) List all users, 3) Revoke existing user and 4) Uninstall WireGuard (which removes the whole /etc/wireguard directory).
🚀 Useful WireGuard commands
Service management
Bash# Start WireGuard sudo systemctl start wg-quick@wg0 # Stop WireGuard sudo systemctl stop wg-quick@wg0 # Restart WireGuard sudo systemctl restart wg-quick@wg0 # Service status sudo systemctl status wg-quick@wg0 # Enable on boot sudo systemctl enable wg-quick@wg0 # Disable on boot sudo systemctl disable wg-quick@wg0
Connection information
Bash# View WireGuard information sudo wg show # View transfer statistics sudo wg show wg0 transfer # View current configuration sudo wg show wg0 dump
Logs
Bash# View logs in real-time sudo journalctl -u wg-quick@wg0 -f # View last entries sudo journalctl -u wg-quick@wg0 -n 50
🔐 Allow WireGuard in UFW
Important: Don't forget to allow the WireGuard port in UFW after installation, otherwise your VPN won't work.
After installing WireGuard, allow the port in UFW:
Bash# Read the port chosen during the installation (random by default) sudo wg show wg0 listen-port # or: sudo grep ListenPort /etc/wireguard/wg0.conf # Allow the WireGuard port (replace <PORT> with the value found above) sudo ufw allow <PORT>/udp # Reload UFW sudo ufw reload # Verify that the rule is active sudo ufw status | grep <PORT>
✅ Verification
Verify that WireGuard is working
Bash# Check service status sudo systemctl status wg-quick@wg0 # Check active connections sudo wg show # Verify that the port is open sudo ss -ulnp | grep <PORT>
Test from your client
Once connected from your client:
- Check your public IP:
curl ifconfig.me(should display your VPS IP) - Test connectivity:
ping 8.8.8.8 - Verify that you are connected to the VPN from your network interface
🆘 Troubleshooting
WireGuard won't start
Bash# Check logs sudo journalctl -u wg-quick@wg0 -n 50 # Check configuration sudo wg-quick down wg0 sudo wg-quick up wg0 # Verify that the port is available sudo ss -ulnp | grep <PORT>
Cannot connect from my client
-
Check that the port is open in UFW:
Bashsudo ufw status | grep <PORT> -
Check that the server is listening on the port:
Bashsudo ss -ulnp | grep <PORT> -
Check your client configuration: Make sure your server IP in
Endpointis correct -
Check server-side logs:
Bashsudo journalctl -u wg-quick@wg0 -f
Installation script fails
If the installation script encounters errors:
- Verify that you have root or sudo rights
- Check your internet connection
- Make sure your system is up to date:
sudo apt update && sudo apt upgrade -y - Try downloading the script again:
Bash
rm wireguard-install.sh curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh chmod +x wireguard-install.sh
📚 Additional resources
❓ Frequently Asked Questions
Q: Can I use multiple clients simultaneously?
A: Yes, WireGuard supports multiple clients connected at the same time. Simply add a new client with the script.
Q: What is WireGuard's speed?
A: WireGuard is one of the fastest VPNs available, with performance close to native speed.
Q: Is WireGuard secure?
A: Yes, WireGuard uses modern encryption and has been audited for security.
Q: Can I change the WireGuard port after installation?
A: Yes, but you'll need to modify the configuration manually. It's simpler to reinstall with the script if necessary.
Good configuration! 🚀