In this guide, you will learn How To SSH into a Windows Machine.
OpenSSH is a connectivity tool for remote sign-in that uses the SSH protocol. It encrypts all traffic between client and server to eliminate eavesdropping, connection hijacking, and other attacks.
An OpenSSH-compatible client can be used to connect to Windows Server and Windows Client devices.
Steps To SSH into a Windows Machine
In this article, we’ll show you how to configure OpenSSH on Windows, and connect to it using Putty or any other SSH client.
How To Enable SSH on Windows
If you are using a Windows 10 machine, you need to be sure that your build of Windows 10 is 1809 or newer. To do this, you can run the command below:
Note: If you have an older Windows 10 build installed, you can update it through Windows Update
Then, run the command below from your PowerShell to enable OpenSSH on your system:
Add-WindowsCapability -Online -Name OpenSSH.Server*
Verify your OpenSSH status by running the following PowerShell command:
Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Server*'
Configure SSH on Windows
At this point, you need to check the status of ssh-agent and sshd services from your PowerShell:
Get-Service -Name *ssh*
In my case, both services are in a Stopped state and not added to the automatic startup list. To start SSH services and configure autostart for them on your Windows machine, run the following commands:
# Start-Service sshd # Set-Service -Name sshd -StartupType 'Automatic' # Start-Service ‘ssh-agent’ # Set-Service -Name ‘ssh-agent’ -StartupType 'Automatic'
Configure Firewall For SSH
At this point, you need to allow incoming connections to TCP port 22 in the Windows Defender Firewall.
To do this, you can add a firewall rule to allow SSH traffic using PowerShell on your Windows machine:
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Now you can start to connect to your Windows.
Connect From Linux
At this point, you can connect to Windows using any SSH client. To connect from Linux, use the command below:
ssh -p 22 admin@IP-address-of-your-windows-machine
Here, the admin is a local Windows user under which you want to connect.
After that, a new Windows command prompt window will open in an SSH session.
Generate SSH Keys on your Windows Machine
If you want to use key-based ssh authentication instead of password authentication, you need to generate a key using ssh-keygen on your client.
Then, the contents of the id_rsa.pub file must be copied to the c:\users\admin\.ssh\authorized_keys file in Windows 10.
You can configure various OpenSSH server settings in Windows using the %programdata%\ssh\sshd_config configuration file.
For example, you can disable password authentication and leave only SSH key-based auth on your Windows machine with:
PubkeyAuthentication yes PasswordAuthentication no
Here you can also specify a new TCP port (instead of the default TCP 22 port) on which the SSHD will accept connections. For example:
After making changes to the sshd_config file, you need to restart the sshd service:
Get-Service sshd | Restart-Service –force
After that, you can connect from your Linux client to Windows without a password. Use the command:
ssh -l admin@IP-address-of-your-windows-machine
At this point, you have learned to SSH into a Windows Machine and enable PubkeyAuthentication to connect to your system without a password.
Hope you enjoy it.
You may be like these articles: