diff --git a/runpod/cli/groups/ssh/commands.py b/runpod/cli/groups/ssh/commands.py index 1c6e43764..30ae470cd 100644 --- a/runpod/cli/groups/ssh/commands.py +++ b/runpod/cli/groups/ssh/commands.py @@ -5,7 +5,7 @@ import click from prettytable import PrettyTable -from .functions import generate_ssh_key_pair, get_user_pub_keys +from .functions import add_ssh_key, generate_ssh_key_pair, get_user_pub_keys class SSHGroup(click.Group): @@ -69,7 +69,18 @@ def add_key(key, key_file): Adds an SSH key to the current user account. If no key is provided, one will be generated. """ - if not key and not key_file: + if key_file: + with open(key_file, "r", encoding="utf-8") as f: + public_key = f.read().strip() + if not public_key: + raise click.ClickException("The specified key file is empty.") + add_ssh_key(public_key) + elif key: + public_key = key.strip() + if not public_key: + raise click.ClickException("The provided public key is empty.") + add_ssh_key(public_key) + else: click.confirm("Would you like to add an SSH key to your account?", abort=True) key_name = click.prompt( "Please enter a name for this key", default="RunPod-Key", type=str