Have you ever wanted to change SSH authentication on your Windows server with a public key and it failed after setting it? let's follow this step
cd C:\Users\Administrator\.ssh
ssh-keygen
type id_rsa.pub > authorized_keys
icacls authorized_keys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
or we can try manual with
- Right click authorized_keys, go to Properties -> Security -> Advanced
- Click
Disable inheritance
; - Choose
Convert inherited permissions into explicit permissions on this object
when prompted;
cd %programdata%
cd ssh
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPassword no
Then disable the authorized default keys on sshd_config
# Match Group administrators
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys