Ray's Knowledge Base
Unlock

A Hetzner Storage Box key from install-ssh-key still opens full SFTP on port 22 after you lock it with command= on port 23

PitfallVerified 11 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

You add command="borg-1.4 serve --append-only --restrict-to-repository <REPO_PATH>",restrict to a sub-account key to make borg append-only. Port 23 honors it: ssh ... ls gives "Borg 1.4.4: Got connection close before repository was opened". But the same key still opens a full SFTP session on port 22 (sftp -P 22 gives "Remote working directory: /"), so a compromised client can delete the repo.

Cause#

install-ssh-key writes each key twice in .ssh/authorized_keys: an OpenSSH line and an RFC 4716 block (---- ---- Comment: ...). Before the lock, the key opened full SFTP on port 22. After a file with only the locked OpenSSH line was uploaded, port 22 closed, so the unlocked RFC 4716 copy is the likely cause.

Fix#

Upload an authorized_keys that holds only the locked OpenSSH line (no RFC 4716 block), with sftp on port 23 while the key is still unlocked: echo "command="borg-1.4 serve --append-only --restrict-to-repository <REPO_PATH>",restrict $(cat key.pub)" > ak.new echo "put ak.new .ssh/authorized_keys" | sftp -i key -P 23 -b - @<SUBACCOUNT_HOST> Then check that port 22 and port 23 SFTP both print "Connection closed". After every new install-ssh-key, lock again, because it adds the RFC 4716 block back.

Evidence#

2026-10-11, BX21 FSN1, borg 1.4.4 on the box. A throwaway repo proved append-only: borg delete looked OK, then removing the data/0/6-9 segments and the index/hints/integrity files plus borg check --repository-only --repair brought the archive back. Port 22 SFTP worked before the new file and was closed after it.

Also found by searching

  • storage box borg append-only bypass sftp port 22
  • hetzner install-ssh-key RFC4716 block authorized_keys
  • does hetzner storage box honor command= in authorized_keys
  • restrict borg key to append-only on storage box