VS Code Remote-SSH Setup

Using the Remote Explorer extension in VS Code allows you to develop directly on a remote server as if it were local. This is the recommended workflow for managing complex Docker Compose stacks and configuration files.

🔑 1. Generate SSH Key Pair (Local Machine)

If you don’t already have a key pair, generate one on your laptop:

ssh-keygen -t ed25519 -C "[email protected]"
  • Press Enter to save to the default location (~/.ssh/id_ed25519).
  • (Optional) Set a passphrase for extra security.

📤 2. Deploy Public Key to Server

Copy your public key to the remote server to allow passwordless login:

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server-ip

If ssh-copy-id is not available, manually append the contents of id_ed25519.pub to ~/.ssh/authorized_keys on the server.

⚙️ 3. Configure VS Code SSH Host

  1. Install the “Remote - SSH” extension from Microsoft.
  2. Open the Command Palette (Cmd+Shift+P) and type “SSH: Open SSH Configuration File”.
  3. Select ~/.ssh/config and add your server details:
Host my-production-server
    HostName 1.2.3.4
    User root
    IdentityFile ~/.ssh/id_ed25519

🚀 4. Connect via Remote Explorer

  1. Click the Remote Explorer icon in the VS Code sidebar (looks like a small monitor).
  2. Find your host (my-production-server) in the list.
  3. Click the “Connect in New Window” icon.
  4. VS Code will install its server-side component and open the remote filesystem.

💡 Best Practices

  • SSH Agent: Use ssh-add to keep your key in memory so you don’t have to enter the passphrase repeatedly.
  • Port Forwarding: Use the “Ports” tab in VS Code to securely tunnel local services (like localhost:8080) from the server to your laptop’s browser.

Last Updated: 2026-04-22