SSHAutomator is a high-performance Go program that provides concurrent execution of scripts and commands on multiple remote servers over SSH, with built-in connection pooling and error handling.
- Concurrent Execution: Execute commands on multiple servers simultaneously with controlled concurrency
- Connection Pooling: Smart connection management to prevent resource exhaustion
- Robust Error Handling: Comprehensive error reporting and graceful failure management
- Context-Aware: Support for timeouts and graceful cancellation
- Flexible Authentication: Support for both password and key-based authentication
- Resource Efficient: Optimized memory usage and connection handling
- Configuration Options: Extensive command-line options for customization
go install github.com/gokusan92/SSHAutomator@latest
The program accepts the following command-line arguments:
sshautomator -script <script.txt> [options]
-host
: SSH host to connect to-port
: SSH port (default: 22)-username
: SSH username-password
: SSH password (optional if using key file)-keyfile
: Path to private key file (optional)-script
: Path to the script file containing commands-servers
: Path to server list file-concurrent
: Maximum number of concurrent connections (default: number of CPU cores)
You can authenticate using either a password or a private key:
# Password authentication
sshautomator -script commands.txt -host example.com -username user -password pass
# Key-based authentication
sshautomator -script commands.txt -host example.com -username user -keyfile ~/.ssh/id_rsa
When using the -servers
option, the server list file should be formatted as follows:
host1 username password
host2 username keyfile /path/to/key
host3 username password
Each line represents one server with space-separated fields:
- Host address
- Username
- Authentication type ("password" or "keyfile")
- Password or path to keyfile (depending on authentication type)
Single server execution:
sshautomator -script script.txt -host example.com -port 22 -username myuser -password mypassword
Multiple servers with concurrent execution:
sshautomator -script script.txt -servers serverlist.txt -concurrent 5
The script file should contain one command per line:
cd /var/log
ls -la
grep "error" application.log
The program provides detailed error reporting:
- Connection failures
- Authentication errors
- Command execution failures
- Timeout issues
Error messages include the affected server and specific failure reason.
- Uses connection pooling to manage resources efficiently
- Controlled concurrency to prevent overwhelming target servers
- Efficient memory usage with proper cleanup
- Context-aware execution with timeout support
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Clone the repository
git clone https://github.com/gokusan92/SSHAutomator.git
- Install dependencies
go mod tidy
- Run tests
go test ./...
- Follow standard Go coding conventions
- Use
gofmt
for code formatting - Include tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- The program uses
ssh.InsecureIgnoreHostKey()
for host key verification. In production environments, consider implementing proper host key verification. - Passwords and sensitive data are handled securely in memory.
- Connection timeouts are implemented to prevent hanging connections.
- Consider using key-based authentication instead of passwords when possible.
Common issues and solutions:
-
Connection timeouts
- Check network connectivity
- Verify SSH service is running on target
- Check firewall settings
-
Authentication failures
- Verify credentials
- Check key file permissions
- Ensure key format is correct
-
Execution errors
- Verify command syntax
- Check user permissions on target
- Review server logs for details