Skip to content

Instantly share code, notes, and snippets.

@MangaD
Created February 9, 2025 18:20
Show Gist options
  • Save MangaD/91b93e34b2d9dce25f63d6590957ae87 to your computer and use it in GitHub Desktop.
Save MangaD/91b93e34b2d9dce25f63d6590957ae87 to your computer and use it in GitHub Desktop.
OpenSSH

OpenSSH

CC0

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:


1. Pre-installed SSH Components

a. OpenSSH Client

  • The OpenSSH client is installed by default.
  • It allows you to connect to remote systems via SSH from a command prompt or PowerShell.

b. OpenSSH Server

  • The OpenSSH server is available but not enabled by default.
  • It allows your Windows 11 machine to accept incoming SSH connections.

2. Using the SSH Client

You can use the SSH client from the Command Prompt or PowerShell.

Basic SSH Commands

  • Connect to a remote server:

    ssh username@hostname

    Replace username with the remote system’s user and hostname 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/

Configuration Files

  • 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

3. Setting Up the SSH Server

To allow your Windows 11 machine to accept incoming SSH connections:

a. Install and Enable OpenSSH Server

  1. Open Settings

    :

    • Go to SettingsAppsOptional Features.
  2. 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.
  3. 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.

b. Firewall Configuration

Make sure the Windows Firewall allows SSH connections:

  1. Open Windows Defender Firewall with Advanced Security.
  2. Click on Inbound RulesNew Rule.
  3. Choose Port and enter 22 (default SSH port).
  4. Allow the connection and save the rule.

4. Testing SSH Server

From another machine, test the connection using:

ssh username@your_windows_ip

If successful, you’ll get a shell on your Windows machine.


5. Key Management

SSH uses public and private key pairs for secure authentication.

Generating SSH Keys:

  1. Open PowerShell and run:

    ssh-keygen
  2. Save the key in the default location (~/.ssh/id_rsa).

  3. Copy the public key to the remote server:

    ssh-copy-id username@hostname

Using SSH Keys:

After the public key is copied, you can connect without entering a password:

ssh username@hostname

6. Advanced SSH Configurations

  • Changing the SSH Server Port:

    1. Edit the SSH server configuration file: C:\ProgramData\ssh\sshd_config.

    2. Change the Port directive to a new value (e.g., Port 2222).

    3. Restart the SSH server:

      net stop sshd
      net start sshd
  • Enabling Key-Based Authentication:

    1. Add public keys to C:\Users\<YourUsername>\.ssh\authorized_keys.

    2. 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

7. Common SSH Issues on Windows 11

  • 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 in C:\ProgramData\ssh\logs for errors.


8. Comparing SSH on Windows 11 to Linux

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment