Skip to content

Fix broken keyPath to ssh-keygen #7024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marcleblanc2
Copy link

Problem

When keyPath contains spaces, ex. /Users/username/Library/Application Support/Code/User/globalStorage/amazonwebservices.aws-toolkit-vscode/aws-ec2-key the ssh-keygen command fails with "Too many arguments", and doesn't get caught by the "Unknown key type" failure check.

This results in log output like

[error] aws.ec2.openRemoteConnection: Error: Unable to connect to target instance on region . Testing SSM connection to instance failed: Warning: Permanently added 'aws-ec2-' (ED25519) to the list of known hosts.
no such identity: /Users/username/Library/Application Support/Code/User/globalStorage/amazonwebservices.aws-toolkit-vscode/aws-ec2-key: No such file or directory
ec2-user@aws-ec2-: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). [EC2SSMTestConnect]

Workaround

Manually run the command with a double quoted path to create the key in this path.

Solution

Double quote the path in the command arg


  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

When keyPath contains spaces, ex. `/Users/username/Library/Application Support/Code/User/globalStorage/amazonwebservices.aws-toolkit-vscode/aws-ec2-key` the ssh-keygen command fails with "Too many arguments", and doesn't get caught by the "Unknown key type" failure check. 

This results in log output like

[error] aws.ec2.openRemoteConnection: Error: Unable to connect to target instance <id> on region <region>. Testing SSM connection to instance failed: Warning: Permanently added 'aws-ec2-<id>' (ED25519) to the list of known hosts.
no such identity: /Users/username/Library/Application Support/Code/User/globalStorage/amazonwebservices.aws-toolkit-vscode/aws-ec2-key: No such file or directory
ec2-user@aws-ec2-<id>: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). [EC2SSMTestConnect]

Workaround: manually run the command with a double quoted path to create the key in this path.
@marcleblanc2 marcleblanc2 requested a review from a team as a code owner April 11, 2025 21:42
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.

@justinmk3
Copy link
Contributor

Thanks for looking into this. Did you confirm that this change fixes the issue? I am surprised if it does, because the list form of arguments should already do that. By adding quotes as you've done here, it will send literal " chars to the program.

If that fixes the issue, that might indicate a bug in ssh-keygen. It's certainly worth a workaround to avoid such a bug, but we need to make sure it doesn't regress anything.

@@ -81,7 +81,7 @@ export class SshKeyPair {
}
return await tryRun(
'ssh-keygen',
['-t', keyType, '-N', '', '-q', '-f', keyPath],
['-t', keyType, '-N', '', '-q', '-f', concat('"', keyPath, '"')],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm error src/awsService/ec2/sshKeyPair.ts(84,51): error TS2304: Cannot find name 'concat'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants