Originally published on 2015-08-12; fully revised and updated.

gsh (Group Shell) is a remote shell multiplexor: it runs commands across multiple machines at once while keeping remote shells interactive and persistent. This is useful for sysadmins and DevOps engineers who need to check state, gather data, or run repeatable operations across server fleets over SSH.
What gsh is and when to use it
In the original source, gsh is described as a pluggable Python implementation related to DSH (Distributed Shell). It requires remote shell access (commonly SSH) to each target host, then lets you select systems by tags/macros and run one command across that set.
- Run the same read-only check on many servers (kernel, OS release, disk usage).
- Target hosts by groups/tags instead of manually listing hostnames.
- Keep output grouped by host for quick triage.
How host targeting works with /etc/ghosts
gsh uses /etc/ghosts to map hosts to tags. You then call gsh with a systems expression (macros/tags) and a command.
# Machines
# hostname OS-Version Hardware OS cp security
linuxbrigade.com debian6 baremetal linux plesk iptables
linuxbrigade.com centos5 vps linux cpanel csfcluster
linuxbrigade.com debian7 baremetal linux plesk iptables
linuxbrigade.com centos6 vps linux cpanel csfcluster
linuxbrigade.com centos6 vps linux cpanel csfcluster
linuxbrigade.com centos6 vps linux nocp denyhosts
linuxbrigade.com debian6 baremetal linux plesk iptables
linuxbrigade.com centos6 baremetal linux cpanel csf
linuxbrigade.com centos5 vps linux cpanel csfCode language: CSS (css)
The original article shows expressions like cpanel+vps and web-RHEL4 for combining/splitting groups. Exact behavior depends on your ghosts(1) macro rules and local configuration.
Execution workflow
flowchart TD
A[Set up SSH access to hosts] --> B[Define hosts and tags in etc ghosts]
B --> C[Run gsh with systems expression and command]
C --> D[gsh opens remote shells]
D --> E[Command runs on selected hosts]
E --> F[Output is returned per host]
F --> G[Review results and rerun as needed]
Command syntax and option reference
gsh [OPTIONS] SYSTEMS CMD...Code language: CSS (css)
From the source: SYSTEMS is a combination of ghost macros, and CMD is the command to run remotely.
| Option | Purpose | Typical use |
|---|---|---|
-h, --help | Display help | Check available flags on your installed version |
-d, --debug | Enable execution debugging reports | Troubleshoot host matching or SSH execution |
--no-host-prefix | Do not prefix output lines with hostname | Use only when host identity is not needed in output |
-s, --show-commands | Show command before output report | Improve auditability of what was executed |
-n, --open-stdin | Keep stdin open while running | Interactive scenarios (use carefully) |
-l, --user USER | SSH as a specific user | Run as an ops account instead of current local user |
-r, --run-locally | Run command locally, replacing $host with host | Template-like local command generation |
-o, --self-remote | Run locally instead of SSH for local host | Avoid SSH to self when local host is in target set |
-V, --version | Show version and exit | Validate binary version during troubleshooting |
Practical command examples
# Example from the original post
gsh linux "cat /etc/redhat-release; uname -r"
# Show command before output for better traceability
gsh -s linux "uptime"
# Run as a specific user
gsh -l root linux "df -h /"
# Example tag expressions from the original post
gsh cpanel+vps "hostname"
gsh web-RHEL4 "uname -a"Code language: PHP (php)
Command pattern comparison
| Pattern | Example | When to use |
|---|---|---|
| Single tag/group | gsh linux "uptime" | Operate on one broad fleet segment |
| Combined tags | gsh cpanel+vps "hostname" | Narrow to hosts that match combined criteria |
| Split/exclusion style | gsh web-RHEL4 "uname -a" | Target one set while removing another (per ghosts rules) |
| Explicit remote user | gsh -l root linux "df -h /" | Use controlled privileged account context |
References
- http://www.linuxbrigade.com/run-the-same-command-on-many-linux-servers-at-once/
- http://linux.die.net/man/1/gsh
- https://github.com/gmjosack/gsh
- http://outflux.net/unix/software/gsh/
- http://outflux.net/unix/software/gsh/gsh.html
Best practices and common pitfalls
- Set up SSH keys before using gsh at scale to avoid repeated password prompts.
- Start with read-only commands first (for example,
uptime,uname,cat) before making changes. - Keep host prefixes enabled for easier debugging across many targets.
- Validate group/tag expressions on a small subset before broad execution.
- Review
ghosts(1)andgsh --helpon your installed version, because option details can vary.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals