Skip to main content
Glama
README.md
# SSH MCP Server

A Model Context Protocol (MCP) server that provides SSH access to Unix/Linux servers through Claude Desktop. Execute commands, manage files, and monitor your remote servers using natural language!

## Features

- šŸ”Œ **Direct SSH Access** - Execute commands on your remote servers from Claude Desktop
- šŸ“ **File Management** - Upload, download, and browse files
- šŸ“Š **System Monitoring** - Get real-time system information (CPU, memory, disk, temperature)
- šŸ”„ **Process Management** - Check running processes
- šŸ“ **Multi-Command Scripts** - Execute multiple commands in sequence
- šŸ” **Secure** - Uses SSH key authentication

## Prerequisites

- Python 3.8 or higher
- Claude Desktop
- Remote Unix/Linux server with SSH enabled
- SSH key pair for authentication

## Installation

### 1. Clone the Repository

```bash
git clone https://github.com/paraporoco/SSH-MCP.git
cd SSH-MCP
```

### 2. Configure Your Connection

Copy the example configuration file:

```bash
# Windows PowerShell
Copy-Item config.example.json config.json

# Linux/Mac
cp config.example.json config.json
```

Edit `config.json` with your server details:

```json
{
  "ssh": {
    "host": "YOUR_SERVER_IP",
    "port": 22,
    "user": "YOUR_SSH_USERNAME",
    "key_path": "PATH_TO_YOUR_SSH_KEY"
  },
  "connection": {
    "timeout": 30,
    "default_command_timeout": 30
  }
}
```

**Example:**
```json
{
  "ssh": {
    "host": "192.168.1.100",
    "port": 22,
    "user": "username",
    "key_path": "C:\\Users\\YourName\\.ssh\\id_rsa"
  },
  "connection": {
    "timeout": 30,
    "default_command_timeout": 30
  }
}
```

### 3. Run Setup Script

#### Windows (PowerShell)

```powershell
.\setup.ps1
```

#### Linux/Mac

