EC2 Session Gate
Secure EC2 instance management and connection gateway
A modern, cross-platform application for managing AWS EC2 instances and establishing secure connections via AWS Systems Manager Session Manager.
🚀 Overview
EC2 Session Gate simplifies secure access to your EC2 instances without exposing SSH ports or managing complex VPN configurations. Built on AWS Systems Manager Session Manager, it provides a seamless interface for SSH, RDP, and custom port forwarding connections.
Why EC2 Session Gate?
- ✅ Zero Open Ports - No need to expose SSH ports or manage security groups
- ✅ Secure by Default - Uses AWS SSM Session Manager for encrypted connections
- ✅ Cross-Platform - Works seamlessly on Windows, macOS, and Linux
- ✅ Easy to Use - Intuitive web interface with desktop app option
- ✅ Multi-Profile Support - Switch between AWS profiles effortlessly
- ✅ Auto Key Detection - Automatically finds and uses SSH keys for password decryption
✨ Features
Core Capabilities
-
🔐 SSH Connections
Secure shell access via SSM port forwarding with automatic SSH key detection and path resolution -
🖥️ RDP Support
Remote desktop connections for Windows instances with automatic password decryption using SSH keys -
🔌 Custom Port Forwarding
Forward any port through SSM tunnels with flexible port selection and automatic port management -
📊 Instance Management
View, filter, and manage EC2 instances with real-time status updates and comprehensive instance details -
🔑 Multi-Directory SSH Keys
Support for multiple SSH key directories with automatic key lookup and path resolution -
⚡ Auto-Refresh
Automatic instance list refresh with configurable intervals -
🎨 Modern UI
Clean, responsive interface built with Bootstrap 5
📋 Prerequisites
Before you begin, ensure you have:
- Python 3.9+ installed
- AWS CLI v2 installed and configured
- AWS Session Manager Plugin installed
- AWS credentials configured (via
~/.aws/credentialsor environment variables)
Installing Prerequisites
Install AWS CLI v2
macOS:
brew install awscli
Linux:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Windows: Windows:
choco install awscli
Download and run the installer from AWS CLI Downloads
Install Session Manager Plugin
macOS:
brew install --cask session-manager-plugin
Linux:
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" -o "session-manager-plugin.rpm"
sudo yum install -y session-manager-plugin.rpm
Windows:
choco install awscli-session-manager
Download and run the installer from Session Manager Plugin Downloads
🛠️ Installation
-
Clone the repository
git clone https://github.com/boussaffawalid/ec2-session-gate.git cd ec2-session-gate
-
Create a virtual environment
python -m venv .venv # Activate virtual environment # On macOS/Linux: source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
Installing from PyPI
Alternatively, install directly from PyPI:
pip install ec2-session-gate
After installation, launch the application:
# Desktop GUI mode (default)
ec2-session-gate-gui
# Or API/server mode
APP_MODE=api ec2-session-gate
# Or web browser mode
APP_MODE=web ec2-session-gate
🎮 Usage
Running the Application
EC2 Session Gate supports three execution modes:
🖥️ Desktop Mode (Recommended)
Launches a native desktop window using PyWebView.
python run.py
# or explicitly:
APP_MODE=desktop python run.py
🌐 Web Browser Mode
Opens the application in your default web browser.
APP_MODE=web python run.py
🔌 API/Server Mode
Runs the Flask server only (useful for remote access or API usage).
APP_MODE=api python run.py
The application will be available at http://127.0.0.1:5000
Quick Start Guide
-
Connect to AWS
- Select your AWS profile from the dropdown
- Choose the AWS region
- Click "Connect"
- View your EC2 instances in the list
-
Start a Connection
- SSH: Click the "SSH" button on an instance card
- RDP: Click the "RDP" button (Windows instances only)
- Custom Port: Click the "Port" button and specify remote/local ports
-
Manage Connections
- View active connections in the sidebar
- Copy connection details to clipboard
- Terminate connections when done
Advanced Features
Instance Filtering
Use the filter box to search instances by:
- Instance name
- Instance ID
- Instance type
- Instance state
- Operating system
Supports regular expressions for advanced filtering.
Port Selection
- SSH/RDP: Automatically uses the same local port as remote port (22 for SSH, 3389 for RDP)
- Custom Ports: Uses the same local port if available, otherwise falls back to configured range
- Port Range: Configurable in Preferences with OS-specific defaults:
- Windows: 40000-40100 (below ephemeral port range)
- Linux/macOS: 61000-61100 (above ephemeral port range)
⚙️ Configuration
Preferences
Preferences are stored in:
- Linux/macOS:
~/.config/ec2-session-gate/preferences.json - Windows:
%APPDATA%\ec2-session-gate\preferences.json
Available Settings
| Setting | Description | Default |
|---|---|---|
| Port Range | Port range for port forwarding | OS-specific (Windows: 40000-40100, Linux/macOS: 61000-61100) |
| SSH Key Folders | Directories where SSH keys are stored (one per line) | ~/.ssh |
| Logging Level | Application log level | INFO |
SSH Key Configuration
Configure multiple SSH key directories in Preferences:
- Each folder path on its own line
- Supports
~expansion (e.g.,~/.ssh) - Keys are automatically searched when decrypting Windows passwords
- SSH commands include the key path automatically
Example:
~/.ssh
~/Projects/keys
/path/to/custom/keys
📁 Project Structure
ec2-session-gate/
├── src/ # Source code
│ ├── app.py # Flask app factory + blueprints
│ ├── api.py # REST API endpoints
│ ├── ui.py # UI routes
│ ├── aws_manager.py # AWS SSM connection management
│ ├── preferences_handler.py # User preferences
│ ├── health.py # Health check utilities
│ ├── utils.py # Utility functions
│ └── static/ # Frontend assets
│ ├── css/ # Stylesheets
│ ├── js/ # JavaScript
│ └── templates/ # HTML templates
├── run.py # Application launcher
├── requirements.txt # Python dependencies
├── pyproject.toml # Project metadata
└── tests/ # Test files
🔧 Development
Running Tests
python -m pytest tests/
Building Desktop App
Using PyInstaller (Standalone Executable)
# Install PyInstaller
pip install pyinstaller
# Build standalone executable
python build_standalone.py
# Or manually:
pyinstaller --onefile \
--windowed \
--add-data "src/static:src/static" \
--add-data "src/defaults.json:src" \
--add-data "src/logging.yaml:src" \
--hidden-import=webview \
--hidden-import=flask \
run.py
The executable will be created in the dist/ directory:
- Windows:
dist/ec2-session-gate.exe - macOS:
dist/ec2-session-gate.app - Linux:
dist/ec2-session-gate
Project Dependencies
- Flask>=2.3 - Web framework
- boto3>=1.34 - AWS SDK for Python
- botocore>=1.34 - AWS SDK core library
- PyYAML>=6.0 - YAML parsing for configuration
- pywebview>=4.0 - Desktop application framework
- cryptography>=41.0 - Password decryption for Windows instances
- psutil>=5.9.0 - Process management and cleanup
🐛 Troubleshooting
Common Issues
AWS CLI not found
Solution: Install AWS CLI v2 and ensure it's in your PATH.
Verify installation:
aws --version
Session Manager Plugin missing
Solution: Install the AWS Session Manager Plugin.
Verify installation:
session-manager-plugin
No AWS credentials detected
Solution: Configure AWS credentials via aws configure or environment variables.
aws configure
# or set environment variables:
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
export AWS_DEFAULT_REGION=us-east-1
Port already in use
Solution: Adjust port range in Preferences or specify a different local port when starting a connection.
SSH key not found
Solution: Add SSH key directories in Preferences. Ensure keys have correct permissions:
chmod 600 ~/.ssh/your-key.pem
Logs
Application logs are written to:
- Development:
src/app.log - Production:
~/.config/ec2-session-gate/logs/app.log
View logs:
tail -f src/app.log
🤝 Contributing
Contributions, feedback, and improvement ideas are welcome!
How to Contribute
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Contact
- Maintainer: Walid Boussafa
- Email: walid.boussafa@outlook.com
- GitHub: @boussaffawalid
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
📦 Publishing to PyPI
Installing from PyPI
Once published, users can install the package using:
pip install ec2-session-gate
After installation, the application can be launched with:
# Desktop GUI mode (default)
ec2-session-gate-gui
# Or API/server mode
APP_MODE=api ec2-session-gate
# Or web browser mode
APP_MODE=web ec2-session-gate
Publishing a New Version
-
Update version in
setup.pyandpyproject.toml -
Install build tools:
pip install build twine
-
Build the package:
make build # or: python -m build
-
Test on TestPyPI (optional):
make publish-test # or: twine upload --repository testpypi dist/*
-
Publish to PyPI:
make publish # or: twine upload dist/*
Standalone Executable Distribution
To create standalone executables for distribution:
# Build standalone executable
make build-standalone
# or: python build_standalone.py
The executables will be in the dist/ directory and can be distributed independently without requiring Python installation.
📚 Additional Resources
🎯 Roadmap
- Enhanced connection history
- Connection templates/presets
- Batch operations on instances
- Export connection details
- Dark mode support
- Mobile-responsive improvements
🙏 Acknowledgments
This project was inspired by SSM Manager, a Windows desktop application for managing AWS SSM sessions. EC2 Session Gate extends this concept with cross-platform support and additional features.
Built with:
Made with ❤️ for the AWS community
Metadata
Release files for ec2-session-gate 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ec2_session_gate-1.0.5.tar.gz | 2.6 MB | Without provenance | Details for ec2_session_gate-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ec2_session_gate-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for ec2_session_gate-1.0.5-py3-none-any.whl |
Total release size: 5.2 MB
Release files / ec2_session_gate-1.0.5.tar.gz
| Download URL | ec2_session_gate-1.0.5.tar.gz |
|---|---|
| Size | 2.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1ab251efa9d701a962cac55aebf11da3465b5b32e43be796ef91d74a5800c13
|
|
BLAKE2b-256 checksum How to use checksums |
1d2bcd093c514284209702f35df1af8d64c3c6492f506019e3e0c5c64450f24b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / ec2_session_gate-1.0.5-py3-none-any.whl
| Download URL | ec2_session_gate-1.0.5-py3-none-any.whl |
|---|---|
| Size | 2.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
851b5dd9a080a06ebac85c321a67fb18f9e06a9febfdc151d25ec6cecb122055
|
|
BLAKE2b-256 checksum How to use checksums |
cf3037fafd7f77cf62af7a5d367bf792bbae45a1ea8dcda51d099916bfb2b02c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for ec2-session-gate 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.