The Windows version of OpenSSH client doesn't include a ssh-copy-id command. I don't know why. If it does one day, then this gist can be ignored.
- This script is written in PowerShell as the legacy program
cmd.exe
is not flexible enough for the required options. - Download the file
ssh-copy-id.ps1
to your Windows PC, or copy and paste its contents to a file of the same name. - Run the script passing your linux account ssh information (for example
powershell .\ssh-copy-id.ps1 [email protected]
). If you use a non-standard port add the parameter-port=nnnn
. This should work with any Linux platform. - Run the command for each linux account you connect with. You will be prompted for your Linux host password. If you have more than 1 account on any machine, you must do this for each account.
If the script won't run, then run this command once
Set-ExecutionPolicy RemoteSigned CurrentUser
Refer to https://go.microsoft.com/fwlink/?LinkID=135170
The file name and location of the script is not important but the filename extension must be .ps1
If the public key is already known to the account, it will not be added again.
For a complete description of available options run powershell .\ssh-copy-id.ps1 -?
Prerequisites
- You have installed Microsoft's version of OpenSSH Client on your machine. Read this. You do NOT need to install SSH Server. Current versions of Windows 10 and Windows 11 have OpenSSH installed as part of the base Operating System and you do NOT need to install it.
- You have generated a default authorize key. DO THIS ONLY ONCE.
You can tell if this is done by looking in your
.ssh
folder. The current default key isid_ed25519
but usingid_rsa
will also work. If you find 2 files, eitherid_ed25519
andid_ed25519.pub
orid_rsa
andid_rsa.pub,
your default keys have been generated. Otherwise, runssh-keygen
Press enter for all prompts and the default keys will be generated in the correct place.ssh-keygen
will warn you it is about to override exiting keys. If it does warn, answer no.