How to activate and configure ssh server in windows 10
Open Power shell with administrator elevation, and run the following to install it:
Add-WindowsCapability -Online -Name OpenSSH.Server*
Then we start the service:
Start-Service sshd
We specify that it starts automatically on each reboot of the operating system running:
Set-Service -Name sshd -StartupType 'Automatic'
And now we generate the keys of all users running:
Get-ChildItem $env:ProgramData\ssh\ssh_host_*_key | ForEach-Object { . $env:WINDIR\System32\OpenSSH\ssh-keygen.exe -l -f $_ }
This command will create the id_rsa_username and id_rsa_username.pub files in each .ssh folder of the operating system users:
PS C:\Users\user1> Get-ChildItem $env:ProgramData\ssh\ssh_host_*_key | ForEach-Object { . $env:WINDIR\System32\OpenSSH\ssh-keygen.exe -l -f $_ }
1024 SHA256:nEQ9U2pw4eKAfEr5BemBKt2Q7Mtp6/4BjxdMB9uBIms nt authority\system@pc1 (DSA)
256 SHA256:29lH+JeQAQvayYWLSeKDSM6taGeQBPl5FVPkG5jcSQI nt authority\system@pc1 (ECDSA)
256 SHA256:XgbLIvx/Rtfy3RW0geFE+6iuaQz1Dfnk4CP0iE7uIW4 nt authority\system@pc1 (ED25519)
3072 SHA256:DIoHAE+0GDdiaMBzwbiepfKePXd0xDwbw0zUimb/x/U nt authority\system@apc1 (RSA)
PS C:\Users\user1> history
Id CommandLine
-- -----------
1 echo %programdata%
2 Get-ChildItem $env:ProgramData\ssh\ssh_host_*_key | ForEach-Object { . $env:WINDIR\System32\OpenSSH\ssh-keygen.exe -l -f $_ }
PS C:\Users\user1>
Although installing the ssh server in the first step informs that it does not require a restart, you must surely restart for the new service to appear in the list of Windows services with the name "OpenSSH SSH Server".
In the default installation the port of the SSH Server is 443, probably because in some versions of Windows 10 port 22 is already in use in development tools. To change it we open with administration elevation the file C:ProgramDatasshsshd_config, and we comment on the line that appears with 'Port 443' putting a # in front, and we uncomment the line '#Port 22' removing the # to leave the usual connection port by ssh. We save and restart the "OpenSSH SSH Server" service.
Now it remains only to allow port 22 on the firewall running in Power shell:
New-NetFirewallRule -Name 'ssh' -DisplayName 'ssh' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
And with this you already have access to Windows 10 by ssh.