
gittech. site
for different kinds of informations and explorations.
SSH_commander: Run sequential command(s) on a group of SSH servers
SSH Commander
SSH Commander is a powerful, colorful command-line tool for executing commands across multiple SSH servers simultaneously. It supports both password and key-based authentication, custom ports, and can execute both single commands and command files.
Features
- π Supports both password and key-based authentication
- π Colorized output for better readability
- π Execute commands from files
- π Interactive server management
- π Secure password handling (never shown in terminal)
- π Single binary deployment
- βοΈ YAML-based configuration
- π Real-time output streaming
- β¨οΈ Graceful interrupt handling (Ctrl+C support)
System Requirements
Linux
Ubuntu/Debian:
- Modern systems:
libffi8
andlibssl3
- Older systems:
libffi7
andlibssl1.1
CentOS/RHEL:
- Modern systems:
libffi-8
andopenssl-3
- Older systems:
libffi-7
andopenssl-1.1
Windows
- Microsoft Visual C++ Redistributable
macOS
- No additional requirements
Installation
Option 1: Debian Package (Ubuntu/Debian)
- Download the latest .deb package from the releases page
- Install using dpkg:
sudo dpkg -i ssh-commander_*.deb
If you encounter any dependency errors during installation, run:
sudo apt -f install
This will automatically install any missing dependencies and complete the installation.
Option 2: Using Pre-built Binaries
- Download the latest release for your platform from the releases page
- Extract the archive
- Run the installation script:
./install.sh # For macOS/Linux
.\install.ps1 # For Windows (Run as Administrator)
Option 3: Building from Source
- Clone the repository:
git clone https://github.com/AthenaNetworks/ssh_commander.git
cd ssh_commander
- Create a virtual environment and install dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- Build the executable:
./build_all.sh
Configuration
SSH Commander stores server configurations in ~/.config/ssh-commander/servers.yaml
. This file is automatically created when you add your first server.
Configuration Format
The configuration file uses YAML format and supports both key-based and password authentication:
# Key-based authentication (recommended)
- hostname: web1.example.com
username: admin
key_file: ~/.ssh/id_rsa # Path to your SSH key
port: 22 # Optional, defaults to 22
tags: [prod, web] # Optional, defaults to ['default']
# Password authentication
- hostname: db1.example.com
username: dbadmin
password: your_secure_password # Not recommended for production use
port: 2222
tags: [prod, db] # Optional server tags
Security Notes
β οΈ Important Security Warning:
- Passwords are stored in plaintext and are NOT secure
- Anyone with access to your config file can see the passwords
- This includes backup systems, cloud sync, etc.
β Recommended Approach:
- Use key-based authentication instead
- Generate an SSH key:
ssh-keygen -t ed25519
- Copy to server:
ssh-copy-id user@hostname
- Use
key_file: ~/.ssh/id_ed25519
in config
- Generate an SSH key:
Configuration Security
- Config file is searched for in the following order:
- Path specified by
--config
argument servers.yaml
in the same directory as the executable~/.config/ssh-commander/servers.yaml
- Path specified by
- File permissions are set to user-only read/write (600)
- SSH key paths support
~
expansion to your home directory
Usage
Managing Servers
- Add a new server interactively:
ssh-commander add
- List configured servers:
ssh-commander list
- Remove a server:
ssh-commander remove web1.example.com
Executing Commands
- Run a single command on all servers:
ssh-commander exec -c "uptime"
- Run a command on servers with specific tags:
ssh-commander exec -c "uptime" -t "prod,web"
- Run multiple commands from a file:
ssh-commander exec -f commands.txt
- Run commands from file on specific tags:
ssh-commander exec -f commands.txt -t "staging"
Example commands.txt
:
uptime
df -h
free -m
who
- Use a different config file:
ssh-commander --config prod-servers.yaml exec -c "docker ps"
Real-world Examples
- Check system status across all servers:
ssh-commander exec -c "systemctl status nginx"
- Deploy updates:
ssh-commander exec -c "sudo apt update && sudo apt upgrade -y"
- Monitor disk space:
ssh-commander exec -c "df -h / /var /home"
- Check running Docker containers:
ssh-commander exec -c "docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'"
- Execute a maintenance script:
# maintenance.txt
systemctl status nginx
df -h
free -m
find /var/log -type f -size +100M -exec ls -lh {} \;
# Run maintenance checks
ssh-commander exec -f maintenance.txt
Output Formatting
SSH Commander uses colors to make output more readable:
- π΅ Server names are highlighted in blue
- π’ Successful output is shown in green
- π΄ Errors are displayed in red
- π£ Command execution status in purple
Security Considerations
Password Storage:
- Passwords in the config file should be treated with care
- Consider using key-based authentication when possible
- Use appropriate file permissions for your config file:
chmod 600 servers.yaml
SSH Keys:
- Key files should have proper permissions:
chmod 600 ~/.ssh/id_rsa
- Consider using different keys for different server groups
- Key files should have proper permissions:
Network Security:
- Be mindful of firewalls and network policies
- Use custom ports if needed
- Consider using jump hosts for isolated networks
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0) - see the LICENSE file for details.
Key points of the GPL-3.0 license:
- β You can use this software for commercial purposes
- β You can modify the source code
- β You can distribute your modifications
- β οΈ You must disclose the source code of your modifications
- β οΈ You must license your modifications under the GPL-3.0
- β οΈ You must state the significant changes you made
Support
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information about your problem
- Include your OS version and Python version when reporting bugs