Sulteric
Sulteric

Reputation: 527

Setting up Password Free SSH from Linux to Windows 10

I'm trying to set up a password free ssh path from a linux server to a windows machine. I currently have MobaSSH running on the windows machine. I can ssh from the linux server to the windows machine fine and execute commands just fine but I have to enter a password.

I create a public RSA key on the linux system and using WinSCP I copied the file over to the C:\Users\MyUserName\.ssh folder and restarted the MobaSSh service on the windows machine.

It still won't let me ssh in without a password. What am I missing here? Any help vastly appreciated.

Upvotes: 3

Views: 4579

Answers (1)

bitinerant
bitinerant

Reputation: 1541

OpenSSH is available for Windows 10 and has worked very reliably for me. I can consistently connect from a Linux machine without a password. Here is how to set it up.

  • upgrade to Windows 10 version 1809 or higher

    • check via: powershell -c "(Get-Item 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion').GetValue('ReleaseID')"; see also systeminfo | findstr /B /C:"OS Name" /C:"OS Version" for Pro vs. Home, build number
    • upgrade via Windows Update settings or Download Windows 10 (the latter works around an issue where some systems are stuck at 1803)
  • install SSH client and server (as administrator; source) - in Windows PowerShell:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd  # remote login should be possible following this command
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name *ssh*  # there should be a firewall rule named "OpenSSH-Server-In-TCP"  # optional
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0  # optional
  • enabling public key login for administrators (source) - from Linux command-line:
scp ~/.ssh/id_rsa.pub administrator@remote_computer_name:'C:\ProgramData\ssh\administrators_authorized_keys'  # if using an alternate method, ensure file is not UTF-16 encoded
icacls C:\ProgramData\ssh\administrators_authorized_keys /remove "NT AUTHORITY\Authenticated Users"
icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r
get-acl C:\ProgramData\ssh\ssh_host_dsa_key | set-acl C:\ProgramData\ssh\administrators_authorized_keys
  • enabling public key login for non-administrators - in Windows PowerShell:
Install-Module -Force OpenSSHUtils -Scope AllUsers  # for: Repair-AuthorizedKeyPermission
cd C:\Users\...
ssh-keygen  # create ~/.ssh
# add key(s) to ~/.ssh/authorized_keys
$ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission -FilePath .ssh\authorized_keys
# if above fails, try ''%%Set-ExecutionPolicy Unrestricted -Scope CurrentUser%%''; see also https://github.com/PowerShell/Win32-OpenSSH/issues/1245#issuecomment-440388604

Upvotes: 3

Related Questions