krzysiek
krzysiek Author of itreset.github.io, a site dedicated to IT issues: virtualization, network configuration. This is a public notebook of instructions and problems encountered by the author of the blog.

Passwordless SSH Access from Windows to a Linux Device

Passwordless SSH Access from Windows to a Linux Device

The OpenSSH client in Windows 10 does not include the ssh-copy-id command that is commonly available in Linux systems. However, with a simple one-liner in PowerShell, we can replicate the functionality and copy the SSH public key to a remote Linux device — enabling passwordless login.

1️⃣ Generating an SSH Key

Skip this step if you already have a working SSH key pair.

Open PowerShell (not Command Prompt!) and run:

1
ssh-keygen

By default, the keys will be saved in the directory:

1
%USERPROFILE%\.ssh\

The public key file we are interested in is:

1
id_rsa.pub

Example output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
C:\Users\kadamczak/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\kadamczak/.ssh/id_rsa
Your public key has been saved in C:\Users\kadamczak/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:kXlQ1VNzGN+yytspx5i9BAUHlXg9y34pGIgEIqaKkc8 stordis\kadamczak@NB-TECH17
The key's randomart image is:
+---[RSA 3072]----+
| o . .. ....+=+Bo|
|o.. . . + .o*o=|
|+ . = o .+.=|
|o+ . + . . = |
|o E S + o .|
| o + o.|
| o=o .|
| +++. |
| .o+. |
+----[SHA256]-----+
PS C:\Users\kadamczak>

2️⃣ Copying the SSH Key to a Remote Linux Device

To copy your public key to the remote Linux device, use the following one-liner in PowerShell:

1
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh user@REMOTE_IP "cat >> ~/.ssh/authorized_keys"

Replace user and REMOTE_IP with your actual Linux username and the IP address or FQDN of the remote machine.

Example:

1
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh krzysiek@192.168.196.200 "cat >> ~/.ssh/authorized_keys"

You’ll be asked for your password once. After successful execution, the key will be saved on the remote server.

3️⃣ Testing Passwordless SSH Access

Now test the connection:

1
ssh krzysiek@192.168.196.200

Example session:

1
2
3
4
5
6
PS C:\Users\admin> ssh krzysiek@192.168.196.200
Linux srvoffice-rpi 6.1.21-v7+ #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l

Last login: Wed May 22 13:44:05 2024 from 10.10.169.3

krzysiek@srv-rpi:~ $

Notice that no password was required — the setup was successful.

References

This guide was heavily inspired by a blog post written by Christopher Hart