Claude Code can SSH into remote servers and run commands, as long as the connection is non-interactive (no password prompts, no 2FA).
Requirements
- SSH key-based auth - The server must accept your SSH key without a password
- Passwordless sudo (optional) - If you want Claude to run sudo commands
Setup Steps
1. Generate SSH key (if you don't have one)
2. Copy your public key to the server
3. Create an SSH config alias (optional but nice)
Edit ~/.ssh/config:
Now you can just use ssh myserver instead of the full command.
4. Test it works without prompts
If this runs without asking for anything, Claude can use it.
5. Enable passwordless sudo (optional)
On the server, run:
Add this line at the end (replace claude with your username):
How Claude Uses SSH
Claude runs each command as a separate SSH call:
There's no persistent session - each command connects, runs, and disconnects. This means:
- No interactive programs (vim, htop, etc.)
- No environment variables carrying over between commands
- Each command must be self-contained
Example Commands Claude Can Run
Troubleshooting
"Permission denied" - Key not set up properly, check ~/.ssh/authorized_keys on server
"Host key verification failed" - First time connecting, SSH manually once to accept the host key
Sudo asks for password - Add NOPASSWD rule in sudoers (step 5)
Command hangs - Probably waiting for input, make sure the command is non-interactive
Last updated on