`n

VS Code Remote Development Setup - Complete Guide

Published: September 25, 2024 | Reading time: 15 minutes

Quick Remote Setup

Get started with remote development in minutes:

Essential Extensions
# Install Remote Development Pack
- Remote - SSH
- Remote - Containers
- Remote - WSL
- Remote - Tunnels

# Quick SSH setup
Ctrl+Shift+P → "Remote-SSH: Connect to Host"
Enter: user@hostname
Enter password or use SSH key

Understanding Remote Development

VS Code Remote Development allows you to:

  • Code on remote servers - Access powerful cloud machines
  • Work in containers - Consistent development environments
  • Use WSL - Linux development on Windows
  • Share workspaces - Collaborate with team members
  • Access resources - Use remote databases, APIs, and services

Remote Development Types

Remote SSH

Connect to remote servers via SSH for development:

SSH Configuration
# SSH config file (~/.ssh/config)
Host dev-server
    HostName 192.168.1.100
    User developer
    Port 22
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ServerAliveInterval 60

# Connect to remote host
Ctrl+Shift+P → "Remote-SSH: Connect to Host"
Select: dev-server
Enter password if prompted

Remote Containers

Develop inside Docker containers for consistent environments:

Dev Container Setup
# .devcontainer/devcontainer.json
{
  "name": "Node.js Development",
  "image": "mcr.microsoft.com/vscode/devcontainers/javascript-node:18",
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {}
  },
  "customizations": {
    "vscode": {
      "extensions": [
        "esbenp.prettier-vscode",
        "dbaeumer.vscode-eslint"
      ]
    }
  },
  "forwardPorts": [3000, 8080],
  "postCreateCommand": "npm install"
}

Remote WSL

Use Windows Subsystem for Linux for development:

WSL Setup
# Install WSL
wsl --install

# Install specific distribution
wsl --install -d Ubuntu-22.04

# Connect to WSL
Ctrl+Shift+P → "WSL: Connect to WSL"
Select distribution: Ubuntu-22.04

# WSL configuration
# .wslconfig (Windows)
[wsl2]
memory=4GB
processors=2
swap=2GB

SSH Key Setup

Generate SSH Keys

SSH Key Generation
# Generate SSH key pair
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"

# Save to default location
Enter file in which to save the key: ~/.ssh/id_rsa
Enter passphrase (optional): [your-passphrase]

# Copy public key to server
ssh-copy-id user@hostname
# Or manually copy
cat ~/.ssh/id_rsa.pub | ssh user@hostname "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

SSH Agent Setup

SSH Agent Configuration
# Start SSH agent
eval "$(ssh-agent -s)"

# Add SSH key
ssh-add ~/.ssh/id_rsa

# Add to shell profile
echo 'eval "$(ssh-agent -s)"' >> ~/.bashrc
echo 'ssh-add ~/.ssh/id_rsa' >> ~/.bashrc

# Test connection
ssh -T user@hostname

Remote Development Configuration

SSH Configuration File

Advanced SSH Config
# ~/.ssh/config
Host production
    HostName prod.example.com
    User deploy
    Port 22
    IdentityFile ~/.ssh/prod_key
    ForwardAgent yes
    ServerAliveInterval 60
    ServerAliveCountMax 3
    Compression yes
    ControlMaster auto
    ControlPath ~/.ssh/control-%r@%h:%p
    ControlPersist 10m

Host staging
    HostName staging.example.com
    User developer
    Port 2222
    IdentityFile ~/.ssh/staging_key
    ForwardAgent yes
    LocalForward 3000 localhost:3000
    LocalForward 5432 localhost:5432

Remote Settings

Remote Development Settings
{
  // Remote SSH settings
  "remote.SSH.remotePlatform": {
    "production": "linux",
    "staging": "linux"
  },
  "remote.SSH.configFile": "~/.ssh/config",
  "remote.SSH.useLocalServer": true,
  "remote.SSH.enableDynamicForwarding": true,
  
  // Remote containers settings
  "remote.containers.defaultExtensions": [
    "ms-vscode.vscode-json",
    "esbenp.prettier-vscode"
  ],
  "remote.containers.dockerPath": "docker",
  
  // Remote WSL settings
  "remote.WSL.fileWatcher.polling": true,
  "remote.WSL.useShellEnvironment": true
}

Container Development

Dev Container Configuration

Complete Dev Container
# .devcontainer/devcontainer.json
{
  "name": "Full Stack Development",
  "dockerComposeFile": "docker-compose.yml",
  "service": "app",
  "workspaceFolder": "/workspace",
  
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {},
    "ghcr.io/devcontainers/features/git:1": {},
    "ghcr.io/devcontainers/features/node:1": {
      "version": "18"
    }
  },
  
  "customizations": {
    "vscode": {
      "extensions": [
        "esbenp.prettier-vscode",
        "dbaeumer.vscode-eslint",
        "ms-vscode.vscode-typescript-next",
        "bradlc.vscode-tailwindcss"
      ],
      "settings": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
          "source.fixAll.eslint": true
        }
      }
    }
  },
  
  "forwardPorts": [3000, 8080, 5432],
  "portsAttributes": {
    "3000": {
      "label": "Frontend",
      "onAutoForward": "notify"
    },
    "8080": {
      "label": "Backend",
      "onAutoForward": "notify"
    }
  },
  
  "postCreateCommand": "npm install",
  "postStartCommand": "npm run dev"
}

Docker Compose for Development

Docker Compose Setup
# .devcontainer/docker-compose.yml
version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ../..:/workspaces:cached
    command: sleep infinity
    networks:
      - dev-network
    depends_on:
      - db
      - redis

  db:
    image: postgres:15
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: developer
      POSTGRES_PASSWORD: password
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - dev-network

  redis:
    image: redis:7
    ports:
      - "6379:6379"
    networks:
      - dev-network

volumes:
  postgres-data:

networks:
  dev-network:
    driver: bridge

Port Forwarding

Automatic Port Forwarding

Port Forwarding Configuration
{
  // Automatic port forwarding
  "remote.autoForwardPorts": true,
  "remote.autoForwardPortsSource": "hybrid",
  
  // Port forwarding settings
  "remote.portForwarding.showNotification": true,
  "remote.portForwarding.includeLocalhost": true,
  
  // Specific port configurations
  "remote.portsAttributes": {
    "3000": {
      "label": "React Dev Server",
      "onAutoForward": "notify"
    },
    "8080": {
      "label": "API Server",
      "onAutoForward": "silent"
    },
    "5432": {
      "label": "PostgreSQL",
      "onAutoForward": "silent"
    }
  }
}

Manual Port Forwarding

Manual Port Commands
// Forward ports manually
Ctrl+Shift+P → "Remote-SSH: Forward Port"
Enter port number: 3000
Enter local port: 3000

// View forwarded ports
Ctrl+Shift+P → "Remote-SSH: Show Forwarded Ports"

// Stop port forwarding
Right-click port → "Stop Forwarding"

// Port forwarding in SSH config
Host dev-server
    HostName 192.168.1.100
    User developer
    LocalForward 3000 localhost:3000
    LocalForward 8080 localhost:8080
    LocalForward 5432 localhost:5432

Remote Extensions

Extension Management

Remote Extension Setup
// Install extensions on remote
Ctrl+Shift+X → Search extension → Install
Extensions are installed on remote machine

// Sync extensions
Ctrl+Shift+P → "Extensions: Sync Extensions"
Choose sync method:
- Sync to remote
- Sync from remote
- Manual sync

// Extension recommendations
// .vscode/extensions.json
{
  "recommendations": [
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "ms-vscode.vscode-typescript-next"
  ]
}

Performance Optimization

Remote Performance Settings

Performance Configuration
{
  // Remote performance
  "remote.SSH.useLocalServer": true,
  "remote.SSH.enableDynamicForwarding": true,
  "remote.SSH.remoteServerListenOnSocket": true,
  
  // File watching
  "remote.autoForwardPorts": true,
  "remote.autoForwardPortsSource": "hybrid",
  
  // Terminal performance
  "terminal.integrated.shell.linux": "/bin/bash",
  "terminal.integrated.shellArgs.linux": ["-l"],
  
  // Editor performance
  "editor.suggest.snippetsPreventQuickSuggestions": false,
  "editor.quickSuggestions": {
    "other": true,
    "comments": false,
    "strings": true
  }
}

Troubleshooting

Common Issues

Troubleshooting Steps
// Connection issues
1. Check SSH key permissions: chmod 600 ~/.ssh/id_rsa
2. Verify SSH config: ssh -T user@hostname
3. Check firewall settings
4. Restart SSH service: sudo systemctl restart ssh

// Extension issues
1. Reload window: Ctrl+Shift+P → "Developer: Reload Window"
2. Check extension compatibility
3. Reinstall extensions on remote
4. Clear extension cache

// Performance issues
1. Check network latency
2. Optimize file watching
3. Use local server mode
4. Reduce extension count

Debug Remote Connections

Debug Commands
// Enable debug logging
Ctrl+Shift+P → "Remote-SSH: Show Log"
Check for error messages

// Test SSH connection
ssh -v user@hostname
ssh -vv user@hostname
ssh -vvv user@hostname

// Check remote server
ssh user@hostname "ps aux | grep vscode"
ssh user@hostname "netstat -tlnp | grep :22"

Security Considerations

SSH Security

Security Best Practices

  • Use SSH keys instead of passwords
  • Disable password authentication
  • Use strong passphrases
  • Regularly rotate SSH keys

Network Security

  • Use VPN for remote access
  • Configure firewall rules
  • Limit SSH access by IP
  • Use non-standard SSH ports

Summary

VS Code Remote Development provides powerful capabilities:

  • SSH Development: Code on remote servers
  • Container Development: Consistent environments
  • WSL Integration: Linux development on Windows
  • Port Forwarding: Access remote services
  • Extension Sync: Seamless development experience

Need More Help?

Struggling with remote development setup or need help with specific remote configurations? Our remote development experts can help you set up the perfect remote environment.

Get Remote Development Help