Skip to content

Instantly share code, notes, and snippets.

@mcocdawc
Created February 19, 2016 16:44
Show Gist options
  • Save mcocdawc/93fbb7f8de3c09ab9517 to your computer and use it in GitHub Desktop.
Save mcocdawc/93fbb7f8de3c09ab9517 to your computer and use it in GitHub Desktop.
No retyping of passwords for computerclusters
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
Host server1
User username_on_server1
HostName server1.com
Host server2
User username_on_server2
HostName server2.com
#!/bin/bash
# Opens ssh sessions to be picked up by ControlMaster in ~/.ssh/config during the day
# -f forks to the background
# -N no commands to be executed on remote computer
# -o Specify ssh options
for computer in server1 server2; do
printf "\n \n $computer \n \n"
ssh -f $computer -N -o 'ServerAliveInterval 300' -o 'ServerAliveCountMax 100'
done
@mcocdawc
Copy link
Author

This is a minimal example of how to set up your ssh to not retype your passwords when often sshing to computer clusters from Unix.
Speak with the administrators of the remote servers if they allow this:

  1. Append the snippet of the file config to ~/.ssh/config/
  2. Put silent_ssh to a directory which is in PATH and make it executable.
  3. Replace the names of server1, username_on_server1... with the actual names.

If you now execute silent_ssh it creates background processes of ssh connections to the remote servers.
Every time you reconnect to the server the ControlMaster will reuse the existing ssh connection.
This includes other ssh based services like scp, sftp or rsync.

Because of the options -o 'ServerAliveInterval 300' -o 'ServerAliveCountMax 100' you have to reexecute silent_ssh approximately every 8 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment