假如执行ssh-keygen -t rsa -C "eric_zhng@hotmail.com"获取公钥和秘钥的时候出现以下错误

1
2
3
4
5
6
$ ssh-keygen -t rsa -C "eric_zhng@hotmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): C:\Users\Administrator\github\.ssh
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Saving key "i\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~\033[3~C:\\Users\\Administrator\\github\\.ssh" failed: No such file or directory

解决办法参考GPT的回复

The error you’re encountering occurs because the path C:\Users\Administrator\github\.ssh does not exist. When you use ssh-keygen, it needs to save the key in a valid directory, but this path might not exist yet.

Here’s how you can resolve this issue:

  1. Create the directory: Make sure the directory C:\Users\Administrator\github\.ssh exists before running the command. You can create the directory by running the following command in a Command Prompt or PowerShell:
1
mkdir C:\Users\Administrator\github\.ssh
  1. Run the command again: After creating the directory, rerun the ssh-keygen command:
1
ssh-keygen -t rsa -C "eric_zhng@hotmail.com" -f C:\Users\Administrator\github\.ssh\id_rsa

The -f option is used to specify the file in which to save the private key.

Afterward, you should be able to generate the SSH key without encountering the “No such file or directory” error.