How to Install and Host SSH Server on Windows Using Batch Script (Complete 2026 Guide)
Imagine controlling your Windows system remotely with full command-line access, securely and efficiently, just like a professional cybersecurity expert. That’s exactly what an SSH server allows you to do. While SSH is commonly associated with Linux systems, modern Windows systems now support OpenSSH natively, making it easier than ever to deploy secure remote access.
In this complete guide, you will learn how to install and host an SSH server on a Windows system using a simple batch script. This method is ideal for beginners, system administrators, and cybersecurity professionals who want automation, speed, and reliability.
Table of Contents
- What is SSH?
- Why Use SSH on Windows?
- System Requirements
- Batch Script for SSH Setup
- How the Script Works
- Step-by-Step Installation Guide
- How to Connect to SSH Server
- How to Stop SSH Service
- Security Best Practices
- Troubleshooting
- Frequently Asked Questions
- Related Posts
What is SSH?
SSH (Secure Shell) is a cryptographic network protocol used to securely access and manage remote systems over an unsecured network. It encrypts communication between the client and server, ensuring data confidentiality and integrity.
SSH is widely used in cybersecurity, system administration, penetration testing, and remote server management.
Why Use SSH on Windows?
Traditionally, Windows relied on RDP (Remote Desktop Protocol), but SSH provides a lightweight and secure alternative.
- Secure remote access with encryption
- Low bandwidth usage
- Command-line control for automation
- Cross-platform compatibility
- Ideal for developers and ethical hackers
System Requirements
- Windows 10 or Windows 11
- Administrator privileges
- Internet connection (for initial setup)
- Basic knowledge of Command Prompt
Batch Script for SSH Server Setup
Below is the complete batch script to install and configure an SSH server automatically:
@echo off
title SSH Server Setup on Windows
echo Installing OpenSSH Server...
:: Install OpenSSH Server if not installed
powershell -Command "Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' | Select-Object -ExpandProperty State" | findstr "NotPresent" > nul
if %errorlevel%==0 (
powershell -Command "Add-WindowsCapability -Online -Name 'OpenSSH.Server~~~~0.0.1.0'"
)
:: Start SSH service
sc config sshd start=auto
net start sshd
:: Allow SSH through Windows Firewall (port 22)
netsh advfirewall firewall add rule name="OpenSSH" dir=in action=allow protocol=TCP localport=22
:: Get server IP address
for /f "tokens=2 delims=:" %%A in ('ipconfig ^| findstr /R "IPv4.*"') do set "IP=%%A"
set IP=%IP:~1%
:: Get current username
set USERNAME=%USERNAME%
:: Check password status
powershell -Command "$pass = Get-LocalUser -Name $env:USERNAME | Select-Object -ExpandProperty PasswordLastSet; If ($pass -eq $null) {Write-Output 'No Password Set'} Else {Write-Output 'Password Set'}" > password_status.txt
set /p PASSWORD=<password_status.txt
del password_status.txt
:: Save details to file
echo SSH Server Details: > ssh_details.txt
echo -------------------- >> ssh_details.txt
echo IP Address: %IP% >> ssh_details.txt
echo Username: %USERNAME% >> ssh_details.txt
echo Password: %PASSWORD% >> ssh_details.txt
echo Installation complete! Check "ssh_details.txt" for login details.
pause
How the Script Works?
This script automates the entire SSH server setup process:
- Checks if OpenSSH Server is installed
- Installs it if missing
- Starts and enables the SSH service
- Opens port 22 in Windows Firewall
- Fetches system IP and username
- Saves login details in a text file
This is extremely useful for quick deployment in labs, penetration testing environments, and remote management setups.
Step-by-Step Installation Guide
- Open Notepad
- Paste the batch script
- Save the file as ssh_setup.bat
- Right-click and select Run as Administrator
- Wait for installation to complete
- Open ssh_details.txt to get login details
Once completed, your SSH server will be live and ready to accept connections.
How to Connect to SSH Server?
You can connect using:
Using Command Prompt
ssh username@IP_ADDRESS
Using PuTTY
- Enter IP address
- Select port 22
- Click Open
This allows secure remote access from any system.
How to Stop SSH Service on Windows?
If you want to stop or disable the SSH server, use the following commands:
Stop SSH Service
net stop sshd
Disable Auto Start
sc config sshd start=disabled
Remove Firewall Rule (Optional)
netsh advfirewall firewall delete rule name="OpenSSH"
These commands help you fully control your SSH server lifecycle.
Security Best Practices
Running an SSH server without security measures can expose your system. Follow these best practices:
- Change default port from 22
- Use strong passwords
- Enable key-based authentication
- Disable root or admin login
- Use firewall restrictions
- Monitor login attempts
| Security Measure | Benefit |
|---|---|
| Change SSH Port | Reduces brute-force attacks |
| Key Authentication | Stronger than passwords |
| Firewall Rules | Restricts unauthorized access |
Troubleshooting Common Issues
- SSH not starting → Run as Administrator
- Connection refused → Check firewall settings
- Wrong IP → Verify using ipconfig
- Login failed → Ensure password is set
Always verify logs using Event Viewer if issues persist.
Related Cybersecurity Guides
- How to Change SSH Server Default Port on Windows (Step-by-Step Secure Method 2026)
- How to Install SSH Server on Windows Using PowerShell (Step-by-Step 2026 Guide)
- What is SSH and How It Works? Full Guide with Servers, Clients & Top Tools
- EvilWAF Explained: Complete Guide to WAF Bypass, Features, Installation & Usage (2026)
- WiFi Explained Simply: How It Works, Security Risks and Hidden Dangers (2026 Guide)
- FTP Explained Simply: Complete Guide to FTP Server, Clients & Top Tools (2026)
Frequently Asked Questions
Is SSH safe on Windows?
Yes, SSH is highly secure when configured properly with encryption and authentication methods.
Can I use SSH without a password?
Yes, using SSH keys is recommended for better security.
What port does SSH use?
By default, SSH uses port 22.
Can I access SSH over the internet?
Yes, by configuring port forwarding on your router.
Does Windows support SSH natively?
Yes, modern Windows versions include OpenSSH as an optional feature.
Conclusion
Setting up an SSH server on Windows is no longer complex. With a simple batch script, you can automate the entire process and deploy a secure remote access system within minutes. Whether you are a cybersecurity professional, developer, or system administrator, mastering SSH on Windows gives you powerful control over your systems.
By following this guide, you now have the ability to install, host, manage, and stop an SSH server confidently. Focus on security best practices to ensure your system remains protected while enjoying the flexibility of remote access.
.png)








