Skip to content

SSH persistence guide

Carl Kittelberger edited this page Jul 12, 2026 · 4 revisions

SSH Persistence Across Firmware Upgrades

Overview

This guide explains how to prepare your Denon PRIME 4 filesystem so that SSH access persists across reboots and firmware upgrades on Engine OS 5.x (AZ01, Yocto-based).

The Overlay Mechanism

The Denon PRIME 4 uses overlayfs to separate persistent user data from the read-only root filesystem. /etc and /var are each mounted as a real OverlayFS union (confirmed from the etc.mount/var.mount unit definitions):

[Mount]
What=overlay
Where=/etc
Type=overlay
Options=lowerdir=/etc,upperdir=/data/system/etc/overlay,workdir=/data/system/etc/.work

(and the equivalent for /var, with upperdir=/data/system/var/overlay.)

The rest of the filesystem, including /root, /usr and /home, is mounted read-only (/dev/root / auto ro in /etc/fstab) and is fully replaced on every firmware update. Only /data (and therefore the two overlay upper directories) is persistent.

graph TD
    A[Boot Process] --> B[Mount Root Filesystem read-only]
    A --> C[Mount data Partition]
    B --> D[etc - base config files]
    B --> E[var - base variable data]
    C --> F[data/system/etc/overlay]
    C --> G[data/system/var/overlay]
    D --> H[overlayfs Merge]
    E --> I[overlayfs Merge]
    F --> H
    G --> I
    H --> J[etc - merged view]
    I --> K[var - merged view]
    style F fill:#90EE90
    style G fill:#90EE90
    style D fill:#FFB6C1
    style E fill:#FFB6C1
Loading

