I am trying to copy a client key from Linux(Ubuntu) to Windows server as an administrator user.
so far i am able to achieve this by using following steps:

I am using bash in linux and powershell 7.3.4 in windows as an administrator.

  1. Copy the public key from linux client to windows server:
    scp ~/.ssh/public_key.pub Admin@WindowsServer:__PROGRAMDATA__/ssh/
  2. ssh into windows server and check if there is administrators_authorized_keys file present in C:\PROGRAMDATA\SSH\
    If not, Create:
    New-Item -Force -Path c:\PROGRAMDATA\ssh\administrators_authorized_keys
  3. Set Permissions for administrators_authorized_keys file:
    icacls C:\PROGRAMDATA\ssh\administrators_authorized_keys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
  4. Append public_key.pub content into administrator_authorized_keys.
    Get-Content C:\ProgramData\ssh\public_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys

Now that the administrators_authorized_keys file has been created and configured, i am trying to have a different linux client to append its public key to this windows server (with administrators_authorized_keys configured) using scp in ONE-LINE.

I have tried something like this:
scp Linux2Win_key.pub Admin@WindowsServer:__ProgramData__/ssh/ ; Get-Content C:\ProgramData\ssh\Linux2Win_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys
Public key file is copied but NOT appended to the administrator_authorized_keys file. Got an Error:
-bash: Add-Content: command not found
-bash: Get-Content: command not found
Then i tried this : scp Linux2Win_key.pub Admin@WindowsServer:__ProgramData__/ssh/ ; cat __ProgramData__/ssh/Linux2Win_key.pub >> __ProgramData__/ssh/administrators_authorized_keys
Similar result, Public key file is copied but NOT appended to the administrator_authorized_keys file. Got an Error:
-bash: __ProgramData__/ssh/administrators_authorized_keys: No such file or directory

It looks like scp can only copy files and ssh-copy-id don't work in windows despite openssh can be enabled and ssh can be used in windows.

If you know any better way (rather than doing manually) to append public key to authorized_keys or administrators_authorized_keys in windows, please share. Thanks
I know, this is more of a windows issue and i have tried asking everywhere else.
I am sorry if it offends anyone that i present this issue in linux/unix fourm.

1 Answer 1


It seems I was just missing quotes!

When using scp command, after Admin@WindowsServer:, the content must be in quotes.

scp Linux2Win_key.pub Admin@WindowsServer:'__ProgramData__/ssh/ ; Get-Content C:\ProgramData\ssh\Linux2Win_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys'

This worked for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .