Port 22 vanishes,
The service survives.

The complex relocates OpenSSH to a hidden port known only to the server administrator. After the move, port 22 simply ceases to exist. There is no service behind it, no open door — and attacking it becomes pointless. And for those who come looking for the old door, a CORE trap can be deployed on the freed port 22.

Relocation, not redirection

In AGL, this operation is called castling — a chess term that refers to changing port positions in a single move. The essence is simple: the port is relocated, and in place of the old door, the server administrator can install a trap.

The MOVE_PORT command completely removes OpenSSH from port 22 and raises it on a hidden port, the number of which the administrator can pre-set at their discretion. The hidden port parameter is set in SETTINGS (default 2244).

Changing the port is not redirection or "substitution": port 22 disappears from the host — there is no service or open door behind it. Uninvited guests don't even get a Connection refused (connection reset) response from the kernel. After the move, the server simply remains silent, and the most intrusive scanners receive an Operation timed out response.

Masking the socket activator

Starting with Ubuntu 24.04, port 22 is held by default not by the SSH service itself, but by the system socket activator ssh.socket — a spare door through which systemd would return the port. Canonical began experimenting with this technology back in the interim release of Ubuntu 22.10, but it was precisely by version 24.04 LTS that the socket activation mechanism became a permanent "out-of-the-box" standard.

Because of this, the classic port change in sshd_config no longer works directly: the activator would continue to hold port 22. To ensure the move to another port is successful, the ssh.socket unit is stopped, disabled, and masked with the systemctl mask command. After this procedure, socket activation is completely neutralized and does not interfere with manual service management.

The admin cannot lock themselves out

Anti-lockout — literally "anti-self-blocking": a set of guarantees ensuring the administrator will not lose access to their own server during the port move. The complex performs no hidden actions: access appears and disappears only by the explicit intent of the administrator. More about changing access in the Web Gateway section.

During the port move, the complex establishes a local loop (unconditional, lives throughout the entire move) which guarantees unconditional access from the inside. Also, by default, the complex does not limit access from the outside. A limit, or port hiding, can always be set using separate options if required. More about changing access in the Web Gateway section, as well as in the Security Layers section.

Relocation safeguards

The complex accounts for a possible collision that could lead to administrator self-lockout. A safeguard is built into the relocation and reverse relocation operations. If the administrator has activated a CORE trap on port 22, the operation is canceled with a warning.

A similar safeguard triggers if armor (AntiDDoS) is armed on port 22. The complex rejects the move with an explicit message: "First remove the armor from the standard port (ANTIDDOS), then perform the move." Armor and relocation are mutually exclusive states: armor protects an active port, while relocation closes it. That is why the admin must first consciously remove the armor, and then perform the move. Later, if the admin deems it necessary to arm armor on the hidden port — they can do so as a separate operation.

Note: If Option B was enabled, the port will be removed even if armor was installed on it.

Every step is reversible

castling — procedure (illustration)
# 1. backups: factory anchor (once) + 3 stamped rolling copies
cp sshd_config → sshd_config.agl_backup_YYYYMMDDHHMMSS
# 2. privsep insurance: /run/sshd is restored before verification
# 3. config edit: Port → hidden port
# 4. syntax check before application
sshd -t || rollback # failure rolls back the previous config
# 5. application: the service restarts on the new port
# 6. accessibility rule: the new port inherits the rule type of port 22

Factory anchor — during the first move, an initial copy of the sshd configuration is created, taken once and never overwritten. The copy of the original configuration is written as sshd_config.agl_original.

The first copy stores the "pre-AGL" state. Further, with each subsequent move, a rolling backup is written. Rotation occurs across three files. This amount is enough to cancel any failed step, and not enough to clutter the disk with duplicates.

The complex also accounts for the specifics of tmpfs: the /run/sshd directory disappears after a reboot, and without it, sshd rejects even a perfectly configured change. Therefore, before each check, the complex restores the directory — and only then verifies if everything is fine with the service via the sshd -t command. The slightest deviation from the plan — a rollback to the previous config along with a log entry.

Conflict-free coexistence

Armor (AntiDDoS, LIMIT rule) and protection (doors A/B) can coexist on the same port. This is a conscious choice by the admin: under attack, the limit reduces server RAM usage, while the doors maintain priority for the whitelist. The complex does not touch the LIMIT when enabling protection — the armor remains if the admin armed it. More about AntiDDoS in the Perimeter and Core Armor section.

What happens when armor is removed

Reverse castling and armor

During reverse castling, the armor on the hidden port is cleared, but NOT restored on port 22. The admin arms armor on 22 consciously after the move. No automatic migration of stateful states — every action is declarative and reversible.

Reverse castling

Return to factory state

OpenSSH returns to port 22, and the complex restores the factory perimeter. The standard SSH rule is restored exactly as it was before the move. Ubuntu 24.04 services are revived: the socket activator is unmasked and monopolistically intercepts port 22. The complex restores the factory geometry.

Anti-lockout during reverse castling

Anti-lockout guarantees that returning the port will not lead to self-lockout. Before starting the reverse castling, the complex checks whether a CORE trap is deployed on port 22. If a CORE trap is installed, to avoid conflict, the reverse castling is canceled until it is disabled.

Armor is not migrated automatically

If armor was armed on the hidden port, it is cleared during reverse castling. The log writes a prompt: "Reverse castling: hidden port armor cleared. Arm armor on port 22 (ANTIDDOS)."

The AGL complex keeps records of the move in the log, where it stores a complete chronicle of events in the form of structured entries.

What the system promises the administrator