Disclaimer: ChatGPT generated document
On Windows 11, SSH (Secure Shell) works out of the box because Microsoft includes both an SSH client and an SSH server in the operating system. Here’s an overview of how SSH works on Windows 11, how to use it, and how to configure it:
- The OpenSSH client is installed by default.
- It allows you to connect to remote systems via SSH from a command prompt or PowerShell.
- The OpenSSH server is available but not enabled by default.
- It allows your Windows 11 machine to accept incoming SSH connections.
You can use the SSH client from the Command Prompt or PowerShell.
-
Connect to a remote server:
ssh username@hostname
Replace
username
with the remote system’s user andhostname
with its IP address or domain name. -
Specify a custom port:
ssh username@hostname -p 2222
-
Copy files using SCP (Secure Copy Protocol):
scp localfile.txt username@hostname:/remote/path/
-
Copy files from remote to local:
scp username@hostname:/remote/path/remote_file.txt ./local_path/
-
You can configure SSH connections in the
~/.ssh/config
file. For example:
Host myserver HostName 192.168.1.100 User myusername Port 22
This allows you to connect with a simple:
ssh myserver
To allow your Windows 11 machine to accept incoming SSH connections:
-
Open Settings
:
- Go to Settings → Apps → Optional Features.
-
Install OpenSSH Server
:
- Search for "OpenSSH Server" in the list of optional features.
- If it’s not installed, click Add a feature, search for "OpenSSH Server," and install it.
-
Enable the SSH Server Service
:
- Open Services (search
services.msc
in the Start Menu). - Find OpenSSH SSH Server in the list.
- Right-click → Properties → Set Startup type to
Automatic
. - Click Start to run the service.
- Open Services (search
Make sure the Windows Firewall allows SSH connections:
- Open Windows Defender Firewall with Advanced Security.
- Click on Inbound Rules → New Rule.
- Choose Port and enter
22
(default SSH port). - Allow the connection and save the rule.
From another machine, test the connection using:
ssh username@your_windows_ip
If successful, you’ll get a shell on your Windows machine.
SSH uses public and private key pairs for secure authentication.
-
Open PowerShell and run:
ssh-keygen
-
Save the key in the default location (
~/.ssh/id_rsa
). -
Copy the public key to the remote server:
ssh-copy-id username@hostname
After the public key is copied, you can connect without entering a password:
ssh username@hostname
-
Changing the SSH Server Port:
-
Edit the SSH server configuration file:
C:\ProgramData\ssh\sshd_config
. -
Change the
Port
directive to a new value (e.g.,Port 2222
). -
Restart the SSH server:
net stop sshd net start sshd
-
-
Enabling Key-Based Authentication:
-
Add public keys to
C:\Users\<YourUsername>\.ssh\authorized_keys
. -
Disable password authentication in
sshd_config
by setting:
PasswordAuthentication no
-
-
Configuring SSH Tunnels: Forward ports through SSH to access remote services securely:
ssh -L local_port:remote_host:remote_port username@hostname
Example:
ssh -L 8080:localhost:80 username@hostname
-
Firewall Blocking Connections: Ensure port
22
(or the custom port) is open in the firewall. -
Permission Issues with
.ssh
Folder: Ensure the.ssh
folder and its files have the correct permissions:icacls C:\Users\<YourUsername>\.ssh /inheritance:r /grant:r <YourUsername>:F
-
Service Not Starting: Check the
sshd
logs inC:\ProgramData\ssh\logs
for errors.
Feature | Windows 11 | Linux |
---|---|---|
SSH Client Pre-installed | Yes | Yes |
SSH Server Pre-installed | No (optional feature) | Yes (most distros) |
Key Management | Same as Linux | Same |
Configuration File Location | C:\ProgramData\ssh\sshd_config |
/etc/ssh/sshd_config |
Logs | C:\ProgramData\ssh\logs |
/var/log/auth.log (Ubuntu) |