This guide covers keeping a CloudSOE Bastion Host patched on both AWS and Azure. On a bastion, “the software” is the operating system: OpenSSH, fail2ban, AIDE, the Active Directory toolchain and ntpd-rs are all Ubuntu packages, so patching is mostly apt. The image runs on Ubuntu 26.04 LTS and doesn’t include PHP, so PHP2Shell doesn’t apply. The php-url-fopen and phpmyadmin-syslog entries in /etc/fail2ban/jail.local are standard fail2ban jail definitions, and they’re switched off.

What you can upgrade in place

ComponentIn place?How
Operating system and OpenSSH (Ubuntu 26.04 LTS)Yesapt (see Update the operating system). A reboot drops every session.
fail2banYesapt; your /etc/fail2ban/jail.local is kept
AIDEYesapt, then re-baseline the database after patching
sssd, realmd, adcli, Kerberos, SambaYesapt; if you’ve joined a domain, check logins still work afterwards
ntpd-rsYesapt

Because a bastion holds very little data, moving to a fresh image is also cheap, and it’s the right way to get a newer Ubuntu release. What you carry over is users, keys and configuration (see Move to a fresh CloudSOE image).

Before you start: back up

Cloud disk snapshot

  • AWS: EC2 → Volumes → select the instance’s root volume → Actions → Create snapshot.
  • Azure: your VM → Disks → select the OS disk → Create snapshot.

Users, keys and configuration

Collect what makes your bastion yours: SSH settings, sudo rules, fail2ban tuning and every user’s authorized_keys.

