Speed up SSH connections using a socket

Hello,

If you connect twice or more to the same server and you don’t want to reauthenticate again, you can use a socket to bypass it. You need OpenSSH 4.x or higher.

Normal situation:

1) First time

$ ssh ruben@pc-rgonzalez
ruben@pc-rgonzalez’s password:

2) Second time

ssh user@pc

user@pc password:

This is the normal behavior, so you need the put credentials twice.

Using ssh socket feature bypass it, so on the CLIENT side you need to add these lines.

(youre path here)

/etc/ssh/ssh_config

# socket speed up

Host *
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p

Better situation:

1) First time

$ ssh user@pc

user@pc password:

2) Second time

$ ssh user@pc

$ (no password needed!)

It’s also create a socket in your home like this:

file /home/user/.ssh/socket-user\@pc\:22
/home/user/.ssh/socket-user@pc-user:22: socket

If you close your ssh session , socket will be deleted until you create a new one using another ssh session.

It works nice if you need to exec a command behind a firewall like:

(create a session in background, it also creates the socket)
$ ssh -N -f user@firewall

then

ssh user@firewall “ssh -t user@anothermachine”

ssh user@firewall “ssh -t user@anothermachine2”

etc

See you!

Advertisement

One thought on “Speed up SSH connections using a socket

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s