# SSH Manager Deployment Guide 🚀 ## Overview The MCP SSH Manager now includes advanced deployment features that solve common deployment challenges: - ✅ Automatic permission handling - ✅ Secure sudo execution - ✅ Server aliases for easier access - ✅ Batch file deployments - ✅ Automatic backups before deployment ## New Tools ### 1. `ssh_deploy` - Automated File Deployment Deploy files with automatic permission handling and backup. #### Basic Usage ``` "Deploy my config file to production server" "Upload all JavaScript files to staging" ``` #### Advanced Usage with Options ```json { "server": "production", "files": [ { "local": "/local/path/file.js", "remote": "/var/www/app/file.js" } ], "options": { "owner": "www-data:www-data", "permissions": "644", "backup": true, "restart": "systemctl restart nginx" } } ``` `restart` is a shell command, not a service name: it runs as written on the server, as the SSH user, after the file is in place (so a bare `nginx` is run as the `nginx` program). It is the one part of a deploy that is not quoted for you, on purpose, because `cd /opt/app && ./bin/restart` is a legitimate value. With approval turned on, the approval card shows the files, their target paths and this command in full. `readonly` and `restricted` servers refuse `ssh_deploy` altogether. ### 2. `ssh_execute_sudo` - Execute with Sudo Run commands with sudo privileges securely. ``` "Run 'apt update' on production with sudo" "Execute 'systemctl restart nginx' as root on staging" ``` ### 3. `ssh_alias` - Manage Server Aliases Create shortcuts for your servers. ``` "Create alias 'prod' for production server" "List all server aliases" "Remove alias 'old-server'" ``` ## Common Deployment Workflows ### Application Module Deployment A typical end-to-end deployment of a couple of module files into a running app: ``` # Step 1: Create aliases for easier access "Create alias 'myapp' for production_server" # Step 2: Deploy files using the new tool "Deploy handler.py and handler.js to myapp:/opt/myapp/apps/myapp/module/" # Step 3: Restart the service "Run './bin/restart' on myapp" ``` The deployment tool automatically: - Uploads to a temp location first - Moves files to the correct location - Handles permissions if needed - Creates backups of existing files ### Web Application Deployment ``` # Deploy with automatic nginx restart "Deploy index.html to production:/var/www/html with nginx restart" # This single command: # 1. Backs up existing index.html # 2. Uploads new file to temp # 3. Moves to final location with correct permissions # 4. Restarts nginx ``` ### Configuration File Updates ``` # Deploy sensitive config with proper permissions "Deploy nginx.conf to prod:/etc/nginx/ with owner root:root and permissions 644" ``` ## Security Best Practices ### 1. Sudo Password Handling ⚠️ **Never** pass sudo passwords directly in commands. Instead: **Option A: Configure in .env (Recommended)** ```env SSH_SERVER_PRODUCTION_SUDO_PASSWORD=your_password ``` **Option B: Use key-based sudo (Most Secure)** Configure passwordless sudo for specific commands on your server. ### 2. Sensitive File Handling The deployment tool automatically: - Never logs passwords in output - Masks sensitive information in logs - Uses secure temp file locations ### 3. Backup Strategy Always enabled by default: - Creates timestamped backups before overwriting - Format: `original_file.bak.YYYYMMDD_HHMMSS` ## Troubleshooting ### Permission Denied Errors **Problem**: Can't write to system directories **Solution**: Use `ssh_deploy` with proper options: ```json { "options": { "owner": "www-data:www-data", "sudoPassword": "configured_in_env" } } ``` ### Server Not Found **Problem**: "Server 'host.example.com' not found" **Solution**: Use configured name or create an alias: ``` "Create alias 'host.example.com' for myapp" ``` ### Files Not Updating **Problem**: Files uploaded but changes not visible **Solution**: Ensure service restart: ```json { "options": { "restart": "systemctl restart myapp" } } ``` ## Configuration Examples ### .env Configuration ```env # Server with sudo password for deployments SSH_SERVER_PRODUCTION_HOST=prod.example.com SSH_SERVER_PRODUCTION_USER=deploy SSH_SERVER_PRODUCTION_PASSWORD=deploy_password SSH_SERVER_PRODUCTION_SUDO_PASSWORD=sudo_password SSH_SERVER_PRODUCTION_DEFAULT_DIR=/var/www/app # Development server with key auth SSH_SERVER_DEV_HOST=dev.example.com SSH_SERVER_DEV_USER=developer SSH_SERVER_DEV_KEYPATH=~/.ssh/dev_key SSH_SERVER_DEV_DEFAULT_DIR=/home/developer/app ``` ### Alias Configuration Create a `.server-aliases.json`: ```json { "prod": "production", "dev": "development", "stage": "staging", "myapp": "production_server" } ``` ## Performance Tips 1. **Batch Deployments**: Deploy multiple files in one command 2. **Use Aliases**: Shorter names = faster typing 3. **Default Directories**: Set default dirs to avoid repetition 4. **Connection Reuse**: Connections are kept alive during session ## Example: Complete Application Update End-to-end deployment of a couple of customization files into a running app: ```bash # 1. Setup (one time) "Create alias 'myapp' for production_server" # 2. Deploy both files at once "Deploy these files to myapp: - handler.py to /opt/myapp/apps/myapp/module/handler/ - handler.js to same location" # 3. Restart service "Run 'cd /opt/myapp && ./bin/restart' on myapp" ``` The single-command flow replaces the manual process of upload-to-tmp, chown, chmod, mv, restart — all handled by `ssh_deploy` in one shot: - ✅ Single command deployment - ✅ Automatic permission/ownership handling - ✅ Automatic backup before overwriting - ✅ No sudo password typed in the terminal ## Support For issues or questions: - Check server logs: `"Execute 'tail -f /var/log/syslog' on server"` - Test connection: `python tools/test-connection.py servername` - View aliases: `"List server aliases"`