Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

How to Use gsh to Run Linux Commands Across Multiple Servers

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

gsh-run-linux-commands

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.

OptionPurposeTypical use
-h, --helpDisplay helpCheck available flags on your installed version
-d, --debugEnable execution debugging reportsTroubleshoot host matching or SSH execution
--no-host-prefixDo not prefix output lines with hostnameUse only when host identity is not needed in output
-s, --show-commandsShow command before output reportImprove auditability of what was executed
-n, --open-stdinKeep stdin open while runningInteractive scenarios (use carefully)
-l, --user USERSSH as a specific userRun as an ops account instead of current local user
-r, --run-locallyRun command locally, replacing $host with hostTemplate-like local command generation
-o, --self-remoteRun locally instead of SSH for local hostAvoid SSH to self when local host is in target set
-V, --versionShow version and exitValidate 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

PatternExampleWhen to use
Single tag/groupgsh linux "uptime"Operate on one broad fleet segment
Combined tagsgsh cpanel+vps "hostname"Narrow to hosts that match combined criteria
Split/exclusion stylegsh web-RHEL4 "uname -a"Target one set while removing another (per ghosts rules)
Explicit remote usergsh -l root linux "df -h /"Use controlled privileged account context

References

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) and gsh --help on your installed version, because option details can vary.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

How to Configure HTTP/HTTPS Proxy on Linux and Windows (CLI, GUI, Registry, and APT)

Set up proxy access correctly on Windows and Linux for command-line tools, package managers, and system-level use. This guide covers quick commands, persistent configuration, and common troubleshooting steps.

Read More

Linux pmap Command Guide: Inspect Process Memory Maps with Practical Examples

Learn how to use the Linux pmap command to inspect per-process memory mappings, compare output modes, and troubleshoot high memory usage quickly. This updated guide includes workflow steps, command examples, and interpretation tips.

Read More

iostat Command Guide for Linux: 20 Practical Examples for CPU and Disk I/O Troubleshooting

Learn how to use iostat to monitor CPU and storage performance on Linux systems. This revised guide covers installation, 20 practical commands, metric interpretation, and a troubleshooting workflow.

Read More

xargs in Linux: Practical Commands, Safe Patterns, and Pipeline Workflows

This guide explains how to use xargs effectively in Linux/Unix shells, from basic stdin handling to safe file operations and parallel execution. You’ll learn practical command patterns, portability caveats, and safer alternatives.

Read More

Linux mount and umount Commands: Practical Examples, /etc/fstab, and Safe Unmounting

Learn how to mount and unmount filesystems reliably on Linux, from one-off commands to persistent /etc/fstab entries. This guide covers common filesystem types, command comparisons, and safe troubleshooting steps.

Read More

Linux System Administrator Responsibilities: Daily Operations, Privileges, and Best Practices

Linux system administrators are responsible for server reliability, security, access control, patching, backups, and troubleshooting. This updated guide maps those responsibilities to practical workflows and command examples.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x