How to Connect to Windows Server from Linux Using SSH Windows 10

How to Connect to Windows Server from Linux Using SSH Windows 10?

Secure Shell (SSH) is a widely used protocol for securely accessing remote servers, commonly employed on Linux systems. However, SSH can also be used to connect to a Windows server, particularly if you’re running Windows 10 or Windows Server 2019 and later, which come with built-in OpenSSH support. This guide explains how to connect to Windows Server from Linux using SSH Windows 10.

Prerequisites

Before starting, ensure you have the following:

  1. Windows Server Configuration
    • The Windows server must have the OpenSSH Server feature installed and running.
    • Administrative access to enable and configure the OpenSSH server.
  2. Linux System Configuration
    • A Linux system with an SSH client installed. Most Linux distributions come with OpenSSH by default.
  3. Network Access
    • A network connection between the Linux machine and the Windows server. Ensure firewalls or security settings allow SSH traffic (port 22 by default).

How to Connect to Windows Server from Linux Using SSH Windows 10 Step-by-Step Guide

Step 1: Install and Configure OpenSSH on the Windows Server

1.1 Check for OpenSSH Installation

On the Windows server:

  • Open the Settings app.
  • Navigate to Apps > Optional Features.
  • Scroll down to check if the OpenSSH Server feature is listed. If it is not installed, follow the next step.

1.2 Install OpenSSH Server

  1. Open PowerShell as an administrator.
  2. Run the following command to install OpenSSH Server:
    powershell
    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  3. Once installed, verify the installation:
    powershell
    Get-Service sshd

1.3 Start and Configure the OpenSSH Service

  1. Start the OpenSSH service:
    powershell
    Start-Service sshd
  2. Configure the service to start automatically:
    powershell
    Set-Service -Name sshd -StartupType Automatic

1.4 Allow SSH Through the Windows Firewall

  1. Open PowerShell as an administrator.
  2. Run the following command to allow SSH traffic:
    powershell
    New-NetFirewallRule -Name sshd -DisplayName "OpenSSH Server Port" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Step 2: Find the Windows Server’s IP Address

On the Windows server:

  1. Open a Command Prompt or PowerShell window.
  2. Run the following command to find the server’s IP address:
    cmd
    ipconfig
  3. Note the IPv4 address under the active network adapter.

Step 3: Test SSH Connection from Linux

3.1 Open the Terminal on Linux

Launch the terminal on your Linux system. SSH commands are run from the terminal.

3.2 Use the SSH Command

Run the following command to initiate an SSH connection to the Windows server:

bash
ssh username@windows_server_ip
  • Replace username with the user account on the Windows server.
  • Replace windows_server_ip with the server’s IP address.

3.3 Accept the SSH Key

The first time you connect, SSH will ask to confirm the server’s fingerprint. Type yes and press Enter.

3.4 Enter the Password

Provide the password for the specified Windows account. Upon successful authentication, you’ll be connected to the Windows server.

Step 4: Troubleshooting Common Issues

4.1 Firewall or Network Issues

  • Ensure port 22 is open on the Windows server firewall.
  • Verify that there are no network restrictions or additional firewalls blocking SSH traffic.

4.2 Incorrect Username or Password

  • Double-check the username and password. The username must exist on the Windows server.

4.3 SSH Service Not Running

  • Verify that the OpenSSH service is running on the Windows server:
    powershell
    Get-Service sshd

4.4 Key-Based Authentication Issues

  • If using SSH keys, ensure the public key is added to the authorized_keys file on the Windows server. The default location is:
    makefile
    C:\ProgramData\ssh\administrators_authorized_keys

Step 5: Set Up Key-Based Authentication (Optional)

For enhanced security, configure SSH to use key-based authentication instead of passwords.

5.1 Generate SSH Keys on Linux

  1. Open the terminal and run:
    bash
    ssh-keygen -t rsa -b 2048
  2. Save the key pair in the default location (usually ~/.ssh/id_rsa) and set a passphrase.

5.2 Copy the Public Key to the Windows Server

Use the ssh-copy-id command to copy the public key to the Windows server:

bash
ssh-copy-id username@windows_server_ip

Alternatively, manually add the contents of the public key file (~/.ssh/id_rsa.pub) to the authorized_keys file on the Windows server.

5.3 Test Key-Based Authentication

Connect to the server without a password:

bash
ssh username@windows_server_ip

Step 6: Automate Tasks with SSH

Once connected, you can use SSH to execute commands on the Windows server, transfer files, or manage the server remotely. Here are a few examples:

6.1 Execute Commands

Run a command directly from Linux:

bash
ssh username@windows_server_ip "dir C:\Users"

6.2 Transfer Files

Use scp to transfer files between your Linux system and the Windows server:

bash
scp file.txt username@windows_server_ip:C:\

Security Tips for SSH

  1. Use Strong Passwords
    Avoid using weak passwords to reduce the risk of unauthorized access.
  2. Restrict Access
    Limit SSH access to specific IP addresses using firewall rules.
  3. Disable Password Authentication
    Once key-based authentication is set up, disable password authentication in the OpenSSH configuration file (sshd_config).
  4. Monitor Logs
    Regularly review the SSH logs on the Windows server for unauthorized access attempts.

Conclusion

Connecting to a Windows server from a Linux system using SSH on Windows 10 is a straightforward process, thanks to the built-in OpenSSH support in modern Windows versions. By following the steps outlined in this guide, you can establish a secure and efficient connection for remote server management. With the added security of key-based authentication and proper configuration, you can ensure a robust and reliable setup for your SSH needs.

Scroll to Top