Abstrax

Adding SSH access

This guide adds an SSH public key for a user, then optionally hardens the SSH server. It assumes the user already exists (see Creating a user).

1. Add the public key

You can pass the key directly:

sudo abstrax ssh-key add deploy "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5... ci@example" \
  --name=ci-deploy --comment="CI deploy key"

Or read it from a file with --from-file:

sudo abstrax ssh-key add deploy /home/deploy/id_ed25519.pub --from-file --name=ci-deploy

Expected output:

SSH key added for deploy.
  ID:          ci-deploy
  Name:        ci-deploy
  Fingerprint: SHA256:abc123...

Abstrax writes the key into the user's authorized_keys with a managed marker comment, so it can be listed and removed later.

To make a key expire, or to limit it to known addresses, pass --expires and --from. --expires is a UTC time (2026-11-07T23:59:00Z) and needs OpenSSH 8.2 or later. --from is a comma-separated list of IP addresses or CIDRs. ssh-key info reports expires_at, from, and expired.

2. Confirm the key

abstrax ssh-key list deploy
ID          TYPE          FINGERPRINT          MANAGED
ci-deploy   ssh-ed25519   SHA256:abc123...     yes

3. Test logging in

Before changing any server settings, confirm you can actually log in with the new key from another terminal:

ssh -i /path/to/private_key deploy@your-server

Do not skip this step if you plan to disable password authentication in the next step.

4. Optionally harden the SSH server

Once key-based login works, you can tighten the SSH configuration. Abstrax writes these settings to /etc/ssh/sshd_config.d/00-abstrax.conf, which sshd reads before drop-ins such as 50-cloud-init.conf. It validates the configuration with sshd -t before reloading, then checks sshd -T and fails if the new value did not take effect.

Disable password authentication (Abstrax warns you to confirm you have a working key first):

sudo abstrax ssh config disable-password-auth

Disable root login over SSH:

sudo abstrax ssh config disable-root-login

disable-root-login writes PermitRootLogin no and blocks root for every method. If root still needs to log in while password authentication is on, --keys-only is the safer choice. It writes prohibit-password, so root can use an SSH key and not a password. OpenSSH builds that still report without-password are treated the same way. Without the flag, enable-root-login writes yes.

sudo abstrax ssh config enable-root-login --keys-only

Apply the changes:

sudo abstrax ssh reload

Check the current settings at any time:

abstrax ssh config show
  Port:                        22 (default)
  PermitRootLogin:             no (abstrax)
  PasswordAuthentication:      no (abstrax)
  ClientAliveInterval:         0 (default)

The value in parentheses is where sshd got that setting: abstrax, default, or another config file.

5. Changing the SSH port (optional)

If you change the SSH port, open it in the firewall before sshd reloads. --allow-firewall does that, and leaves the previous port open so you can test a new connection. Add --close-old-port only after that connection works. If the new port does not answer, Abstrax rolls the change back.

sudo abstrax ssh config set-port 2222 --allow-firewall
sudo abstrax ssh config set-port 2222 --allow-firewall --close-old-port

set-port reloads sshd as part of the change.

If you change the firewall yourself, allow the new port before changing SSH:

sudo abstrax firewall allow 2222 --protocol=tcp
sudo abstrax ssh config set-port 2222

Safety reminders

  • Always keep a second logged-in session open while changing SSH settings, so you can revert if something goes wrong.
  • Confirm key login works before disabling password authentication.
  • Changing the port without updating the firewall can lock you out.