Resolving SSH Key Loading Issues on Windows

While SSH is commonly associated with Linux and Unix systems, it can also be configured on Windows. This guide focuses on resolving SSH key loading issues specifically for Windows environments.
Understanding the Challenge
Similar to Linux/Unix, the default SSH configuration on Windows might only load keys authorized by administrators, typically stored in a location like %ProgramData%\ssh\administrators_authorized_keys. This restricts user access unless they are explicitly added to the administrator-authorized keys.
Enabling User-Authorized Keys on Windows
-
Locate the
sshd_configFile: On Windows, thesshd_configfile is usually found inC:\ProgramData\ssh. -
Add User-Authorized Keys Configuration: Append the following line to the
sshd_configfile, ensuring it’s placed below any existingAuthorizedKeysFiledirectives:AuthorizedKeysFile ~/.ssh/authorized_keysThis instructs OpenSSH for Windows to load keys from the
.ssh/authorized_keysfile located in each user’s home directory. -
Disable Administrator-Only Keys: Locate and comment out the following line in the
sshd_configfile:AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keysAdding a
#at the beginning of the line will effectively disable it. -
Restart the SSH Server: After making changes to the
sshd_configfile, restart the SSH server for the modifications to take effect.- Command Prompt:
net stop sshd && net start sshd
- Command Prompt:
-
Create
.sshDirectory: Ensure each user’s home directory contains a.sshsubdirectory. You can create it manually if it doesn’t exist.
- Generate Public-Private Key Pairs: Users should generate their own public-private key pairs using the
ssh-keygencommand (which is included with OpenSSH for Windows). - Add Public Key to
authorized_keys: Users should copy their public key (the content of theid_rsa.pubfile) and add it to their~/.ssh/authorized_keysfile.
By following these steps, you can configure OpenSSH for Windows to allow users to connect securely with their own authorized keys, granting them authorized access to the server.