Who knew Windows had SSH built in... and to think, I'd just been leaving a WSL window open with sshd running on it...
- If you did not enable automatic startup of SSH services, enable them:
Start-Service 'sshd'
Start-Service 'ssh-agent'Make sure you ran Powershell as administrator!
- Don't forget to forward port 22 in the router settings!
Since CMD is hot garbage, run the following to get into Git Bash:
"%SYSTEMDRIVE%\Program Files\Git\bin\sh.exe" --loginOr, tack it into the ssh command:
$ ssh Matthew@192.168.2.83 -t '"%SYSTEMDRIVE%\Program Files\Git\bin\sh.exe" --login'- Go into Windows Settings and enable the OpenSSH server (guide/overview)
Add-WindowsCapability -Online -Name OpenSSH.Server* New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22If desired:
Set-Service -Name 'sshd' -StartupType 'Automatic' Set-Service -Name 'ssh-agent' -StartupType 'Automatic'
- Add laptop's
id_rsa.pubto~/.ssh/authorized_keys - Follow this guide for setting up OpenSSH authentication with public key instead of password:
Server setup continued (non-elevated powershell):
- Log in as a user, for which public key auth to be used
cd $env:USERPROFILE; mkdir .ssh; cd .ssh; New-Item authorized_keys;- Paste the contents of the
id_rsa.pubfile from the client to the.ssh\authorized_keysfile from the previous step.- Setup permissions properly (important!!!):
- Run
start .to open explorer with the current folder ($env:USERPROFILE\.ssh);- Right click
authorized_keys, go toProperties -> Security -> Advanced- Click "Disable inheritance";
- Choose "Convert inherited permissions into explicit permissions on this object" when prompted;
- (really, really important) Remove all permissions on file except for the
SYSTEMand yourself. There must be exactly two permission entries on the file. Some guides suggest running theRepair-AuthorizedKeyPermission $env:USERPROFILE\.ssh\authorized_keys- this will try to add thesshduser to the permission list and it will break the authentication, so, don't do that, or at least do not agree on adding thesshduser). BothSYSTEMand yourself should have full control over the file.- If your Windows build is 1809 or later, it is required to comment out the following lines in
C:\ProgramData\ssh\sshd_configfile. Then restart thesshdservice.# Match Group administrators # AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
(copied 2021-12-14)