Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Created July 5, 2024 11:23
Show Gist options
  • Save gilangvperdana/2f888242a7aad32571b47a4598a037d4 to your computer and use it in GitHub Desktop.
Save gilangvperdana/2f888242a7aad32571b47a4598a037d4 to your computer and use it in GitHub Desktop.
Fix OpenSSH Denied with Pubkey on Windows Server

General

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

Create authorized_keys

cd C:\Users\Administrator\.ssh
ssh-keygen
type id_rsa.pub > authorized_keys

Change the permission

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;

Change some paramaters on sshd_config

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

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment