Easily manage dozens or hundreds of machines via SSH
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore More Vim leftovers Oct 24, 2016



Hey software engineers! Do you manage servers? Lots of servers? Hate copying and pasting IP addresses? Need a way to execute a command on each of a group of servers that you manage?

This app can help with those things.


You must have jq installed on your system so that the list of servers can be parsed. If jq is not found, ssh-to will complain and exit.

Getting Started

In order to use this script, you'll need to create a servers.json file:

./ssh-to --create

This will create a sample servers.json in the current directory. You may want to then move that file to $HOME/.ssh-to-servers.json so that ssh-to can be run from any directory in the filesystem.

Next, to add hosts and hostgroups to the servers.json file:

./ssh-to --edit

This will bring up $EDITOR to edit the file. After you are done editing, exit the editor, and the validity of the JSON will be checked. If the JSON fails to validate, you'll be prompted to hit ENTER to go back into the editor or ctrl-C to abort.

An exmample servers.json file can be found here.


Syntax: ssh-to [ --dump | --loop ] group [ host_number ] [ ssh_args ]

  • If no group if specified, all groups will be printed.
  • --dump Dump the IP address of the target host. Useful in automation.
  • --loop Loop through the target group and execute the same command on each host.


$ ssh-to
# Please re-run me with a group name to see a list of servers in that group.
# Available group names:
#       hadoop
#       kafka
#       splunk
#       zookeeper
# Exmample: ssh-to group_name

If no index is specified, all servers in that group will be displayed and the user will be prompted to pick one in the next invocation.


$ ssh-to hadoop
# Please re-run me with an index number of which server to SSH into.
# Available hosts in group 'hadoop': 
# 1)  hadoop01.sys.comcast.net
# 2)  hadoop02.sys.comcast.net
# 3)  hadoop03.sys.comcast.net
# 4)  hadoop04.sys.comcast.net
# Example: /Users/dmuth200/bin/ssh-to hadoop 1

If a group name and index are specified, SSH will be launched:

$ ssh-to hadoop 2
# SSHing to (hadoop01.sys.comcast.net)...
Last login: Wed Mar  9 17:00:23 2016 from
[dmuth200@hadoop01.sys.comcast.net ~]$ 

That was easy! :-)

Usage in Automated Environments

Want to use this script in an automated environment? No problem, just use the optional --dump parameter:

$ ssh-to hadoop 1 --dump

This can be used within other commands like so:

  • ssh otherusername@$(ssh-to hadoop 1 --dump)
  • scp file $(ssh-to hadoop 1 --dump):.
  • etc.

It can also be used in shell scripting as in the following example

for HOST in $(ssh-to --dump hadoop)
   scp file.txt ${HOST}:/path/to/destination/

Passing Options to SSH

If your SSH key isn't on the remote server, you're using prompted for a password. This can be a problem in automated environments. Instead, try using the $SSH_OPTS environment variable. That will let you pass options into the SSH command line.


SSH_OPTS=-oBatchMode=yes ssh-to hadoop --loop hostname

This will print hostnames of hosts in the hadoop group that you can SSH into.

Tmux Support

Yes, we have Tmux support. (how cool is that!?)

When a SSH connection is launched, the current window you are in will be renamed to the human-readable name of the target host. When you disconnect, the name will change back to what it was before.

This is useful to help you keep track of when SSH sessions get disconnected.

Looping Through Many Hosts

Now let's say you have dozens (or even hundreds) of hosts, and you want to execute a command on all of them. This can be done with the --loop parameter:

ssh-to hadoop --loop "hostname"
# Looping over group 'hadoop'...
# SSHing to hadoop01.sys.comcast.net...
# Executing command: hostname
# SSHing to hadoop02.sys.comcast.net...
# Executing command: hostname
# SSHing to hadoop03.sys.comcast.net...
# Executing command: hostname
# SSHing to hadoop04.sys.comcast.net...
# Executing command: hostname

Execution happens serially.

The --loop mode is quite useful for things like maintenance or upgrades.

Naturally, you can chain multiple commands with --loop, do inline shell script, etc. For example:

ssh-to hadoop --loop "puppet agent --test; service nginx start; nc -vz localhost 80"

Or lets say you want to do rolling upgrades of your Splunk platform:

ssh-to splunk --loop "yum install -y splunk; /opt/splunk/bin/splunk stop; /opt/splunk/bin/splunk start --answer-yes --no-prompt"

That's literally all there is to it! And I've literally (not figuratively) done this in production.


Douglas Muth douglas_muth@cable.comcast.com

Bugs can be filed here or emailed directly to me.