DEV Community

shiva kumar
shiva kumar

Posted on

SSHing from Ubuntu to windows

Recently I was trying to access windows server 2016 from ubuntu 20.04 without password. Best way to do that using shh but windows server 2016 doesn't come with ssh installed. Download the OpenSSH-Win64.zip
Download

Extract the file in C:\Program Files\, after that open sshd_Config_default with notepad and uncomment the line port 22. Shh connect the remote machine in port 22.

uncomment port 22

Now open powershell and run the following commands

powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

Allow inbound for ssh on port 22
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Start sshd, this will also create host key in C:\ProgramData\ssh

net start sshd

Check if the service is running

Get-Service -Name ssh-agent,sshd

service running

From your powershell create a new file
New-Item -ItemType file "C:\ProgramData\ssh\administrators_authorized_keys"

Copy the public key from client ubuntu machine and append it to adminstrators_athorized_keys file. Creating a public key can be done using ssh-keygen in Ubuntu

Restart the service using the command in powershell

Restart-Service -Name sshd, ssh-agent -Force

ssh Administrator@windows-ip-address
Now from ubuntu machine you can successfully ssh to windows machine.

Hope this helps. Follow me for quick tips and solution for daily challenges

Reference:
OpenSSH Key management
Win32-OpenSSH

Top comments (0)