0

I'm using the PowerShell terminal in Windows 10.
I created a folder "new_folder" in ~/.ssh

mkdir ~/.ssh/new_folder

Then I try to run ssh-keygen with the -f option.
The documentation says "[-f output_keyfile]".
Both ssh-keygen -t rsa -b 4096 -f ~/.ssh/new_folder
and ssh-keygen -t rsa -b 4096 -f ~/.ssh/new_folder/new_file fail with this error:

Saving key "~/.ssh/new_folder" failed: No such file or directory

I did the same using CMD terminal, and it works with both relative and absolute path.

ssh-keygen -t rsa -b 4096 -f "C:/Users/alex/.ssh/new_key"
ssh-keygen -t rsa -b 4096 -f "./new_key"

What's wrong with ssh-keygen in PowerShell ?

phuclv
  • 26,555
  • 15
  • 113
  • 235
Alex 75
  • 113
  • 4
  • (1) The text does not correspond the picture (`new_folder` vs `new`). (2) It *seems* the tilde is not expanded in the `ssh-keygen` case. I know little about Windows, nothing about PowerShell, so this is not an answer. – Kamil Maciorowski Jun 30 '22 at 11:16
  • 2
    The two commands are not even the same… – Ramhound Jun 30 '22 at 11:51
  • Thanks. I removed the images (just there to show the error). PS and CMD commands are slightly different because the nature of their console... CMD does not have the tilde for user home path. Also adjusted the order of parameters (not sure if that was relevant) to be the same. – Alex 75 Jun 30 '22 at 12:30
  • Is the "OpenSSH Authentication Agent" system service running? Try also to use `c:\Users\USERNAME\.ssh\id_rsa`. Avoid using the tilde. (Add to your comment `@harrymc` for me to be notified.) – harrymc Jun 30 '22 at 14:45
  • Yes, as Kamil pointed out (I missed his initial comment) the tilde is not working (expanded). That was actually the right answer. I assumed it was fine because _mkdir_ accepts it. So, yes, using C:\Users\USERNAME\.ssh\my_key works fine. (@harrymc, no "OpenSSH Authentication Agent" is not running, it is disabled!) – Alex 75 Jun 30 '22 at 16:36

1 Answers1

0

The tilde in PowerShell only works under certain conditions, so it's better to avoid it, because you can't know without trying if it will work in your context.

So, instead of ~/.ssh/ you should use C:\Users\USERNAME\.ssh. This will work in all cases.

harrymc
  • 455,459
  • 31
  • 526
  • 924