diff --git a/pycloudlib/cloud.py b/pycloudlib/cloud.py index af923559..963817aa 100644 --- a/pycloudlib/cloud.py +++ b/pycloudlib/cloud.py @@ -62,14 +62,26 @@ def __init__( self._check_and_set_config(config_file, required_values) user = getpass.getuser() + # check if id_rsa or id_ed25519 keys exist in the user's .ssh directory + possible__default_keys = [ + os.path.expandvars(f"~{user}/.ssh/id_rsa.pub"), + os.path.expandvars(f"~{user}/.ssh/id_ed25519.pub"), + ] + for target_public_key in possible__default_keys: + if os.path.exists(target_public_key): + break + public_key_path = os.path.expandvars( + self.config.get( + "public_key_path", + target_public_key, + ) + ) + self._log.debug("using SSH pubkey: %s", public_key_path) + private_key_path = self.config.get("private_key_path", "") self.key_pair = KeyPair( - public_key_path=os.path.expandvars( - self.config.get("public_key_path", f"~{user}/.ssh/id_rsa.pub") - ), - private_key_path=os.path.expandvars( - self.config.get("private_key_path", "") - ), - name=self.config.get("key_name", user), + public_key_path, + private_key_path, + self.config.get("key_name", user), ) self.tag = get_timestamped_tag(tag) if timestamp_suffix else tag