How to configure SSH Key based authentication on Windows | Askme4Tech (2024)

While internally we use ssh for remote connections with password authentication, on external servers it's more secure to use publickey authentication.

Remember that Security is a priority and we must not sacrifice it for any reason.

Today Iwill explain how can configure SSH to use publickey authentication instead of password authentication.

If you have already installed an Open SSH Server andOpen SSH Client then you can continue to read the article. Otherwise please read the articles and come back to continue.

How to generate SSH public/private key pairs

The first step for ssh public key authentication is to generate the public/private keys in the client's PC. The private key must be stored on the windows client's PC in a secure place. The public key must be stored on the OpenSSH Server.

To generate the public/private keys we will use the ssh-keygen command in the windows pc with an OpenSSH client installed.
Hold a minute!!! What type of key should be used? RSA or Ed25519? Which is more secure?

I won't go into deep but after research, I found that the Ed25519 it's more secure. Based on Wikipedia the EdDSA was designed to be faster without sacrificing security. Additionally, this is the recommendation from Microsoft.

So I will generate an Ed25519 key.

  • Open PowerShell as Administrator and type the following command:
    sshd-keygen -t ed25519
  • You can press enter to accept the default values or specify a path where you would like to save the key pairs.
  • For now leave it to the default path.
  • You can type a passphrasealso, and use it like a multi factor authentication. Every time that you will use the key for authentication you will need to type the passphrase.
  • The use if a passphrase depends of your requirements.
  • For now we will not use a passphrase.
  • The keys are generated to the path "C:\users\<username>\.ssh" as you will see.
How to configure SSH Key based authentication on Windows | Askme4Tech (1)

Let's continue with the next step to store the private key in the user pc securely.

How to securely store the private key on the client

Now that we have the private key our first priority is to keep it in safe place. You must remember that the private key is like your password.

To do this we will use the ssh-agent command to securely store the private key.

  • Because the ssh agent service is disabled by default we must revert to Automatic and start the Service.
  • So type the following commands.
    Set-Service ssh-agent -StartupType automatic
    Start-Service ssh-agent
How to configure SSH Key based authentication on Windows | Askme4Tech (2)
  • Now type the followingcommand to store the private key into the ssh agent.
    ssh-add $env:USERPROFILE\.ssh\id_ed25519
How to configure SSH Key based authentication on Windows | Askme4Tech (3)
  • After adding the key to ssh agent keep the private key somewhere safe and deleted from the client PC that will use it for the ssh connection.
  • Remember that the private key can't be retrieved from the ssh agent. If for any reason lose the private key and need touse it on another pc then you must generate a new key pair.

How to copy public key to the OpenSSH Server

Public key must be saved on the OpenSSH Server in a specific location depends of the user type.

If the user is a Standard user then the public key must be saved into C:\users\<username>\.ssh in text file with the name authorized_keys.

If the user is an Administrator the the public key must be saved in C:\ProgramData\sshin text file asadministrators_authorized_keys.

Let's try to do a test with both user types.

First ,Iwill try with the administrator account

  • Copy/Paste the Public key in the path C:\ProgramData\ssh" and rename the public key toadministrators_authorized_keys.
  • Don't forget to delete the extension.pub
How to configure SSH Key based authentication on Windows | Askme4Tech (4)
  • Right click and select Properties.
  • Go in the Tab Security and verify that in the publik key has accessonly the Administrators Group and the SYSTEM user. Any other user must be deleted.
  • Or you can run the following command to give the appropriate access.
    icacls.exe ""$env:ProgramData\ssh\administrators_authorized_keys"" /inheritance:r /grant ""Administrators:F"" /grant ""SYSTEM:F""

If you want to to connect remotely with a standard user instead of an administrator then the only step that need to do is the following:

  • Copy/Paste the Public key in the path C:\users\<username>\ssh"
  • Rename the public key toauthorized_keys
  • Delete the extension .pub.

How to enable Public Key Authentication on the OpenSSH Server

By default the Public Key Authentication it's not enabled on the OpenSSH Server.

To enable the Public Key Authentication you must edit the sshd_config file which located in C:\Programdata\ssh and change from no to yes the line with the PubKey Authentication.

Don't forget to disable the Password authenticationwhile changingthe value from Yes to No.

After the changes, save the file and restart the OpenSSH Server to take the changes.

How to configure SSH Key based authentication on Windows | Askme4Tech (5)

How to connect remotely with the SSH

