In the evolving landscape of IT management, secure and efficient remote access to your servers is critical. With Windows Server 2022, you can enable SSH (Secure Shell) for secure command-line access, facilitating better automation and management. I wanted to try this out recently, to see if it would work with Visual Studio Code’s Remote Development Extension. I won’t cover that in this post, since I’m still experimenting with it at the time I’m writing this.
This guide will walk you through the process of enabling and configuring the SSH server on your Windows Server 2022.
Why Use SSH on Windows Server? Link to heading
SSH provides a secure channel over an unsecured network, allowing encrypted communication and secure login from a remote computer. It’s widely used for remote management and automation, offering numerous benefits:
- Security: Encrypted connections protect data integrity and confidentiality.
- Automation: Easily script and automate administrative tasks.
- Compatibility: Standardized protocol compatible with many tools and platforms.
Step-by-Step Guide to Enable SSH on Windows Server 2022 Link to heading
If you are looking for a fully automated method, see Configuring SSH Access on Windows Server 2022 Using PowerShell.
Step 1: Install OpenSSH Server Link to heading
-
Open Windows Settings:
- Press
Win + I
to open the Settings app.
- Press
-
Navigate to Apps:
- Go to
Apps
>Optional Features
.
- Go to
-
Add a Feature:
- Click on
Add a feature
.
- Click on
-
Install OpenSSH Server:
- In the search box, type “OpenSSH Server” and select it.
- Click
Install
.
Step 2: Start and Configure the SSH Service Link to heading
-
Open PowerShell as Administrator:
- Right-click on the Start button and select
Windows PowerShell (Admin)
.
- Right-click on the Start button and select
-
Start the SSH Service:
Start-Service sshd
- Set SSH to Start Automatically:
Set-Service -Name sshd -StartupType 'Automatic'
-
Confirm the Firewall Rule: Ensure that the firewall allows SSH traffic.
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Step 3: Verify SSH Configuration Link to heading
-
Check the SSH Service Status:
Get-Service -Name sshd
-
Connect via SSH: From a remote machine, use an SSH client (e.g., PuTTY, OpenSSH) to connect to the Windows Server using its IP address:
ssh username@your_server_ip
Replace
username
with your Windows account username andyour_server_ip
with your server’s IP address.
Additional Configuration Link to heading
Configuring SSH Key-Based Authentication Link to heading
-
Generate SSH Keys: On your client machine, generate a key pair:
ssh-keygen
-
Copy the Public Key to the Server: Use the following command to copy your public key to the server:
ssh-copy-id username@your_server_ip
-
Edit SSH Configuration (Optional): You may want to edit the SSH configuration file (
sshd_config
) for advanced settings. This file is typically located inC:\ProgramData\ssh\
.Example to disable password authentication:
PasswordAuthentication no
Conclusion Link to heading
Enabling SSH on Windows Server 2022 enhances your ability to manage and automate tasks securely and efficiently. With SSH, you can leverage the power of remote command-line access, improving your administrative capabilities and streamlining operations.
Emmanuel Tsouris is a Systems Development Manager working in the cloud, with extensive experience in cloud platforms, enterprise management, and automation. In his spare time, he enjoys hiking, biking, cooking, photography, and writing. For more insights and tips, visit emmanueltsouris.com.