diff --git a/crmsh/bootstrap.py b/crmsh/bootstrap.py index f7b3180f8..88b83d44b 100644 --- a/crmsh/bootstrap.py +++ b/crmsh/bootstrap.py @@ -1010,9 +1010,23 @@ def generate_ssh_key_pair_on_remote( shell = sh.LocalShell() # pass cmd through stdin rather than as arguments. It seems sudo has its own argument parsing mechanics, # which breaks shell expansion used in cmd - cmd = ''' -[ -f ~/.ssh/id_rsa ] || ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -C "Cluster internal on $(hostname)" -N '' -[ -f ~/.ssh/id_rsa.pub ] || ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub + cmd = f''' +key_types=({ ' '.join(ssh_key.KeyFileManager.KNOWN_KEY_TYPES) }) +for key_type in "${{key_types[@]}}"; do + if [ -f ~/.ssh/id_${{key_type}} ]; then + pub_key_file=~/.ssh/id_${{key_type}}.pub + break + fi +done + +if [ -z "$pub_key_file" ]; then + key_type={ssh_key.KeyFileManager.DEFAULT_KEY_TYPE} + priv_key_file=~/.ssh/id_${{key_type}} + ssh-keygen -q -t $key_type -f $priv_key_file -C "Cluster internal on $(hostname)" -N '' + pub_key_file=$key_file.pub +fi + +[ -f "$pub_key_file" ] || ssh-keygen -y -f $priv_key_file > $pub_key_file ''' result = shell.su_subprocess_run( local_sudoer, @@ -1024,7 +1038,15 @@ def generate_ssh_key_pair_on_remote( if result.returncode != 0: raise ValueError(codecs.decode(result.stdout, 'utf-8', 'replace')) - cmd = 'cat ~/.ssh/id_rsa.pub' + cmd = f''' +key_types=({ ' '.join(ssh_key.KeyFileManager.KNOWN_KEY_TYPES) }) +for key_type in "${{key_types[@]}}"; do + if [ -f ~/.ssh/id_${{key_type}} ]; then + cat ~/.ssh/id_${{key_type}}.pub + break + fi +done +''' result = shell.su_subprocess_run( local_sudoer, 'ssh {} {}@{} sudo -H -u {} /bin/sh'.format(constants.SSH_OPTION, remote_sudoer, remote_host, remote_user),