sudo tar czf /home/$(whoami)/bastion-config-$(date +%F).tar.gz \
  /etc/ssh/sshd_config.d /etc/sudoers.d \
  /etc/fail2ban/jail.local /etc/fail2ban/jail.d \
  /home/*/.ssh/authorized_keys
sudo chown $(whoami): /home/$(whoami)/bastion-config-*.tar.gz
chmod 600 /home/$(whoami)/bastion-config-*.tar.gz

# Record the local user accounts you've created (normal users only)
getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1, $6, $7}' > /home/$(whoami)/bastion-users.txt

If you’ve changed /etc/ssh/sshd_config itself rather than using a drop-in, add it to the list. The same goes for any other files you’ve edited, such as /etc/sssd/sssd.conf (kept for reference only, see below). Copy the backup off the instance.

Update the operating system

Everything on the bastion comes from Ubuntu’s repositories:

sudo apt update
apt list --upgradable
sudo apt upgrade

Restarting SSH doesn’t kick anyone out. If an OpenSSH update restarts the SSH service, established sessions and ProxyJump tunnels stay up. Only new connections use the updated daemon.

Rebooting does. If an update needs a reboot, Ubuntu creates /var/run/reboot-required. A reboot drops every session and tunnel through the bastion, including colleagues’ work on private servers. Check who’s connected and give them notice:

[ -f /var/run/reboot-required ] && cat /var/run/reboot-required.pkgs
who
sudo reboot

The bastion is back within a minute or two, and fail2ban starts automatically at boot. Once you’ve rebooted into a new kernel, sudo apt autoremove clears out the old one.

Don’t lock yourself out. If you change SSH configuration while patching, validate it and test a new login in a second terminal before closing your current session:

sudo sshd -t && sudo systemctl reload ssh

If you do lose SSH access, AWS builds have the SSM Agent enabled for Session Manager (with the right IAM role attached), and both clouds offer a serial console.

Re-baseline AIDE after patching. AIDE will report every file apt changed. Review the report, then accept the patched state as the new baseline:

sudo aide --config /etc/aide/aide.conf --check
sudo aideinit && sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db

Automatic security updates. Ubuntu normally runs unattended-upgrades for security fixes, and the CloudSOE build doesn’t switch it off. Check what your instance is doing:

systemctl status unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades

It installs packages but doesn’t reboot. You decide when to take the reboot, so check /var/run/reboot-required regularly. Unattended updates also change files AIDE watches, which is one more reason to re-baseline as part of your routine.

Held packages. apt-mark showhold lists anything pinned at its current version. A held openssh-server won’t get security fixes, so release holds you no longer need with sudo apt-mark unhold <package>.

Stay on Ubuntu 26.04. Don’t run do-release-upgrade on a bastion. A failed distro upgrade on your only way into the network is a bad day. When you want a newer Ubuntu release, move to a fresh CloudSOE image instead.

Upgrade the bastion’s components

There’s no separate application to upgrade. OpenSSH, fail2ban, AIDE, sssd/realmd and ntpd-rs are all Ubuntu packages, and sudo apt upgrade covers them. To patch one component in response to a specific advisory:

ssh -V                                    # OpenSSH version before
sudo apt update
sudo apt install --only-upgrade openssh-server

The same pattern works for fail2ban, aide or sssd. A few component-specific notes:

  • fail2ban. The image’s settings live in /etc/fail2ban/jail.local, which package updates don’t overwrite. After an update, check the SSH jail is still active with sudo fail2ban-client status sshd.
  • sssd and realmd. If the bastion is joined to Active Directory, test an AD login in a second terminal after updating, and check systemctl status sssd.
  • AIDE. Re-baseline after updating, as above.

Move to a fresh CloudSOE image

A fresh image gives you the latest patches on a clean, known-good base. For a security boundary like a bastion, that’s worth doing periodically even without a specific reason. Because nothing important lives on the bastion’s disk, the move is short. Running the old and new bastions side by side for a while is easy and avoids interrupting anyone.

1. Back up the old instance. Create the config tarball and user list as in Before you start.

Optionally, carry over the SSH host keys so clients don’t see a “host key changed” warning when the address moves. These are the bastion’s private identity keys, so handle them with care:

sudo tar czf /home/$(whoami)/bastion-hostkeys.tar.gz /etc/ssh/ssh_host_*
sudo chown $(whoami): /home/$(whoami)/bastion-hostkeys.tar.gz
chmod 600 /home/$(whoami)/bastion-hostkeys.tar.gz

Skip this step if you’d rather rotate host keys as part of the move. Your team will then update known_hosts instead (see step 5).

2. Launch the latest image. Follow the getting-started guide for AWS or Azure. Use the same VPC / virtual network and subnet type as the old bastion. On AWS, attach the same security group so private instances that allow SSH from it accept the new bastion too. Let bastion-firstboot finish building the AIDE database (systemctl status bastion-firstboot).

3. Copy the backup across. Copy it from your workstation:

scp <admin-user>@<old-ip>:'bastion-*' .
scp bastion-config-<date>.tar.gz bastion-users.txt <admin-user>@<new-ip>:

4. Restore on the new instance. Unpack to a staging directory so nothing is overwritten by accident. In particular, don’t overwrite the admin user’s own authorized_keys, which holds the key you just launched with:

mkdir ~/bastion-restore
sudo tar xzf /home/$(whoami)/bastion-config-<date>.tar.gz -C ~/bastion-restore
sudo ls -R ~/bastion-restore

Recreate each local user from bastion-users.txt and install their keys. For example, for a user alice:

sudo adduser --disabled-password --gecos "" alice
sudo install -d -m 700 -o alice -g alice /home/alice/.ssh
sudo install -m 600 -o alice -g alice \
  ~/bastion-restore/home/alice/.ssh/authorized_keys /home/alice/.ssh/authorized_keys

Add them to any groups they had on the old bastion, for example sudo usermod -aG sudo alice. Recreate users with adduser rather than copying /etc/passwd or /etc/shadow between hosts.

Restore SSH, sudo and fail2ban settings, validating each before it takes effect:

# SSH drop-ins (the image's own 99-cloudsoe-marketplace.conf is already present)
sudo cp -n ~/bastion-restore/etc/ssh/sshd_config.d/*.conf /etc/ssh/sshd_config.d/
sudo sshd -t && sudo systemctl reload ssh

# sudo rules: check syntax before relying on them
sudo cp -n ~/bastion-restore/etc/sudoers.d/* /etc/sudoers.d/
sudo chmod 440 /etc/sudoers.d/*
sudo visudo -c

# fail2ban tuning
sudo cp ~/bastion-restore/etc/fail2ban/jail.local /etc/fail2ban/jail.local
sudo cp -n ~/bastion-restore/etc/fail2ban/jail.d/*.local /etc/fail2ban/jail.d/ 2>/dev/null
sudo fail2ban-client -t && sudo systemctl reload fail2ban

If you carried over host keys, restore them and restart SSH:

sudo tar xzf /home/$(whoami)/bastion-hostkeys.tar.gz -C /
sudo chmod 600 /etc/ssh/ssh_host_*_key
sudo chmod 644 /etc/ssh/ssh_host_*_key.pub
sudo sshd -t && sudo systemctl restart ssh

Active Directory: join again, don’t copy. The domain join is tied to the machine account, so don’t copy sssd.conf or Kerberos keytabs across. Join the new bastion with realm join as described in the configuration guide. Use your old sssd.conf only as a reference for the settings you’d adjusted, then run realm permit for the same groups. After cutover, remove the old bastion from the domain with sudo realm leave on the old instance, or delete its computer account in AD.

Re-baseline AIDE once your changes are in place, so the baseline reflects the finished bastion:

sudo aideinit && sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db

Test a login as one of the restored users, and a jump to a private server, before you switch anything over. Then delete the staging copy and tarballs on the new instance with rm -rf ~/bastion-restore and rm ~/bastion-*.tar.gz.

5. Switch your team over. Choose one:

  • Move the address. AWS: EC2 → Elastic IPs → re-associate the Elastic IP with the new instance. Azure: dissociate the static public IP from the old VM’s NIC and associate it with the new one. Everyone’s ~/.ssh/config keeps working.
  • Update DNS if your team connects by hostname.
  • Otherwise, update HostName in every ~/.ssh/config bastion block, -J arguments in scripts, CI jobs and Ansible inventories.

If you didn’t carry over the host keys, everyone needs to remove the old key once:

ssh-keygen -R <bastion-ip-or-hostname>

Then they check the new host key fingerprint on first connect. You can print it on the new bastion with ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub and share it.

Update firewall rules on the private side too. On AWS, rules that reference the bastion’s security group carry over if the new instance uses the same group, but rules written against the old bastion’s private IP don’t. On Azure, update NSG rules that allow SSH from the old bastion’s private IP or subnet. Review the bastion’s own inbound rule for port 22 while you’re there.

6. Retire the old instance. Check that nobody is still using it (who and sudo tail /var/log/auth.log on the old bastion), then stop it. After a few days, terminate it (AWS) or delete the VM with its disks, NIC and any public IP you didn’t reuse (Azure). Delete old snapshots once you no longer need them for rollback. Delete the backup tarballs from your workstation too: they contain everyone’s public keys, and possibly the host keys.

Check everything works

Run these after any OS update or migration:

# SSH config is valid and the service is running
sudo sshd -t
systemctl status ssh
ssh -V

# Your hardening is still in effect (expect: passwordauthentication no, permitrootlogin prohibit-password)
sudo sshd -T | grep -E '^(passwordauthentication|permitrootlogin|x11forwarding) '

# fail2ban is watching SSH
systemctl status fail2ban
sudo fail2ban-client status sshd

# Time sync (Kerberos depends on it) and AIDE
systemctl status ntpd-rs
sudo aide --config /etc/aide/aide.conf --check

# Active Directory, if joined
realm list

Then, from your own machine:

ssh <admin-user>@<bastion-public-ip>
ssh -J <admin-user>@<bastion-public-ip> <user>@<private-instance-ip>

Have at least one other team member confirm they can log in and jump through before you retire anything.

Next steps