Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

ssh-keygen fails with tilde ~

Open ThomasNieto opened this issue 1 year ago • 1 comments
trafficstars

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest version
  • [X] Search the existing issues.

Steps to reproduce

If you try to use tilde ~ to represent the user's home path ssh-keygen will fail.

Expected behavior

Keys generated successfully

Actual behavior

ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\thomas/.ssh/id_rsa): ~/abc/id_abc
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Saving key "~/abc/id_abc" failed: No such file or directory

Error details

No response

Environment data

Tested in Windows PowerShell 5.1 and PowerShell 7.4.1

Version

8.6.0.1

Visuals

No response

ThomasNieto avatar Feb 16 '24 19:02 ThomasNieto

This seems to me a user misunderstanding, rather than a bug.

The tilde expansion is a feature of POSIX shells, such as sh, ksh, dash, bash, zsh. It is not a feature of Windows shells, afaik. The closest equivalent to the ~ prefix under a Windows shell is probably the %USERPROFILE% environment variable.

Even on POSIX systems, the tilde expansion only works on the command line, where the shell substitutes it before ssh-keygen is called, not when ssh-keygen asks for a path interactively, because the latter won't pass through the shell.

Try: ssh-keygen -f %USERPROFILE%/abc/id_abc

Your shell (e.g., cmd.exe) will replace this with ssh-keygen -f C:\Users\thomas/abc/id_abc before calling ssh-keygen.

mgkuhn avatar Jul 31 '24 10:07 mgkuhn