backups: Create .ssh folder before creating SSH key

- As a safe guard although it should exist because of a prior verification of
SSH key.

- Minor refactor to make the method flatter.

Tests:

- Remove /var/lib/plinth/.ssh and visit add remote repository form. The public
key is displayed in the form. The files in /var/lib/plinth/.ssh are created with
expected permissions.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2026-02-05 09:05:16 -08:00
parent dd0a0f56a6
commit e21ab91b21
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -148,15 +148,17 @@ def get_ssh_client_auth_key_paths() -> tuple[Path, Path]:
def generate_ssh_client_auth_key():
"""Generate SSH client authentication keypair, if needed."""
_, key_path = get_ssh_client_auth_key_paths()
if not key_path.exists():
logger.info('Generating SSH client key %s for FreedomBox service',
key_path)
subprocess.run(
['ssh-keygen', '-t', 'ed25519', '-N', '', '-f',
str(key_path)], stdout=subprocess.DEVNULL, check=True)
else:
key_path.parent.mkdir(parents=True, exist_ok=True)
if key_path.exists():
logger.info('SSH client key %s for FreedomBox service already exists',
key_path)
return
logger.info('Generating SSH client key %s for FreedomBox service',
key_path)
subprocess.run(
['ssh-keygen', '-t', 'ed25519', '-N', '', '-f',
str(key_path)], stdout=subprocess.DEVNULL, check=True)
def get_ssh_client_public_key() -> str: