Loading date…
LinkedIn Twitter Instagram YouTube WhatsApp

How to Install and Host SSH Server on Windows Using Batch Script (Complete 2026 Guide)

Read full practical guide on How to Install and Host SSH Server on Windows Using Batch Script (Complete 2026 Guide)

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?

Read full practical guide on 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?

Read full practical guide on 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

Read full practical guide on 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?

Read full practical guide on How the Script Works for SSH?

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

Read full practical guide on Step-by-Step Installation Guide for SSH
  1. Open Notepad
  2. Paste the batch script
  3. Save the file as ssh_setup.bat
  4. Right-click and select Run as Administrator
  5. Wait for installation to complete
  6. 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?

Read full practical guide on 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?

Read full practical guide on 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

Read full practical guide on Security Best Practices for SSH

Running an SSH server without security measures can expose your system. Follow these best practices:

Security Measure Benefit
Change SSH Port Reduces brute-force attacks
Key Authentication Stronger than passwords
Firewall Rules Restricts unauthorized access

Troubleshooting Common Issues

Read full practical guide on Troubleshooting Common Issues for SSH
  • 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.

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.

Shubham Chaudhary

Welcome to Xpert4Cyber! I’m a passionate Cyber Security Expert and Ethical Hacker dedicated to empowering individuals, students, and professionals through practical knowledge in cybersecurity, ethical hacking, and digital forensics. With years of hands-on experience in penetration testing, malware analysis, threat hunting, and incident response, I created this platform to simplify complex cyber concepts and make security education accessible. Xpert4Cyber is built on the belief that cyber awareness and technical skills are key to protecting today’s digital world. Whether you’re exploring vulnerability assessments, learning mobile or computer forensics, working on bug bounty challenges, or just starting your cyber journey, this blog provides insights, tools, projects, and guidance. From secure coding to cyber law, from Linux hardening to cloud and IoT security, we cover everything real, relevant, and research-backed. Join the mission to defend, educate, and inspire in cyberspace.

Post a Comment

Previous Post Next Post
×

🤖 Welcome to Xpert4Cyber

Xpert4Cyber shares cybersecurity tutorials, ethical hacking guides, tools, and projects for learners and professionals to explore and grow in the field of cyber defense.

🔒 Join Our Cybersecurity Community on WhatsApp

Get exclusive alerts, tools, and guides from Xpert4Cyber.

Join Now