ssh-import-id

raw JSON →
5.13 verified Mon Apr 27 auth: no python

Authorize SSH public keys from trusted online identities (GitHub, GitLab, Launchpad, etc.). Current version 5.13, with stable release cadence since 2019. Integrated into Ubuntu/Canonical Cloud images for key management.

pip install ssh-import-id
error ModuleNotFoundError: No module named 'ssh_import_id'
cause ssh-import-id is not installed or imported with wrong name (hyphen instead of underscore).
fix
Install: pip install ssh-import-id. Import: from ssh_import_id import main.
error ssh-import-id: error: unrecognized arguments: --auto
cause The --auto flag was removed in version 5.10.
fix
Use --retry N instead, e.g., ssh-import-id --retry 3 gh:user.
gotcha The Python module (ssh_import_id) is intended for use as a library but the primary interface is the CLI. Calling main() directly may raise SystemExit on non-zero exit.
fix Use subprocess.run(['ssh-import-id', ...]) for production scripts; wrap main() call in try/except SystemExit if using the library.
gotcha ssh-import-id requires the target user to have a home directory and ~/.ssh/authorized_keys file. May fail silently if not present.
fix Ensure the user exists and has proper directory permissions. Run as the target user or use sudo -u.
deprecated The --auto option (automatic retry) and --erase (remove keys from other sources) have been deprecated in version 5.10+.
fix Use --retry N for retries; use --remove to delete keys from specific sources.

Quickstart: authorize keys from GitHub user 'cmars' using subprocess or the Python module. The CLI is the primary interface.

import subprocess
import os
# Fetch and add keys from GitHub user 'cmars'
subprocess.run(['ssh-import-id', 'gh:cmars'], check=True)
# Or run from Python with module
from ssh_import_id import main
try:
    main(['gh:cmars'])
except SystemExit as e:
    print(f'Exited with code {e.code}')