```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

### 4. Configure Claude Desktop

Add the MCP server to your Claude Desktop configuration:

**Configuration file location:**
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
- **Linux:** `~/.config/Claude/claude_desktop_config.json`

**Add this configuration:**

```json
{
  "mcpServers": {
    "ssh-server": {
      "command": "/FULL/PATH/TO/SSH-MCP/venv/Scripts/python.exe",
      "args": [
        "/FULL/PATH/TO/SSH-MCP/ssh_mcp_server.py"
      ]
    }
  }
}
```

**Windows Example:**
```json
{
  "mcpServers": {
    "ssh-server": {
      "command": "C:\\Users\\YourName\\Projects\\SSH-MCP\\venv\\Scripts\\python.exe",
      "args": [
        "C:\\Users\\YourName\\Projects\\SSH-MCP\\ssh_mcp_server.py"
      ]
    }
  }
}
```

**macOS/Linux Example:**
```json
{
  "mcpServers": {
    "ssh-server": {
      "command": "/home/username/SSH-MCP/venv/bin/python",
      "args": [
        "/home/username/SSH-MCP/ssh_mcp_server.py"
      ]
    }
  }
}
```

### 5. Restart Claude Desktop

Completely quit and restart Claude Desktop to load the MCP server.

## SSH Key Setup

If you don't have an SSH key pair, create one:

### On Windows (PowerShell):
```powershell
ssh-keygen -t rsa -b 4096 -f $env:USERPROFILE\.ssh\id_rsa
```

### On Linux/Mac:
```bash
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
```

Then copy your public key to the remote server:

```bash
ssh-copy-id -i ~/.ssh/id_rsa.pub username@server-ip
```

Or manually append the public key to `~/.ssh/authorized_keys` on your remote server.

## Available Tools

Once configured, you can use these tools in Claude Desktop through natural language:

### 1. **ssh_test_connection**
Test the SSH connection to your remote server.

**Example:** "Test my server connection"

### 2. **ssh_execute**
Execute a single command on your remote server.

**Examples:**
- "Run 'ls -la' on my server"
- "Check disk space on my server"
- "Show me the kernel version"

### 3. **ssh_execute_script**
Execute multiple commands in sequence.

**Example:** "Run these commands on my server: cd /home/user, ls -la, pwd"

### 4. **ssh_system_info**
Get comprehensive system information (OS, CPU, memory, disk, temperature).

**Example:** "Show me my server system info"

### 5. **ssh_list_files**
List files in a directory.

**Examples:**
- "List files in /home/user"
- "Show me what's in /var/log"

### 6. **ssh_read_file**
Read the contents of a file.

**Example:** "Read /etc/hostname from my server"

### 7. **ssh_check_process**
Check if a process is running.

**Example:** "Is nginx running on my server?"

### 8. **ssh_upload_file**
Upload a file from your computer to the remote server.

**Example:** "Upload C:\\myfile.txt to /home/user/myfile.txt"

### 9. **ssh_download_file**
Download a file from the remote server to your computer.

**Example:** "Download /var/log/syslog to C:\\logs\\syslog.txt"

## Usage Examples

Here are some natural language prompts you can use in Claude Desktop:

**System Monitoring:**
- "What's the server CPU temperature?"
- "How much RAM is being used?"
- "Show me disk usage"
- "What's the uptime?"

**File Operations:**
- "List all Python files in /home/user/projects"
- "Read the config file at /etc/nginx/nginx.conf"
- "Upload this script to my server"

**Process Management:**
- "Is docker running?"
- "Show me all Python processes"
- "Check if Apache is active"

**Command Execution:**
- "Update package lists with apt update"
- "Restart the nginx service"
- "Create a directory called /home/user/backup"

## Configuration Options

### Environment Variables (Alternative to config.json)

Instead of using `config.json`, you can set environment variables:

- `SSH_HOST` - Remote server IP address
- `SSH_USER` - SSH username
- `SSH_KEY_PATH` - Path to SSH private key
- `SSH_PORT` - SSH port (default: 22)
- `SSH_TIMEOUT` - Connection timeout in seconds (default: 30)
- `SSH_COMMAND_TIMEOUT` - Command execution timeout (default: 30)

## Troubleshooting

### Connection Issues

1. **Verify server is reachable:**
   ```bash
   ping YOUR_SERVER_IP
   ```

2. **Test SSH manually:**
   ```bash
   ssh -i /path/to/key username@server-ip
   ```

3. **Check SSH service on server:**
   ```bash
   sudo systemctl status ssh
   ```

4. **Verify SSH key permissions:**
   - Private key should be readable only by you (chmod 600)
   - Public key should be in `~/.ssh/authorized_keys` on the server

### MCP Server Not Loading

1. **Verify Python installation:**
   ```bash
   python --version  # Should be 3.8+
   ```

2. **Check virtual environment:**
   ```bash
   # Activate venv and test
   venv/Scripts/python.exe ssh_mcp_server.py  # Windows
   venv/bin/python ssh_mcp_server.py  # Linux/Mac
   ```

3. **Check Claude Desktop logs:**
   - Look for error messages in Claude Desktop console
   - Verify paths in `claude_desktop_config.json` are absolute

4. **Restart Claude Desktop completely:**
   - Close all instances
   - Check system tray for hidden instances
   - Restart and wait 10-15 seconds for MCP servers to initialize

### Permission Denied Errors

- Ensure your SSH key has correct permissions
- Verify the user has necessary permissions on the remote server
- Check that the SSH key is not password-protected (or use ssh-agent)

## Security Considerations

- āš ļø **Never commit `config.json` or SSH keys to version control**
- Use SSH key authentication instead of passwords
- Restrict SSH key permissions (chmod 600)
- Consider using a dedicated SSH user with limited permissions
- Keep your SSH keys secure and rotate them regularly
- Use firewall rules to restrict SSH access

## Development

### Running Tests

```bash
# Activate virtual environment
# Windows
.\venv\Scripts\activate

# Linux/Mac
source venv/bin/activate

# Run test connection
python test_connection.py
```

### Project Structure

```
SSH-MCP/
ā”œā”€ā”€ ssh_mcp_server.py       # Main MCP server
ā”œā”€ā”€ config.example.json     # Configuration template
ā”œā”€ā”€ config.json             # Your config (gitignored)
ā”œā”€ā”€ requirements.txt        # Python dependencies
ā”œā”€ā”€ setup.ps1              # Windows setup script
ā”œā”€ā”€ test_connection.ps1    # Windows test script
ā”œā”€ā”€ .gitignore            # Git ignore rules
└── README.md             # This file
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

MIT License - see [LICENSE](LICENSE) file for details

## Acknowledgments

- Built with [FastMCP](https://github.com/jlowin/fastmcp)
- Uses [Paramiko](https://www.paramiko.org/) for SSH connections
- Designed for [Claude Desktop](https://claude.ai/desktop)

## Support

For issues, questions, or contributions:
- Open an issue on GitHub
- Check existing issues for solutions
- Refer to the [MCP documentation](https://modelcontextprotocol.io/)

---

**Note:** This project is not officially affiliated with Anthropic or Claude Desktop.