Now that we have configure everything we can proceed to connect remotely from the client.

  • Open the Powershell and type the following command
    ssh <username>@<ipaddress>
  • Only the first time you must type yes to add the fingerprint of the SSH Key in the trusted list.
How to configure SSH Key based authentication on Windows | Askme4Tech (6)

How to check Event Logs for SSH Connections

If you want to check the Event Logs to verify the connection or troubleshoot any issue, you can open the Event Logs -- Application and Services Logs -- OpenSSH.

Click on Informational and you will find all the logs that you need.

How to configure SSH Key based authentication on Windows | Askme4Tech (7)

That's it!!!

I hope to learn something valuable or help you to resolve an issue.

I invite you to follow me onTwitterorFacebook. If you have any questions, send me an email atinfo@askme4tech.com

As someone deeply entrenched in the realm of cybersecurity and system administration, I understand the critical importance of secure communication protocols, particularly when it comes to remote connections. The use of SSH (Secure Shell) is a cornerstone in this regard, and I can confidently guide you through the process of configuring SSH for public key authentication, a more secure alternative to password authentication.

Let's delve into the concepts highlighted in the provided article:

  1. SSH and Password vs. Public Key Authentication: The article emphasizes the importance of security, advocating for public key authentication over password authentication, especially for external servers. This is a well-established best practice in the field of cybersecurity. Passwords are susceptible to various attacks, while public key authentication provides a stronger layer of security.

  2. Generating SSH Public/Private Key Pairs: The article correctly outlines the first step in configuring public key authentication — generating key pairs using the ssh-keygen command. It wisely recommends using the Ed25519 algorithm due to its enhanced security features and Microsoft's endorsem*nt.

  3. Storing Private Keys Securely: Security is further reinforced by instructing users to securely store private keys using the ssh-agent command. The article goes on to highlight the necessity of keeping the private key in a safe place, treating it as equivalent to a password.

  4. Copying Public Key to the OpenSSH Server: The article provides clear instructions on where and how to save the public key on the OpenSSH Server, distinguishing between Standard users and Administrators. Proper access control is emphasized, ensuring that only authorized entities have access to the public key.

  5. Enabling Public Key Authentication on the OpenSSH Server: The article correctly identifies that Public Key Authentication is not enabled by default on the OpenSSH Server. It guides users through editing the sshd_config file to enable this feature and emphasizes the need to disable password authentication.

  6. Connecting Remotely with SSH: Once the configurations are in place, the article succinctly explains how to connect remotely using the ssh command, emphasizing the importance of adding the SSH key fingerprint to the trusted list during the first connection.

  7. Checking Event Logs for SSH Connections: The article provides an additional layer of accountability by instructing users on how to check Event Logs for SSH connections. This is a crucial step in monitoring and troubleshooting any potential issues.

By following the outlined steps, users can establish a robust and secure SSH configuration, contributing to a more resilient and protected system. I hope this breakdown provides clarity and confidence as you embark on implementing public key authentication for your SSH connections. If you have any further questions or need additional guidance, feel free to ask.

How to configure SSH Key based authentication on Windows | Askme4Tech (2024)

FAQs

How to configure SSH key on Windows? ›

Set up personal SSH keys on Windows
  1. Install OpenSSH on your device.
  2. Start the SSH service.
  3. Create an SSH key pair.
  4. Add your key to the SSH agent.
  5. Provide Bitbucket Cloud with your public key.
  6. Check that your SSH authentication works.

How to configure key based authentication for SSH? ›

To configure the SSH server to support key-based authentication, follow these steps:
  1. Log in to the server console as the bitnami user.
  2. Create a key pair, consisting of a public and private key, as shown below. ...
  3. Copy the private key file named id_rsa to a secure location.
Feb 6, 2023

How to configure SSH in Windows? ›

To configure SSH on Windows:
  1. Install or enable SSH server on your Windows machine. ...
  2. To enable the built-in SSH server for older Windows versions, see Install Win32 OpenSSH.
  3. Configure and start your SSH server.
  4. If you have firewall, open the SSH port in your firewall.

How to generate and configure SSH certificate based authentication? ›

Generating and Configuring SSH Certificate-Based Authentication (Step-by-Step Guide)
  1. Prerequisites.
  2. Step 1: Generate SSH Key Pair.
  3. Step 2: Copy the Public Key to the Server.
  4. Step 3: Verify SSH Key Authentication.
  5. Introduction to SSH Certificates.
  6. Generating a Certificate from the Public Key.
Mar 8, 2024

How to set SSH configuration? ›

