website/content/blog/sshconnectionsharing.md

32 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2020-06-05 16:45:20 -04:00
---
title: "SSH Connection Sharing"
date: 2020-06-05T16:39:24-04:00
draft: false
2022-01-02 14:24:29 -05:00
tags: ["SSH"]
2023-01-05 14:04:45 -05:00
medium_enabled: true
2020-06-05 16:45:20 -04:00
---
If you're like me, you open a lot of different terminal sessions throughout your day. When it comes to SSH, I want these different sessions to share a connection rather than creating a new one each time.
To accomplish this, I have the following in my `~/.ssh/config` file.
```
ControlMaster auto
ControlPersist no
ControlPath ~/.ssh/sockets/socket-%r@%h:%p
```
| Option | Description |
| ---------------- | ------------------------------------------------------------ |
| `ControlMaster` | Allows connection sharing |
| `ControlPersist` | `yes` to keep connection up even when no clients are connected.<br />`2s` (or custom timeout) to keep the connection up for 2 seconds after no clients are connected.<br />`no` to disconnect immediately |
| `ControlPath` | Where to store connection information. This should not be writable by other users. |
2020-06-11 10:17:32 -04:00
You'll also need to create the `sockets` folder if you don't have it already setup.
```bash
mkdir ~/.ssh/sockets
chmod go-w ~/.ssh/sockets
```