27

I am trying to install OpenSSH on a Windows Server (2012 R2 standard) and I have been following the instructions at this locataion: https://www.server-world.info/en/note?os=Windows_Server_2012&p=openssh

I ran Powershell as Administrator and all seems to install correctly up to the part where I try to generate the SSH host-key by running the command .\ssh-keygen.exe -A (step 7 of the instructions). After running this it returns an error saying:

RSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_rsa_key.9uX3wf3apv: No Such file of directory"

The same error also displays for DSA, ECDSA and ED25519.

Screenshot of errors

If anyone can tell me where I am going wrong here it would be appreciated. I've searched the web and not found any other references to this.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Evvy73
  • 271
  • 1
  • 3
  • 4

4 Answers4

80

The __PROGRAMDATA__ refers to your environment variable PROGRAMDATA (Which probably is set to C:\ProgramData).

It is usually easiest to open an cmd command prompt and type

mkdir %PROGRAMDATA%\ssh

or powershell

mkdir $env:ProgramData\ssh

and then rerun the

.\ssh-keygen.exe -A
Anthon
  • 69,918
  • 32
  • 186
  • 246
33

I got the same error but when I manually added a folder under programdata called SSH and then ran the command again it seemed to work

Scott Coats
  • 339
  • 2
  • 2
2

You have to do this from an cmd prompt as powershell messes up the ProgramData variable.

Do this

C:\Program Files\OpenSSH-Win64>powershell .\install-sshd.ps1 -A

from a command prompt and you will probably be good to go.

Anthon
  • 69,918
  • 32
  • 186
  • 246
0

If you want, you can run it as administrator. This will give ssh-keygen.exe all the rights it needs to create files on its own.

runas.exe /noprofile /user:Administrator .\ssh-keygen.exe

This will install the keys under C:\Users\Administrator.ssh

If you want the keys to be accessible to your current user or another user just run Powershell as that user by right clicking on it and clicking Run as Different User.

You do not want to be in an elevated Powershell when you generate keys

OpenSSH runs from the current user and checks their C:\Users\UserName.ssh. Similar to how SSH works in Linux.