powershellsshssh-keysopensshssh-keygen

How to overwrite existing SSH key file using ssh-keygen and PowerShell without typing y


If I want to overwrite existing SSH key file without typing y, then I would do this in bash:

echo "y" | ssh-keygen -f /home/wakatana/id_rsa -N ""

How can same be achieved using PowerShell? I've tried following:

Write-Host "y" | ssh-keygen.exe -f C:\Users\wakatana\Desktop\id_rsa -N """"

It won't show me Overwrite (y/n)? dialog, but I does not rewrite existing key. What is the problem?


Solution

  • Try Write-Output instead of Write-Host:

    Write-Output "y" | ssh-keygen.exe -f .\test -N "blahblah"
    

    enter image description here