A Python script to connect to AWS instances via SSH and perform directory operations using the uv package manager.
# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Or using pip
pip install uv# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .Create a .env file in your project directory:
# Copy the .env template and edit it
cp .env.example .env# Simple - uses .env file configuration
python aws_ssh_client.py
# Override specific values from .env
python aws_ssh_client.py --key ~/.ssh/different-key
# Enable verbose logging
python aws_ssh_client.py --verbose# Use .env file configuration (recommended)
python aws_ssh_client.py
# Override specific values from .env file
python aws_ssh_client.py --key ~/.ssh/different-key
python aws_ssh_client.py --host different-server.com
# Enable verbose logging
python aws_ssh_client.py --verbose
# If .env values are missing, script will prompt interactively
python aws_ssh_client.py
# AWS_SSH_HOST not found in .env file
# Enter AWS hostname/IP address: 34.229.96.55The script uses this priority order:
- Command line arguments (highest priority)
- .env file variables
- Interactive prompts (only if values are missing)
- Script alerts you: If required values are missing from
.env, you'll see warnings - Interactive prompts: Only appears for missing required values
- Auto-detection: Automatically finds common SSH keys if not specified
- Clean fallback: No hardcoded values in the script
-
Add .env to .gitignore:
echo ".env" >> .gitignore
-
Set proper SSH key permissions:
chmod 600 ~/.ssh/aws-key-2025 -
Use SSH agent (optional):
ssh-add ~/.ssh/aws-key-2025
-
SSH Key Protection: Ensure your SSH private key has proper permissions (600)
chmod 600 ~/.ssh/aws-key-2025 -
Key Management: Consider using SSH agent for better key management
ssh-add ~/.ssh/aws-key-2025 -
Connection Security: The script uses paramiko with proper host key checking
- Permission Denied: Check SSH key permissions and username
- Connection Timeout: Verify AWS security groups allow SSH access
- Host Key Verification: The script automatically adds unknown host keys
- Module Import Error: Ensure you're in the activated virtual environment
Enable debug logging by modifying the logging level:
logging.basicConfig(level=logging.DEBUG)This will show detailed SSH connection information and command execution details.