Login

Please fill in your details to login.





automating ssh connections in windows

Learn to set up passwordless SSH login on Windows using ED25519 keys, SSH Config, and the SSH Agent.
This guide explains how to set up SSH Key Authentication. SSH (Secure Shell) is a protocol used to securely connect to another computer over the internet. Instead of typing a password every time, we are going to use mathematical digital keys and saved passphrases to speed up our workflow.

Generate Your Key Pair


First, we need to create your digital keys using a command line tool called
ssh-keygen
. This tool generates a pair of connected files that work together:

The Private Key: This file stays on your computer and is completely secret. Think of it as your unique physical ID badge which only you have access to.

ALWAYS KEEP YOUR PRIVATE KEY SAFE - NEVER STORE IT ON A REMOTE DRIVE

The Public Key: This file goes onto the remote server. Think of it as a custom lock on the server's door that only your specific ID badge can open. You can secure anything with your public key lock but only you are allowed to open the lock because only you have the private key.

Open the terminal/command prompt on your local PC and run the generation command. We use
ed25519
because it is a modern, fast, and highly secure mathematical algorithm. You might want to give the file a more specific name than just server but remember to use your new name in all subsequent steps instead.

Windows PowerShell
ssh-keygen -t ed25519 -f "$env:USERPROFILE\.ssh\server"

Command Prompt (CMD)
ssh-keygen -t ed25519 -f "%USERPROFILE%\.ssh\server"


When it asks for a passphrase, type a strong but memorable phrase and press the Enter key. A passphrase adds an extra layer of security to the private key, protecting it just in case your laptop is ever compromised. This ISN'T (and shouldn't be) your server users password or your Windows password.

Once the command is complete, you should now have two files in your hidden SSH folder:

server
: Your PRIVATE key. Keep it secret. This is your ID badge.
server.pub
: Your PUBLIC key. This is the lock.

Install the Lock on the Server


Next, we need to copy the public key over to the server so it knows to trust you when you try to access it.

1
SSH into your server

Log into your remote server using the standard ssh command,
ssh user@server
and supply your server users password. You should see the server command prompt,
user@server:~# 
with your flashing cursor.

It is vital that you log onto the server with the user you want to connect.

2
Store the public key

The public key needs to be stored in a special file called authorized_keys in a specific location in your server users home folder for the private key to be able to find and verify it.

First, let's look for the file to see if it's already there. Type the following pressing the ENTER key afterwards.

find ~/.ssh


If you see this...

/user/.ssh
/user/.ssh/authorized_keys


...you are good to go to the next step. Otherwise, create the file now by running the following command.

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys


3
Locate and copy the public key

Now, back on your Windows machine execute the following command to view the contents of the public key file:

Windows PowerShell
Get-Content "$env:USERPROFILE\.ssh\server.pub"

Command Prompt (CMD)
type "%USERPROFILE%\.ssh\server.pub"


Highlight and copy the output displayed on your screen. It should look a little like this...

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPqB5zX9yT2mV8nL4kR7jC1fD3wH6gP0bN5xM8vQ2tZ4 user@example.com


4
Store the key on the server

Now, it's time to store that key in the authorized_keys file on your server. Back in the SSH terminal, execute the following command, replacing
PUBLIC-KEY
with the actual public key that you copied in step 3.

echo "PUBLIC-KEY" >> ~/.ssh/authorized_keys


Remember to press the ENTER key.

Create a Connection Shortcut


Instead of typing a really long connection command every single time you want to SSH into your server, we can create a handy shortcut using an SSH Config file. This file contains a list of shortcut names, hosts, users and a link to the private key file.

Create or edit this text file on your computer
C:\Users\YourUsername\.ssh\config
(no file extension) and add the following text to the file, replacing the {placeholder} text with your actual server details:

Host {shortcut}
    HostName {server address or ip}
    Port 22
    User {server user}
    IdentityFile ~/.ssh/server


Now, instead of typing
ssh user@my-really-long-server-address-which-i-cant-remember
, you can simply type
ssh {shortcut}
in your terminal to connect, although you will still have to enter your passphrase, unless...

Automate the Passphrase


Even with the shortcut, you'll still have to type the passphrase in which, let's face it, is a bit of a pain. To stop your computer from asking for your passphrase every time, we use a secure, built-in background tool called the Windows SSH Agent to remember it for us. This tool safely "holds" your unlocked key in your computer's memory whilst you work.

Windows Powershell
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent
ssh-add "$env:USERPROFILE\.ssh\server"

Command Prompt (CMD)
sc config ssh-agent start= auto
net start ssh-agent
ssh-add "%USERPROFILE%\.ssh\server"


Type your passphrase one last time. Now, Windows handles the login process for you automatically!

⚠️ Crucial Security Rule: Never, ever share your Private Key (the file WITHOUT the
.pub
extension). It is your secret digital identity, and anyone who has it can access your server!

5
Why would we do this?

This workflow makes our life a little easier. Any application which uses SSH (including the standard ssh command and IDEs like Google Antigravity) will be able to access the shortcuts in the config file and use the saved passphrase via the ssh-agent.
Last modified: April 20th, 2026
The Computing Café works best in landscape mode.
Rotate your device.
Dismiss Warning