Easy SSH sessions with Windows Terminal
Tags: tutorial, linux, windowsterminal, ssh
Published: 2020-09-21 19:14:03

---
title: Easy SSH sessions with Windows Terminal
published: true
description: A guide for setting up easy SSH connections with OpenSSH and Windows Terminal.
tags: tutorial, linux, windowsterminal, ssh
canonical_url: https://blog.rousseau.dev/posts/easy-ssh-sessions
cover_image: https://firebasestorage.googleapis.com/v0/b/blog.rousseau.dev/o/images%2Fbackgrounds%2Fconnections.jpg?alt=media
---

I have not used Linux very much since running Ubuntu almost 15 years ago. Now I have some Raspberry Pi and recently converted my virtual machine host to Ubuntu. So I have been using SSH a lot more, and I want to make it easier to SSH into my growing litter of Linux boxes.

This guide is mostly instructions for future me when I inevitably forget them or pave over my machine again.

For the examples, I'll be using the username `user` and the machine `reliablechair`, which is on the network at `reliablechair.lan`.

# Install OpenSSH

OpenSSH is offered as a [Windows feature](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview), but I prefer to install it with [Chocolatey](https://chocolatey.org/).

Run the following commands in an elevated PowerShell console.

```powershell
choco install openssh
cd 'C:\Program Files\OpenSSH-Win64\'
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent
```

# Create an SSH key

The next step is to create an SSH key. I am making one for each target machine, which is probably not necessary. You can use the same key for multiple machines if desired. In that case, you can leave off the filename and use the default name provided by `ssh-keygen`.

You can choose to use a passphrase to secure the key or not. If you do, you will have to enter the passphrase at some point before SSHing into the machine.

These commands do not need an elevated console.

```bash
cd ~
ssh-keygen -t rsa -b 4096 -f .\.ssh\reliablechair
```

# Add an initial entry to SSH config

This entry will let us connect to reliablechair with a password while copy the public key over. Without setting this up, you could get connection errors if SSH tries to use other SSH keys on your machine.

With this entry, using `ssh reliablechair` will be the same as `ssh user@reliablechair.lan`.

```text
Host reliablechair
  User user
  HostName reliablechair.lan
  PreferredAuthentications password
```

# Copy the public key to the target machine

This command will copy the public key into the target machine's authorized keys file.

```powershell
cat .\.ssh\reliablechair.pub | ssh reliablechair "mkdir -p .ssh && cat >> .ssh/authorized_keys"
```

# Update entry in SSH config

Switch the entry for `reliablechair` to use the SSH key. Setting `AddKeysToAgent` to `yes` will add the key to your `ssh-agent` session. This means that if you set a passphrase on the key, you won't have to enter it after the initial session.

```text
Host reliablechair
  User user
  HostName reliablechair.lan
  PreferredAuthentications publickey
  IdentitiesOnly yes
  IdentityFile c:\Users\Ryan\.ssh\reliablechair
  AddKeysToAgent yes
```

## ssh-add

You can also call `ssh-add` directly.

```powershell
ssh-add $env:HOME\.ssh\reliablechair
```

# SSH connection profile for Windows Terminal

Open the Windows Terminal settings. Add a new entry under `profile > list`. Use a new GUID for each entry.

```json
{
  "guid": "{474e775e-4f2a-5b96-ac1e-a2962a402335}",
  "hidden": false,
  "name": "Reliable Chair",
  "commandline": "ssh reliablechair"
}
```

Now there is an option to open a connection to `reliablechair` in the new tab menu for Windows Terminal.

# Wrap-up

With a little configuration, it is easy to create SSH sessions from Windows Terminal.

_This post was originally published at [blog.rousseau.dev](https://blog.rousseau.dev/posts/easy-ssh-sessions). Cover photo by [John Barkiple](https://unsplash.com/@barkiple) on [Unsplash](https://unsplash.com/)._