From b9f2bc18463df2c4a5e4b6b001dfe36645d485b3 Mon Sep 17 00:00:00 2001 From: gryf Date: Tue, 24 Nov 2026 21:58:36 +0100 Subject: [PATCH] Find ssh keys in other types then RSA. In case user doesn't have either ~/.ssh/id_rsa or didn't provide key through the commandline or config file, the boxpy will complain about missing ssh key. With this commit all default supported types of ssh keys are checked prior to parsing commandline/configuration, and first one will be selected. The order of the key types is described in manual for ssh-keygen. --- README.rst | 2 +- box.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 4d20b5b..3216f84 100644 --- a/README.rst +++ b/README.rst @@ -82,7 +82,7 @@ You'll have ``boxpy`` command created for you as well. .. code:: shell-session $ boxpy -V - boxpy 1.11.3 + boxpy 1.11.6 Other option is simply link it somewhere in the path: diff --git a/box.py b/box.py index 0c0e3f0..6458d54 100755 --- a/box.py +++ b/box.py @@ -18,7 +18,7 @@ import requests import yaml -__version__ = "1.11.3" +__version__ = "1.11.6" CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache')) CLOUD_IMAGE = "ci.iso" @@ -46,7 +46,6 @@ ssh: boxpy_data: cpus: 1 disk_size: 6144 - key: ~/.ssh/id_rsa memory: 1024 ''' COMPLETIONS = {'bash': '''\ @@ -542,10 +541,24 @@ class Config: self.ssh_key_path = os.path.join(os.path.expanduser("~/.ssh"), self.ssh_key_path) if not os.path.exists(self.ssh_key_path): - raise BoxConfError(f'Cannot find ssh public key: {self.key}') + if self.key: + raise BoxConfError(f"Cannot find ssh public key: '{self.key}'") + else: + raise BoxConfError(f"Cannot find any default ssh public key") def _set_defaults(self): conf = yaml.safe_load(USER_DATA) + conf['boxpy_data']['key'] = '' + # find out if there are SSH keys already. Set the first key found + for key in ['id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', + 'id_mldsa44_ed25519', 'id_rsa']: + if os.path.exists(os.path + .join(os.path + .expanduser('~/.ssh'), key)): + conf['boxpy_data']['key'] = key + break + else: + LOG.warning("There is no usable default key found in ~/.ssh") # update attributes with default values for key, val in conf['boxpy_data'].items():