Skip to main content
Remove false information. If socket does not exist, it will still create a new one.
Source Link

It's very simple if you plan in advance.

Through the configuration files

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

On the command line

Use the -M options to places the ssh client into “master” mode for connection sharing (See man ssh). You can also specify the path to the socket with the ControlPath option:

ssh -M -o ControlPath=~/.ssh/control:%C <HOST>

The next connection should automatically use the same ControlPath as the master connection. Or if you want to specify:

ssh -o ControlMaster=no -o ControlPath=~/.ssh/control:%C <HOST>

Specify ControlMaster to no in order to prevent the creation of a new socket if ControlPath does not exist.

It's very simple if you plan in advance.

Through the configuration files

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

On the command line

Use the -M options to places the ssh client into “master” mode for connection sharing (See man ssh). You can also specify the path to the socket with the ControlPath option:

ssh -M -o ControlPath=~/.ssh/control:%C <HOST>

The next connection should automatically use the same ControlPath as the master connection. Or if you want to specify:

ssh -o ControlMaster=no -o ControlPath=~/.ssh/control:%C <HOST>

Specify ControlMaster to no in order to prevent the creation of a new socket if ControlPath does not exist.

It's very simple if you plan in advance.

Through the configuration files

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

On the command line

Use the -M options to places the ssh client into “master” mode for connection sharing (See man ssh). You can also specify the path to the socket with the ControlPath option:

ssh -M -o ControlPath=~/.ssh/control:%C <HOST>

The next connection should automatically use the same ControlPath as the master connection. Or if you want to specify:

ssh -o ControlMaster=no -o ControlPath=~/.ssh/control:%C <HOST>

It's very simple if you plan in advance.

Through the configuration files

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

On the command line

Use the -M options to places the ssh client into “master” mode for connection sharing (See man ssh). You can also specify the path to the socket with the ControlPath option:

ssh -M -o ControlPath=~/.ssh/control:%C <HOST>

The next connection should automatically use the same ControlPath as the master connection. Or if you want to specify:

ssh -o ControlMaster=no -o ControlPath=~/.ssh/control:%C <HOST>

Specify ControlMaster to no in order to prevent the creation of a new socket if ControlPath does not exist.

It's very simple if you plan in advance.

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

It's very simple if you plan in advance.

Through the configuration files

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

On the command line

Use the -M options to places the ssh client into “master” mode for connection sharing (See man ssh). You can also specify the path to the socket with the ControlPath option:

ssh -M -o ControlPath=~/.ssh/control:%C <HOST>

The next connection should automatically use the same ControlPath as the master connection. Or if you want to specify:

ssh -o ControlMaster=no -o ControlPath=~/.ssh/control:%C <HOST>

Specify ControlMaster to no in order to prevent the creation of a new socket if ControlPath does not exist.

Add ControlPersist 600 (otherwise, it closes automatically between connections) and %C in case the host is too long
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

It's very simple with recent enough versions of OpenSSH if you plan in advance.

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C
ControlPersist 600

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

It's very simple with recent enough versions of OpenSSH if you plan in advance.

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C
ControlPersist 600

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

It's very simple if you plan in advance.

Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your ~/.ssh/config, set up connection sharing to happen automatically:

ControlMaster auto
ControlPath ~/.ssh/control:%C

If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast.

If you also put ControlPersist 600 in your .ssh/config, the tunnel will remain for 10 minutes (600 seconds) after you stop using it, which means you don't need to keep the first session running: you can have sequential sessions as long as you don't pause for more than 10 minutes.

Add ControlPersist 600 (otherwise, it closes automatically between connections) and %C in case the host is too long
Source Link
Loading
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
Loading