Procedure
  1. Open the SSH configuration file /etc/ssh/sshd_config.
  2. Disable non-admin SSH tunneling. ...
  3. Disable agent forwarding (which is enabled by default). ...
  4. Update authentication methods. ...
  5. If SSH is not going to be used for other purposes on your system, consider restricting use to an explicit list of allowed HSTS users.

Where is my SSH key in Windows? ›

Your private SSH key will be located by default at C:\Users\<username>\. ssh\id_rsa . You should NOT touch this file or share it with anyone.

What is SSH key-based authentication? ›

What is an SSH key? updated on: 01.22.2024. An SSH key is a secure access credential used in the Secure Shell (SSH) protocol. SSH key pairs use public key infrastructure (PKI) technology, the gold standard for digital identity authentication and encryption, to provide a secure and scalable method of authentication.

What are the SSH key authentication methods? ›

SSH public key authentication relies on asymmetric cryptographic algorithms that generate a pair of separate keys (a key pair), one "private" and the other "public". You keep the private key a secret and store it on the computer you use to connect to the remote system.

How does SSH key authentication work? ›

An SSH key is used to access a remote server through an SSH connection. The keys come in pairs, a public key and a private key. The public key is kept within the server and the private key is with the user or the client. The server authenticates the user by sending a message encrypted using the public key.

How to configure SSH client on Windows 10? ›

Set up a Windows 10 SSH server:
  1. Open “Settings” > “Apps” > “Apps & Features” > “Optional Features.
  2. Select “Add Features” and “OpenSSH Server” and “Install” (admin rights required).
  3. Set the startup type for “OpenSSH Authentication Agent” and “OpenSSH Server” to “Automatic” in the Windows “Services” app.
Oct 4, 2023

How to run SSH on Windows? ›

Open command prompt as administrator, e.g. with Windows search > “cmd.exe” > “run as administrator”. Enter CMD command ssh . Connect to the desired server with ssh name@server . If necessary, consider the port: default is port 22, change port with -pPortnumber behind the server name.

How to use SSH server in Windows? ›

How to Connect via SSH
  1. Open the command line/terminal window and run the following ssh command: ssh [username]@[host_ip_address] ...
  2. When connecting to the server for the first time, a message appears asking to confirm the connection. ...
  3. Provide the password when prompted and press Enter.
Nov 23, 2023

What is the difference between SSH key based authentication and certificate authentication? ›

While SSH Key-based authentication uses public key cryptography to operate, SSH Certificate-based authentication simply attaches a signed certificate to each key to verify their identities. In essence, SSH certificates do away with old-school password-based SSH verification processes.

How do I set up certificate-based authentication? ›

Certificate-based authentication
  1. Load required key pairs and certificates for Code Signing.
  2. Prepare Circle of Trust certificates.
  3. Import and install certificates for Circle of Trust.
  4. Turn on Code Signing.
  5. Create Code Signing key pairs and certificates.
  6. Specify custom rules in ECC firewall.

How SSH key based authentication permits you to authenticate to a system without a password? ›

You can configure an SSH server to allow you to authenticate without a password by using key based authentication. This is based on a private-public key scheme. To do this, you generate a matched pair of cryptographic key files. One is a private key, the other a matching public key.

How to configure ssh client on Windows 10? ›

Set up a Windows 10 SSH server:
  1. Open “Settings” > “Apps” > “Apps & Features” > “Optional Features.
  2. Select “Add Features” and “OpenSSH Server” and “Install” (admin rights required).
  3. Set the startup type for “OpenSSH Authentication Agent” and “OpenSSH Server” to “Automatic” in the Windows “Services” app.
Oct 4, 2023

How to add SSH key to ssh agent in Windows? ›

Generating a new SSH key
  1. Open Terminal .
  2. Paste the text below, replacing the email used in the example with your GitHub email address. ssh-keygen -t ed25519 -C "your_email@example.com" ...
  3. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."

How to create SSH keys with PuTTY on Windows? ›

Generating an SSH key pair using PuTTY
  1. Click Save private key. The PuTTYgen Warning panel is displayed.
  2. Click Yes to save the private key without a passphrase.
  3. Type icat as the name of the private key, and specify the location where you want to save the private key. ...
  4. Click Save.

How to connect ssh in Windows CMD? ›

You can start an SSH session in your command prompt by executing ssh user@machine and you will be prompted to enter your password. You can create a Windows Terminal profile that does this on startup by adding the commandline setting to a profile in your settings.json file inside the list of profile objects.

Top Articles
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 6052

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.