Bastion Host Setup

This documentation describes how to fully configure a WireGuard VPN Bastion Host on Ubuntu and allow macOS or Windows clients to connect using their own keys and access the bastion server over SSH only. The VPN is configured to allow only SSH access to the bastion host (192.168.1.100) via the tunnel. All other traffic (e.g. web browsing or general internet access) uses the client's normal internet connection.

Server Setup

Requirements

The bastion host has very low hardware requirements:

  • One virtual CPU (vCPU) setup or better

  • 2GB of RAM or more

  • 10GB disk or more

  • A static IP address

  • Ubuntu 24.04 or higher

  • Access to a user with sudo access to run the setup and configuration.

Install WireGuard

First, install WireGuard on the Bastion Host server:

sudo apt update
sudo apt install wireguard -y

Generate Server Keys

WireGuard uses Curve25519 public-key cryptography for authentication. The server needs a private key (kept secret) and a public key (shared with clients).

triangle-exclamation

Configure environment variables for these keys. We'll use these later:

Find your main network interface

Common interfaces: eth0, ens3, enp0s3, etc. Note this for later use.

Configure WireGuard

Create the WireGuard config file and make the necessary configurations

Add this config to the newly created config file:

circle-info

Where to get the workstation WireGuard's public key?

Each peer block in the configuration, is the "allow list" for who can connect through the WireGuard tunnel. Each workstation must be configured here, and must also provide its WireGuard Public Key (which is different from the workstation SSH key).

Go to Generate Workstation Keys to see how to generate this key.

Enable Forwarding (Required for Routing)

Forwarding must be enabled for the bastion to allow SSH forwarding.

To verify forwarding status at any time:

Expected output:

Configure Firewall (UFW)

Allow WireGuard port:

Reload UFW

Start WireGuard

Client Workstation Setup

For clients (or users) connect to the bastion host, they must also have a proper setup, as follows.

Workstation Install

Download and install WireGuard from the official website:

Visit https://www.wireguard.com/install/arrow-up-right and download the appropriate version for your platform:

  • Windows: Download the Windows installer

  • macOS: Download from App Store

  • Linux: Use your distribution's package manager

Generate Workstation Keys

For Windows:

For macOS:

For Linux/Ubuntu:

Share the public key content with the system administrator

macOS/Linux:

Windows:

Workstation Configuration

In the workstation, the configuration needs to specify which targeted traffic to route through WireGuard, as we don't want all the traffic, but only those targeting the destination servers protected by the Bastion Host.

First, create a new file named bastion-tunnel.conf

... paste with the following content:

Activate Tunnel on Workstation

Once you have installed the WireGuard client and created the configuration file, you need to import this configuration into the WireGuard app.

For macOS:

  1. Open WireGuard application

  2. Click Import tunnel from file

  3. Select your configuration file

  4. Click Activate

For Windows:

  1. Open WireGuard application

  2. Click Import tunnel(s) from file

  3. Select your configuration file

  4. Click Activate

Protecting Target Servers

To restrict SSH access to only the bastion host, configure the firewall on your target servers:

Troubleshooting

Server-side checks:

Last updated

Was this helpful?