SSH Server and Key Login
I wanted to send commands from other computers to my Windows 10 machine. Upon initial install of Windows, I logged in with my Microsoft account and was met with Permission denied, please try again.
when trying passwords
Install OpenSSH Server
- install the client. Search for
More Options
in the Windows start menu - install
OpenSSH Server
- search for
Services
in the Windows Start menu - right click
Open SSH SSH Server
and hitProperties
- set
Startup type
toautomatic
Setup SSH Keys
- Edit files as Administrator. I use VS Code ran as Administrator to edit these files
- create a file named
administrators_authorized_keys
here →'C:\ProgramData\ssh\administrators_authorized_keys'
- in an admin privileged terminal run
icacls .\administrators_authorized_keys /inheritance:r /grant "Administrators:F" /grant "System:F"
- create an SSH key on your remote computer
- copy the
.ssh/id_rsa.pub
contents to the clipboard - On Windows 10 paste key into
'C:\ProgramData\ssh\administrators_authorized_keys'
sshd_config
file
...
PubkeyAuthentication yes
...
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
PermitEmptyPasswords no
...
in Services
window. Restart OpenSSH SSH Server
Bonus
Now I'm able to turn off my windows machine with an authorized remote computer via
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa UERSNAME@192.168.x.xxx 'rundll32.exe powrprof.dll, SetSuspendState Sleep'
Credits
- SSH To Windows Using Public Key - YouTubehttps://winscp.net/eng/docs/guide_windows_openssh_server
- https://winscp.net/eng/docs/guide_windows_openssh_server