DEV Community

Cover image for Setting up SSH on Windows
Mike Whitaker
Mike Whitaker

Posted on

Setting up SSH on Windows

Every online tutorial for this seems to be way WAY too complicated for what is in fact a pretty basic process. This is targeted at people who (for example) need to set up a remote SSH session on a Linux server for development purposes).

We assume you have a username, password and hostname for the server you want to log in it.

  • install OpenSSH on your local Windows machine if it isn't already. You can find this under Settings, search for "Optional Features"

OpenSSH

Click the checkbox, and if it's not installed, install it.

  • Fire up a command prompt.

  • Create yourself an SSH key pair, by running ssh-keygen

C:\Users\You>ssh-keygen
Generating public/private ed<something> key pair.
Enter file in which to save the key (C:\Users\You/.ssh/id_ed<something>):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\You/.ssh/id_ed<something> 
Your public key has been saved in C:\Users\You/.ssh/id_<something>.pub
The key fingerprint is:
SHA256:<some random Text> you@YourMachine
The key's randomart image is:
+--[ED<something> 256]--+
| several lines  |
+----[SHA256]-----+****
Enter fullscreen mode Exit fullscreen mode

This generates a secure public/private key pair. On older machines, it may be saved in .ssh/id_rsa<something> instead of .ssh/id_ed<something>. If you have provided a passphrase[1], don't forget it. :D

  • Now you need to copy the PUBLIC key (the one ending in .pub) to your remote server[2]. Run:
C:\Users\You>scp .ssh\id*.pub user@server:
you@server's password: <type your password here>   
id_ed<something>.pub            100%  110     1.9KB/s   00:00
Enter fullscreen mode Exit fullscreen mode

Note the trailing colon on the command line: don't miss this off!

  • Login to the remote server.
C:\Users\You>ssh user@server
you@server's password: <type your password here>
<lots of blurb>
you@server$ 
Enter fullscreen mode Exit fullscreen mode
  • You are now logged into the remote server. Add your ssh public key to the list of permitted ones.
you@server$ cat id*.pub > .ssh/authorized_keys
you@server$ <now hit control+D>
Enter fullscreen mode Exit fullscreen mode

You will find yourself back at the Windows command prompt

  • Check you can log in without a password. If you originally provided a passphrase when you ran ssh-keygen, you will be prompted before you connect.
C:\Users\You>ssh user@server
<lots of blurb>
you@server$ 
Enter fullscreen mode Exit fullscreen mode

[1] The difference between a password and a pass*phrase* is that the former gets transmitted across the network to your remote host, and can potentially be snooped by a malicious attacker. A passphrase is local to your machine, and therefore immune to being snooped.

[2] You can do this and the next step in one go: the command (on your Windows machine) is

type .ssh\id_*.pub" | ssh user@host "cat >> .ssh/authorized_keys"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)