DEV Community

Udara Dananjaya
Udara Dananjaya

Posted on

Setting Up an SSH Server on Windows with PowerShell

Introduction

Secure Shell (SSH) is a widely used protocol for secure remote access to servers and systems. While SSH is commonly associated with Unix-based systems, you can also enable and configure an SSH server on Windows. In this guide, we'll walk through the process of setting up an SSH server on Windows using PowerShell commands.

Step 1: Check for OpenSSH Capability

First, let's check if your Windows machine already has the OpenSSH capability installed. Open PowerShell and run the following command:

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Enter fullscreen mode Exit fullscreen mode

This command lists the OpenSSH capabilities available on your system.

Step 2: Install OpenSSH Server Capability

If you don't see the OpenSSH.Server capability listed, you can install it with the following command:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Enter fullscreen mode Exit fullscreen mode

This command adds the OpenSSH Server capability to your Windows installation.

Step 3: Start the SSH Server

Next, start the SSH server service with the following command:

Start-Service sshd
Enter fullscreen mode Exit fullscreen mode

This command initiates the SSH server service.

Step 4: Set SSH Server to Start Automatically

To ensure the SSH server starts automatically with Windows, use the following command:

Set-Service -Name sshd -StartupType 'Automatic'
Enter fullscreen mode Exit fullscreen mode

This command configures the SSH server service to start automatically during system boot.

Step 5: Configure the Firewall Rule

To allow SSH traffic through the Windows firewall, create a firewall rule using this command:

New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Enter fullscreen mode Exit fullscreen mode

This command creates a rule named 'sshd' that allows incoming SSH traffic on port 22 (the default SSH port).

Step 6: Verify the Firewall Rule

You can verify that the SSH firewall rule is correctly configured using this command:

Get-NetFirewallRule sshd
Enter fullscreen mode Exit fullscreen mode

This command will display the details of the SSH firewall rule.

Conclusion

Congratulations! You've successfully set up an SSH server on your Windows machine using PowerShell commands. Now you can securely access your Windows system remotely using SSH. This capability can be particularly useful for system administration and remote troubleshooting.

Feel free to explore more SSH-related configurations and use cases to enhance your Windows SSH server setup further.

Happy SSHing!

Top comments (0)