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.
This commit is contained in:
gryf committed 2026-11-24 21:59:43 +01:00
1 parent e3ae80244b
commit b9f2bc1846
2 files changed
+17 -4

No files matched your search

+1 -1
View File
@@ -82,7 +82,7 @@ You'll have ``boxpy`` command created for you as well.
.. code:: shell-session .. code:: shell-session
$ boxpy -V $ boxpy -V
boxpy 1.11.3 boxpy 1.11.6
Other option is simply link it somewhere in the path: Other option is simply link it somewhere in the path:
+16 -3
View File
@@ -18,7 +18,7 @@ import requests
import yaml import yaml
__version__ = "1.11.3" __version__ = "1.11.6"
CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache')) CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
CLOUD_IMAGE = "ci.iso" CLOUD_IMAGE = "ci.iso"
@@ -46,7 +46,6 @@ ssh:
boxpy_data: boxpy_data:
cpus: 1 cpus: 1
disk_size: 6144 disk_size: 6144
key: ~/.ssh/id_rsa
memory: 1024 memory: 1024
''' '''
COMPLETIONS = {'bash': '''\ COMPLETIONS = {'bash': '''\
@@ -542,10 +541,24 @@ class Config:
self.ssh_key_path = os.path.join(os.path.expanduser("~/.ssh"), self.ssh_key_path = os.path.join(os.path.expanduser("~/.ssh"),
self.ssh_key_path) self.ssh_key_path)
if not os.path.exists(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): def _set_defaults(self):
conf = yaml.safe_load(USER_DATA) 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 # update attributes with default values
for key, val in conf['boxpy_data'].items(): for key, val in conf['boxpy_data'].items():