Accessing Windows 11 via SSH Key: A Step-by-Step Guide


In an increasingly connected world, remote access to machines is more important than ever. For users of Windows 11, the ability to connect via SSH (Secure Shell) not only enhances security but also streamlines workflows, especially for developers and IT professionals. This guide will walk you through the steps to access your Windows 11 machine using SSH keys.

What is SSH?

SSH, or Secure Shell, is a cryptographic network protocol that allows users to securely access remote computers. It replaces older protocols like Telnet, offering encrypted communication and better security. Using SSH keys instead of passwords adds an extra layer of protection, as keys are much harder to crack.

Why Use SSH Keys?

Using SSH keys instead of passwords provides several advantages:

  1. Enhanced Security: SSH keys are more secure than passwords and are less susceptible to brute-force attacks.
  2. Convenience: Once set up, SSH keys eliminate the need to enter a password for each connection.
  3. Automation: SSH keys are essential for automating tasks and scripts that require remote access.

Step-by-Step Guide to Access Windows 11 via SSH Key

Step 1: Enable OpenSSH on Windows 11

First, ensure that the OpenSSH server is enabled on your Windows 11 machine.

  1. Open Settings: Click on the Start menu and select Settings.
  2. Go to Apps: Navigate to Apps > Optional features.
  3. Add a feature: Click on Add a feature at the top.
  4. Install OpenSSH Server: Search for OpenSSH Server, select it, and click Install.

Step 2: Configure OpenSSH Server

Now that OpenSSH is installed, you need to configure it.

  1. Start the SSH server:
    • Open Windows PowerShell as an administrator.
    • Run the following command:
      Start-Service sshd

       

  2. Set the SSH server to start automatically:
    Set-Service -Name sshd -StartupType 'Automatic'

     

Step 3: Create SSH Keys

If you don’t already have an SSH key pair, you’ll need to generate one.

  1. Open a terminal on your client machine (Linux, macOS, or Windows with OpenSSH).
  2. Run the command:

    ssh-keygen

    Follow the prompts to save the key in the default location.

Step 4: Copy the Public Key to Windows 11

You’ll now copy your public key to your Windows machine.

  1. Locate your public key:
    • Find it in the ~/.ssh/id_rsa.pub file (or wherever you saved it).
  2. Add the public key to Windows:
    • On your Windows 11 machine, create the .ssh directory if it doesn’t exist:

      mkdir C:\Users\<YourUsername>\.ssh

    • Open or create the authorized_keys file:

      notepad C:\Users\<YourUsername>\.ssh\authorized_keys

    • Paste your public key into this file and save it.

Step 5: Set Permissions

For security, it’s essential to set the correct permissions for the .ssh directory and the authorized_keys file:

icacls C:\Users\<YourUsername>\.ssh /inheritance:r
icacls C:\Users\<YourUsername>\.ssh /grant <YourUsername>:(F)
icacls C:\Users\<YourUsername>\.ssh\authorized_keys /inheritance:r
icacls C:\Users\<YourUsername>\.ssh\authorized_keys /grant <YourUsername>:(F)

Step 6: Connect via SSH

You’re now ready to connect to your Windows 11 machine using SSH:

ssh <YourUsername>@<Windows11IP>

Replace <YourUsername> with your Windows username and <Windows11IP> with the IP address of your Windows 11 machine.

Troubleshooting Tips

  • Firewall Settings: Ensure that the Windows Firewall allows SSH connections (port 22).
  • Service Status: Check if the OpenSSH server is running:

    Get-Service sshd

#OpenSSH Configuration on Windows (for SSH server)
C:\ProgramData\SSH\sshd_config

# Enable public key authentication
PubkeyAuthentication yes

# Allow password authentication (you may want this as 'yes' to keep password login)
PasswordAuthentication yes

# Specify the file where authorized keys are stored
AuthorizedKeysFile .ssh/authorized_keys

Conclusion

Setting up SSH access on Windows 11 using SSH keys not only enhances your security but also makes remote access more convenient. With this setup, you can streamline your workflows, automate tasks, and manage your systems more efficiently. Whether you’re a developer, an IT professional, or just someone looking to manage your devices remotely, mastering SSH can significantly improve your productivity. Happy connecting!


0% Positive Review (0 Comments)