Skip to content

HotTechStack/aws-ssh-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS SSH Directory Access Script

A Python script to connect to AWS instances via SSH and perform directory operations using the uv package manager.

Setup Instructions

1. Install uv package manager (if not already installed)

# 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

2. Install dependencies using uv

# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e .

3. Update .env configuration file

Create a .env file in your project directory:

# Copy the .env template and edit it
cp .env.example .env

6. Run the script

# 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

Usage Examples

Basic Usage

# 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.55

Configuration Priority

The script uses this priority order:

  1. Command line arguments (highest priority)
  2. .env file variables
  3. Interactive prompts (only if values are missing)

Environment Configuration

Missing Configuration Handling

  • 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

Security Best Practices

  1. Add .env to .gitignore:

    echo ".env" >> .gitignore
  2. Set proper SSH key permissions:

    chmod 600 ~/.ssh/aws-key-2025
  3. Use SSH agent (optional):

    ssh-add ~/.ssh/aws-key-2025

Security Notes

  1. SSH Key Protection: Ensure your SSH private key has proper permissions (600)

    chmod 600 ~/.ssh/aws-key-2025
  2. Key Management: Consider using SSH agent for better key management

    ssh-add ~/.ssh/aws-key-2025
  3. Connection Security: The script uses paramiko with proper host key checking

Troubleshooting

Common Issues

  1. Permission Denied: Check SSH key permissions and username
  2. Connection Timeout: Verify AWS security groups allow SSH access
  3. Host Key Verification: The script automatically adds unknown host keys
  4. Module Import Error: Ensure you're in the activated virtual environment

Debugging

Enable debug logging by modifying the logging level:

logging.basicConfig(level=logging.DEBUG)

This will show detailed SSH connection information and command execution details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages