Back to articles
AI & Cloud

Deploy DefGuard on Cloud Server: Comprehensive WireGuard VPN Solution with 2FA and YubiKey

Detailed guide to deploying DefGuard on a cloud server with WireGuard VPN, integrated two-factor authentication (2FA), and YubiKey for comprehensive enterprise security.

DPTCloud Engineering4 min read
Deploy DefGuard on Cloud Server: Comprehensive WireGuard VPN Solution with 2FA and YubiKey

Image credit: Danny144 · Pixabay Content License

Deploy DefGuard on Cloud Server: Comprehensive WireGuard VPN Solution with 2FA and YubiKey

DefGuard is a powerful network security solution designed to protect enterprises from external threats. Combined with WireGuard VPN, two-factor authentication (2FA), and YubiKey, DefGuard provides a comprehensive, self-hosted, and efficient security system. This guide details how to deploy DefGuard on a cloud server using WireGuard VPN with integrated 2FA and YubiKey, ideal for businesses seeking full control over their security infrastructure.

Prerequisites Before Deployment

Before deployment, ensure the following conditions are met:

  • Cloud Server: Use High-RAM Cloud VPS or Dedicated Server to ensure processing performance and scalability.
  • Operating System: Linux (Ubuntu 22.04 LTS or Debian 11 is recommended).
  • Software: WireGuard, DefGuard, YubiKey PAM module, Google Authenticator or TOTP app (for 2FA).
  • Hardware: YubiKey (USB or NFC) to enhance authentication security.

Deploy WireGuard VPN Solution

WireGuard is a modern, lightweight, and secure VPN protocol suitable for deployment on cloud servers. Below are the basic steps to set it up:

# Update the system
sudo apt update && sudo apt upgrade -y

# Install WireGuard
sudo apt install wireguard -y

# Generate public/private keys
wg genkey | sudo tee /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key

Run the following command to configure WireGuard:

sudo nano /etc/wireguard/wg0.conf

Sample configuration file content:

[Interface]
PrivateKey = 
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
PublicKey = 
AllowedIPs = 10.0.0.2/32

Integrate Two-Factor Authentication and YubiKey

To enhance security, integrating two-factor authentication (2FA) and YubiKey is essential. Below are the steps to configure it:

  1. Run the command to install the YubiKey PAM module:
sudo apt install libpam-yubico -y

Modify the PAM configuration file:

sudo nano /etc/pam.d/sshd

Add the following line at the end of the file:

auth required pam_yubico.so id=123456 debug

Replace 123456 with your YubiKey ID. This configuration requires users to authenticate with YubiKey when logging in via SSH.

Authentication and Verification

After deployment, perform the following checks:

  • Run wg show to verify the WireGuard status.
  • Test VPN connection from a client machine using the server's IP address.
  • Attempt SSH login with YubiKey to ensure 2FA is working.

Comprehensive Solution for Enterprises

Deploying DefGuard with WireGuard, 2FA, and YubiKey enables enterprises to have a comprehensive, self-hosted, and effective security solution. By not relying on third-party services, businesses can fully control their security infrastructure, reducing risks and increasing trust.

Troubleshooting

If issues arise, check the following:

  • Ensure port 51820 is open on the firewall.
  • Verify that all software packages are correctly installed.
  • Check logs using journalctl -u wg-quick@wg0.

References

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478