Server security guide · Romania

How do I set up a WireGuard VPN for server admin access?

SSH, database panels, Grafana and every other admin interface do not belong on the public internet, even behind a password and 2FA. A WireGuard VPN moves them onto a private network that only people with a key can reach, and to the internet the server looks closed.

Updated:

Short answer

  1. Generate one key pair for the server and one per person, and declare each person as a peer with AllowedIPs limited to a single /32 address.
  2. Open only the WireGuard UDP port to the internet, and let SSH and admin panels accept connections on the wg0 interface alone.
  3. Give clients PersistentKeepalive when they sit behind NAT, and list only the internal networks in their AllowedIPs, not all traffic.
  4. When someone leaves, delete their peer from the configuration the same day: there is no password to change, only a key to revoke.
What stays on the internet
one UDP port, for example 51820
One peer = one person
AllowedIPs = 10.8.0.x/32, no shared keys
SSH after setup
accepted only on the wg0 interface
Revocation
delete the [Peer] block and run wg syncconf

Why administration belongs behind a VPN

Every service exposed to the internet is a service that may have a vulnerability tomorrow: a database admin panel, a Grafana interface, a Docker API. Even key-only SSH stays exposed to a bug in sshd. With WireGuard, the only thing visible from outside is a UDP port that does not answer packets without a valid key. All administrative services listen on the private address inside the tunnel.

A configuration that holds up: one key per person, strict AllowedIPs

WireGuard has no accounts or passwords; identity is the public key. So each person gets their own key pair, generated on their own laptop, and their own address inside the tunnel network. On the server, AllowedIPs for each peer is that one /32 address and nothing else, so a peer cannot claim someone else's address. On the client, AllowedIPs lists only the internal networks, and PersistentKeepalive = 25 keeps the tunnel open through NAT. Keep the server configuration in Git so a revocation is a commit.

  • The server's private key never leaves the server; each colleague's never leaves their laptop
  • A separate peer for CI or the monitoring server, each with its own address
  • Keep an out-of-band way in, such as a provider console where your plan offers one, as the fallback if the tunnel fails

What Romanian law expects

GDPR Article 32 requires access control on systems that process personal data, and after an incident ANSPDCP asks who could reach the server and how. For entities under OUG 155/2024, the NIS2 transposition approved by Law 124/2025, Article 13 explicitly calls for access-control policies (point f) and multi-factor authentication (point j), and withdrawing rights when an employee leaves is part of access management. The ordinance does not require a VPN as such, but one key per person is a common way to show both: the server's configuration file is the list of who has access.

WireGuard and OpenVPN for administrative access
CriterionWireGuardOpenVPN
Protocol and transportUDP, fixed modern cryptography (Noise, ChaCha20)UDP or TCP, TLS with configurable cipher suites
Size and auditSmall codebase, in the Linux kernel since 5.6Large codebase, runs in user space
IdentityStatic public keys, one peer per personX.509 certificates, your own PKI
RevocationDelete the peer from the configurationCRL or certificate reissue
Visibility from the internetDoes not answer without a valid keyA port that answers the handshake
When to choose itAdministrative access, simple site-to-site linksTCP/443 through restrictive firewalls, an existing PKI

Commands and configuration

Generate keys (on each machine, for itself)
sudo apt install -y wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
/etc/wireguard/wg0.conf on the server, one [Peer] per person
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>

[Peer]
# ana, work laptop
PublicKey = <Ana's public key>
AllowedIPs = 10.8.0.2/32

[Peer]
# monitoring server
PublicKey = <the monitoring machine's public key>
AllowedIPs = 10.8.0.10/32
Firewall: only UDP 51820 to the internet, SSH only through the tunnel; start and revoke
sudo ufw allow 51820/udp
sudo ufw allow in on wg0 to any port 22 proto tcp
sudo ufw delete allow 22/tcp   # only after you have tested the tunnel from a second session
sudo systemctl enable --now wg-quick@wg0

# revoke: delete the [Peer] block from wg0.conf, then
sudo wg syncconf wg0 <(sudo wg-quick strip wg0)

Practical examples

IT outsourcing company in Cluj-Napoca with contractors

Six contractors held SSH keys on customer servers and nobody kept the list. The company put WireGuard on a small access VPS, moved SSH on every server to the tunnel network and issued each contractor one peer. Offboarding a contractor now means deleting a four-line block.

Private clinic in Bucharest with an internally managed booking panel

The database admin interface was on the internet behind a password. After a scanner found it, it was bound to the WireGuard tunnel address. Staff now reach it over the VPN, and the port is no longer visible from outside.

Common mistakes

  • Using a single WireGuard key for the whole team, so you cannot revoke one person without locking everyone out.
  • Setting AllowedIPs = 0.0.0.0/0 on the server for a peer, which lets it claim any address inside the tunnel.
  • Moving SSH to wg0 before testing the tunnel, and losing your own access.
  • Distributing the client configuration, private key included, by email or in chat.

How 4hosting helps

  • The VPN & WireGuard service sets up the server, the per-person keys and the move of SSH and admin panels onto the private network. It runs on your included hours: 1–8 h a month on VPS, 5–10 h on dedicated servers (depending on plan), 10 h on GPU servers.
  • You request those hours from the DevOps Services section of the client panel; they are not carried over, and extra hours are accepted and billed separately.
  • mTLS & Zero Trust is the next step once internal services must authenticate each other, not just people connecting.
  • Firewall & Network Isolation applies the default-deny rules that leave only the WireGuard port and your public web ports open.

Related questions

  • What if the tunnel fails and SSH only listens on wg0?

    You use an out-of-band route that does not depend on the network, such as a provider console if your plan has one, and repair the configuration. That is why you first test with SSH still open to the internet, from a second session, and close the public port only afterwards. Keep a copy of the WireGuard configuration off the server.

  • Is WireGuard safe without a second factor?

    The WireGuard key on the laptop plus the SSH key are already two things an attacker needs. The remaining risk is a stolen laptop that is unlocked; you reduce it with disk encryption and a passphrase on the SSH key. Larger teams can add a layer on top of WireGuard for central identity and 2FA.

  • Can I run WireGuard on the same server I am protecting?

    Yes, for one or two servers it is the simplest option. Once you have more machines, put WireGuard on a small access VPS and let every other server accept SSH only from that tunnel's network. That gives you a single place to manage peers.

Request a security review

A production server starts getting attacked within minutes of receiving a public IP address, however small the project is. This guide ranks the controls by impact, from SSH access to incident response, with the Romanian rules that apply along the way. Every topic has its own page with a short answer, examples and ready-to-use configuration.