This means:

  • ✅ Anything placed under /data/system/etc/overlay/ or /data/system/var/overlay/ survives reboots and firmware upgrades (as long as /data itself isn't reformatted).
  • ❌ Anything written to the base rootfs (/etc/..., /var/..., /root/..., /usr/...) at runtime is lost on reboot, because the underlying rootfs is mounted read-only and gets replaced wholesale on every firmware update anyway.

Denon's Active Wipe List — Avoid These Paths

/etc/az01/overlayfs.conf is a systemd-tmpfiles config, run by overlayfs-setup.service (systemd-tmpfiles --create --remove /etc/az01/overlayfs.conf) before etc.mount/var.mount are mounted, i.e. on every single boot:

r /data/system/etc/overlay/group   - - - -
r /data/system/etc/overlay/gshadow - - - -
r /data/system/etc/overlay/passwd  - - - -
r /data/system/etc/overlay/shadow  - - - -

R /data/system/etc/overlay/ssh     - - - -

r deletes a single file; R deletes a whole directory tree, recursively. This means:

  • Anything under /data/system/etc/overlay/ssh/ — which is where the rootfs-level /etc/ssh/sshd_config.d/ and /etc/ssh/authorized_keys.d/ override paths would naturally land — is deleted before the overlay is even mounted, every boot.
  • /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow overrides are deleted the same way, so setting a root password via the overlay does not work either.

There's also R /data/system/var/overlay/run (clears stale runtime state each boot, standard practice) — this only affects the run subdirectory under the /var overlay, nothing else.

Anything you persist for SSH must avoid /data/system/etc/overlay/ssh/* and the four auth files listed above. Everything else under /data/system/etc/overlay/ and /data/system/var/overlay/ (aside from run) is left alone.

What's Already In Place on Stock Firmware

Stock 5.x firmware already ships (baked directly into the rootfs, not the overlay, so it is not affected by the wipe list):

  • /etc/ssh/sshd_config.d/10-az0x.conf:
    HostKey /etc/ssh/ssh_host_ed25519_key
    HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-ed25519
    
    PermitRootLogin prohibit-password
    
    PasswordAuthentication no
    KbdInteractiveAuthentication no
    
    i.e. root login via SSH key is already permitted; only password/interactive login is disallowed. No sshd_config override is required.
  • An empty /root/.ssh/ directory, but no authorized_keys — so nobody can actually log in yet.
  • sshd.service exists but is not enabled (/usr/lib/systemd/system/multi-user.target.wants/ only contains dbus.service, getty.target, systemd-ask-password-wall.path, systemd-update-utmp-runlevel.service — no sshd.service).

So the only two things that actually need to persist are: (1) enabling sshd.service, and (2) supplying an authorized_keys file for root from a path that isn't on the wipe list.

Procedure

Step 1: Connect to Your Device

You need existing shell access (e.g. from a modified 4.x firmware with SSH already enabled, or a serial/UART console) to run these commands once.

Step 2: Enable sshd.service via the /etc Overlay

Create the systemd override symlink at the standard /etc/systemd/system/ unit-search path (not /etc/lib/..., which systemd never scans):

mkdir -p /data/system/etc/overlay/systemd/system/multi-user.target.wants
ln -s /usr/lib/systemd/system/sshd.service \
  /data/system/etc/overlay/systemd/system/multi-user.target.wants/sshd.service

This is identical in effect to what systemctl enable sshd.service would create, and after the /etc overlay merge it appears at /etc/systemd/system/multi-user.target.wants/sshd.service — the same location systemd's own persistent unit overrides live in.

Step 3: Provide Your Public Key Outside the Wipe List

Store the key under the /var overlay instead of /etc/ssh/authorized_keys.d/ (which is wiped):

mkdir -p /data/system/var/overlay/ssh-keys/root
chmod 700 /data/system/var/overlay/ssh-keys/root
# Paste your public key content into the file below, one key per line:
cat > /data/system/var/overlay/ssh-keys/root/authorized_keys << 'EOF'
ssh-ed25519 AAAA... your-key-comment
EOF
chmod 600 /data/system/var/overlay/ssh-keys/root/authorized_keys

This merges to /var/ssh-keys/root/authorized_keys after the /var overlay is mounted.

Step 4: Point sshd at That Key File

Override AuthorizedKeysFile via SSHD_OPTS in /etc/default/ssh (also not on the wipe list; sshd.service sources it via EnvironmentFile=-/etc/default/ssh):

mkdir -p /data/system/etc/overlay/default
cat > /data/system/etc/overlay/default/ssh << 'EOF'
SYSCONFDIR=${SYSCONFDIR:-/etc/ssh}
SSHD_OPTS="-o AuthorizedKeysFile=/var/ssh-keys/root/authorized_keys"
EOF

Step 5: Reboot and Test

reboot

After reboot:

ssh root@<device-hostname-or-ip>

You should get a root shell — no password prompt, since PasswordAuthentication no is already the stock default and we're relying entirely on pubkey auth.

Verifying the Setup

# Confirm the overlay is mounted
mount | grep overlay

# Confirm sshd.service is enabled and running
systemctl is-enabled sshd
systemctl status sshd

# Confirm the key file merged correctly
cat /var/ssh-keys/root/authorized_keys

# Confirm the env override merged correctly
cat /etc/default/ssh

Troubleshooting

ssh: connect to host ... port 22: Connection refused

This means the network stack is up but nothing is listening on port 22 — almost always sshd.service is not enabled. Check:

systemctl is-enabled sshd   # should print "enabled"
ls -l /etc/systemd/system/multi-user.target.wants/   # should list sshd.service

If the symlink is missing after a reboot, double-check it was created at /data/system/etc/overlay/systemd/system/multi-user.target.wants/sshd.service (not .../lib/systemd/system/...) — that's the exact mistake that causes this symptom.

Permission denied (publickey)

  • Confirm /var/ssh-keys/root/authorized_keys exists after the overlay merge and contains your public key on its own line.
  • Confirm /etc/default/ssh merged correctly and SSHD_OPTS is being picked up (systemctl show sshd.service | grep Environment).
  • Confirm file permissions: chmod 700 on ssh-keys/root, chmod 600 on the authorized_keys file itself, owned by root.

Files Disappear After Reboot

If files placed under /data/system/etc/overlay/ssh/... or the four auth files (passwd, shadow, group, gshadow) vanish after every reboot, that's expected — see Denon's Active Wipe List above. Move the content to a path outside that list (as this guide now does).

Security Considerations

  • SSH key authentication only. Stock firmware already disables password and keyboard-interactive authentication (PasswordAuthentication no, KbdInteractiveAuthentication no) — this guide does not change that, and there is no working path to persist a root password anyway (/etc/shadow overrides are wiped every boot).
  • Treat /var/ssh-keys/root/authorized_keys like any other authorized_keys file: keep its permissions tight (700/600) and only add keys you trust with full root access.
  • Firmware upgrades within the 5.x line (e.g. 5.0.0 → 5.0.3) do not reformat /data, so this setup persists across them. Major version changes (e.g. downgrading to/from 4.x Buildroot-based firmware) use a completely different init system and overlay layout, so this configuration does not carry over across that boundary and must be reapplied.

Additional Resources

Clone this wiki locally