reusing_ssh_connections_in_linux_or_mac.md 1.79 KB
Newer Older
Adam Caprez's avatar
Adam Caprez committed
1
+++
2
title = "Reusing SSH connections"
Adam Caprez's avatar
Adam Caprez committed
3
4
5
description = "Reusing connections makes it easier to use multiple terminals"
weight = "37"
+++
6

7
8
9
10
11
To reduce the number of times it is necessary to enter your credentials,
it's possible to reuse a single SSH connection for multiple terminal instances.

## Mac/Linux

12
13
14
15
16
17
18
To make it more convenient for users who use multiple terminal sessions
simultaneously, SSH can reuse an existing connection if connecting from
Linux or Mac.  After the initial login, subsequent terminals can use
that connection, eliminating the need to enter the username and password
each time for every connection.  To enable this feature, add the
following lines to your `~/.ssh/config `file:

Adam Caprez's avatar
Adam Caprez committed
19
20
{{% panel header="`~/.ssh/config`"%}}
{{< highlight bash >}}
21
22
23
24
Host *
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ControlPersist 2h
Adam Caprez's avatar
Adam Caprez committed
25
26
{{< /highlight >}}
{{% /panel %}}
27

Adam Caprez's avatar
Adam Caprez committed
28
{{% notice info%}}
29
30
31
You may not have an existing `~/.ssh/config.` If not, simply create the
file and set the permissions appropriately first:
`touch ~/.ssh/config && chmod 600 ~/.ssh/config`
Adam Caprez's avatar
Adam Caprez committed
32
{{% /notice %}}
33
34
35

This will enable connection reuse when connecting to any host via SSH or
SCP.  
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

## Windows (PuTTY)

To enable connection reuse in PuTTY, enable the "Share SSH connections if possible" option under
the "SSH" configuration section.

First, select the saved PuTTY config for the cluster and click "Load".

{{< figure src="/images/putty_share_connection1.png" height="450" >}}

Next, select the "SSH" configuration category. Then check the "Share SSH connections if possible" checkbox.

{{< figure src="/images/putty_share_connection2.png" height="450" >}}

Return to the sessions screen by selecting "Session" at the top and click "Save" to save the settings 
for future sessions.

{{< figure src="/images/putty_share_connection3.png" height="450" >}}