Overview
The SSH client is implemented insrc/tools/ssh.py using the Paramiko library. It supports both password and key-based authentication.
Default SSH Settings:
- Host:
localhost - Port:
2222 - User:
sentinel - Connection timeout:
10seconds
Authentication Methods
Password Authentication
The simplest method, suitable for development and testing environments.Key-Based Authentication (Recommended)
More secure method using SSH key pairs.Generate SSH key pair
Generate a new SSH key pair for Sentinel AI:This creates:
- Private key:
~/.ssh/sentinel_key - Public key:
~/.ssh/sentinel_key.pub
Configure Sentinel AI
Set the key file path in your configuration:Modify the SSH client initialization to use the key file:
.env
SSH Client Implementation
TheSSHClient class handles connection management and command execution:
Key Features
Auto Host Key Policy
Automatically accepts unknown host keys using
AutoAddPolicy()Sudo Support
Execute commands with sudo privileges using password injection
Connection Timeout
10-second timeout prevents hanging on unreachable hosts
Stop Signal Handling
Gracefully handles interruption signals during command execution
User Permissions
The SSH user needs appropriate permissions to monitor and manage services.Recommended Setup
Service-Specific Permissions
Depending on which services you’re monitoring:Nginx Permissions
Nginx Permissions
/etc/sudoers.d/sentinel-nginx
PostgreSQL Permissions
PostgreSQL Permissions
/etc/sudoers.d/sentinel-postgresql
Docker Permissions
Docker Permissions
Security Best Practices
Use SSH Keys
Always use key-based authentication in production. Disable password authentication in SSH config.
Restrict SSH User
Create a dedicated user with limited permissions. Never use root account.
Enable SSH Logging
Monitor SSH access logs at
/var/log/auth.log for unauthorized access attempts.Use Firewall Rules
Restrict SSH access to specific IP addresses using iptables or cloud security groups.
Rotate Keys Regularly
Change SSH keys periodically, especially after team member departures.
Disable Root Login
Set
PermitRootLogin no in /etc/ssh/sshd_config.Connection Testing
Test your SSH configuration before running Sentinel AI:Troubleshooting
Connection Timeout
Connection Timeout
Error:
Connection timeout after 10 secondsSolutions:- Verify the SSH_HOST and SSH_PORT are correct
- Check firewall rules allow connections on the SSH port
- Ensure the target server’s SSH service is running
- Test with direct SSH:
ssh -p 2222 user@host
Authentication Failed
Authentication Failed
Error:
Authentication failedSolutions:- Verify SSH_USER and SSH_PASS are correct
- For key-based auth, ensure the key file exists and has correct permissions (600)
- Check that the public key is in the server’s
~/.ssh/authorized_keys - Verify the user account is not locked on the server
Permission Denied for Commands
Permission Denied for Commands
Error:
Permission denied when executing service commandsSolutions:- Configure sudoers as described in User Permissions section
- Test with direct SSH:
ssh user@host 'sudo service nginx status' - Ensure the user is in the sudo group
- Check
/var/log/auth.logfor sudo errors
Host Key Verification Failed
Host Key Verification Failed
Error:
Host key verification failedSolutions:- The SSH client uses
AutoAddPolicy()to accept new keys automatically - If this still occurs, remove old key:
ssh-keygen -R hostname - Or manually accept:
ssh -o StrictHostKeyChecking=no user@host
Advanced Configuration
Multiple Servers
To manage multiple servers, extend the configuration:SSH Bastion/Jump Host
For servers behind a bastion host:Next Steps
Environment Variables
Configure all environment variables
Services Configuration
Define services to monitor
Deployment
Deploy Sentinel AI with Docker