11 SSH in VS Code
11.1 Installing the Remote-SSH Extension
First, install the Remote-SSH extension in VS Code:
- Open VS Code
- Press
Cmd+Shift+X
to open Extensions - Search for “Remote - SSH”
- Install the official extension by Microsoft (it has a blue remote icon)
11.2 Connecting to a Remote Server
Once installed, you have several ways to connect:
Method 1 - Command Palette (Quick Connect):
- Press
Cmd+Shift+P
to open Command Palette - Type “Remote-SSH: Connect to Host…”
- Enter your connection string:
username@hostname
- Enter the server password (or it will use your SSH key automatically)
Method 2 - Using SSH Config (Recommended):
Since you’ve already set up your ~/.ssh/config
file, this is even easier:
- Press
Cmd+Shift+P
- Type “Remote-SSH: Connect to Host…”
- You’ll see your configured hosts (like “myserver”, “dataserver”)
- Select one and VS Code will connect
Method 3 - From the Remote Explorer:
- Click the Remote Explorer icon in the left sidebar (looks like a monitor with a small icon)
- You’ll see your SSH targets
- Click the arrow next to a host to connect
11.3 First Connection
When you first connect to a server:
- VS Code will ask about the server’s platform (Linux, macOS, Windows) - usually Linux
- It will install VS Code Server on the remote machine (happens automatically)
- A new VS Code window opens connected to the remote server
- Look at the bottom-left corner - you’ll see “SSH: servername” indicating you’re connected
11.4 Working with Remote Files
Once connected:
- Open a folder: Click “Open Folder” and browse the remote filesystem
- Open terminal: Press
Ctrl+`
to open a terminal on the remote server - Install extensions: Extensions can be installed locally or on the remote server
11.5 Useful Features for Your Workflow
1. Port Forwarding (great for Jupyter notebooks or web apps):
# If you run Jupyter on the remote server
jupyter notebook --no-browser --port=8888
VS Code automatically forwards the port. You can access it at localhost:8888
on your Mac.
2. Remote Explorer Settings:
Add this to your VS Code settings (Cmd+,
):
{
"remote.SSH.defaultExtensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter"
],
"remote.SSH.connectTimeout": 30
}
3. Managing Multiple Connections:
You can have multiple VS Code windows open, each connected to different servers. Great for comparing code across environments.
11.6 Python Development Setup
Since you work with Python, after connecting to a remote server:
- Install Python extension on the remote server (it will prompt you)
- Select Python interpreter:
Cmd+Shift+P
→ “Python: Select Interpreter” - Choose the appropriate conda/virtual environment
Example workflow for your radiology AI projects:
# In VS Code terminal on remote server
conda activate radiology-ai
cd /home/kittipos/projects/ct-scan-analysis
# Now you can edit and run Python files directly
11.7 Tips for Data Science Work
1. Jupyter Notebooks: - Open .ipynb
files directly in VS Code - They’ll run on the remote server’s compute resources - Great for training models on powerful GPUs
2. Large Data Files: - Use the remote server’s storage - Files stay on the server (no need to download) - Process data where it lives
3. Background Processes:
# Start long-running training in VS Code terminal
nohup python train_model.py > training.log 2>&1 &
# You can disconnect and the process continues
11.8 Common Configuration
Add to your VS Code settings.json for better remote experience:
{
"remote.SSH.showLoginTerminal": true,
"remote.SSH.configFile": "~/.ssh/config",
"remote.SSH.remotePlatform": {
"myserver": "linux",
"dataserver": "linux"
}
}
11.9 Troubleshooting
If you have connection issues:
Test SSH first: Make sure
ssh myserver
works in terminalCheck Remote-SSH output: View → Output → Select “Remote-SSH” from dropdown
Clear VS Code Server: Sometimes you need to remove and reinstall:
ssh myserver rm -rf ~/.vscode-server
11.10 Pro Tips
Save Workspace: Once connected and folder opened, save as workspace (
File → Save Workspace As...
) for quick access laterSync Settings: Enable Settings Sync to have your preferences on all remote connections
GPU Monitoring: If using GPU servers, add GPU monitoring extensions to track usage while training models
Would you like help setting up any specific aspects, like configuring Python environments or setting up port forwarding for Jupyter notebooks?