Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Connect to VPS with VS Code Remote SSH

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to connect to your Virtual Private Server (VPS) directly from Visual Studio Code using the Remote – SSH extension. Instead of switching between a terminal and your editor, you can edit files, run commands, and debug your server code as if it were on your local machine. You'll need a VPS with SSH access (username, IP address, and password or key), and Visual Studio Code installed on your local computer.

What You'll Need

  • A VPS with SSH enabled (most providers do this by default).
  • The VPS's IP address and the username for an account on it (often root or a user you created).
  • Authentication: either a password or an SSH private key. If using a key, you'll need the private key file (e.g., id_rsa) on your local machine.
  • Visual Studio Code installed on your computer.
  • An SSH client available on your system: on Windows 10/11, OpenSSH is usually built-in; on macOS and Linux, it's preinstalled.

Step-by-Step

  1. Install the Remote – SSH extension. Open VS Code, go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X), search for “Remote – SSH”, and install the one published by Microsoft.
  2. Open the Remote Explorer. Click the green icon in the bottom-left corner of the VS Code window (or press F1 and type “Remote-SSH”). This opens the Remote Explorer sidebar.
  3. Add a new SSH host. In the Remote Explorer, click the gear icon (or the “+” next to “SSH Targets”) and choose “Add New SSH Host”.
  4. Enter the SSH connection command. Type something like user@your-server-ip (e.g., root@192.168.1.100). If you use a custom port, add -p port (e.g., ssh user@ip -p 2222). Press Enter.
  5. Select the SSH configuration file. VS Code will ask where to save the host. Choose the default location (usually ~/.ssh/config on Linux/macOS or C:\Users\YourName\.ssh\config on Windows).
  6. Connect to the host. In the Remote Explorer, you'll see the new host listed. Click the folder icon (or the arrow) next to it to connect. A new VS Code window will open.
  7. Authenticate. If you use a password, VS Code will prompt you for it. If you use an SSH key, make sure your key is in the default location (~/.ssh/id_rsa) or specify it in the SSH config file (see Tips).
  8. Open a folder on the VPS. Once connected, you'll see a “Connect to Host” prompt. Click “Linux” (or your server's OS) and then select the folder you want to open (e.g., /var/www or /home/user). You can also use File > Open Folder and type the path.
  9. Start working. You can now edit files, open terminals (Terminal > New Terminal), and run commands directly on the VPS. The terminal will be a remote shell.

Common Mistakes

  • Forgetting to specify the SSH port. If your VPS uses a non-standard port, you must include -p port in the host definition; otherwise, the connection will fail.
  • Using the wrong username. Make sure you use a username that exists on the server. Some providers use root by default, others create a user like ubuntu or deploy.
  • Not having an SSH client installed. On older Windows versions, you may need to install OpenSSH manually. Check by running ssh in a terminal.
  • Ignoring the SSH key permissions. On Linux/macOS, the private key file must have permissions set to 600 (read/write for owner only). If not, SSH will reject it.
  • Typing the IP address incorrectly. A single digit wrong will cause a timeout or “connection refused”. Double-check the IP.

Tips

  • Use SSH keys instead of passwords. They're more secure and allow passwordless login. Generate a key with ssh-keygen and copy it to the server with ssh-copy-id user@ip.
  • Edit the SSH config file for advanced options. You can add multiple hosts, specify ports, usernames, and key files. This makes connecting faster.
  • Install extensions on the remote. Some extensions (like Python or Live Server) need to be installed on the remote side. VS Code will prompt you to install them when you open a relevant file.
  • Use the “Remote Explorer” to quickly switch hosts. You don't need to type the command each time; just click the host.
  • If you're behind a firewall, test basic SSH first. Run ssh user@ip in a terminal to confirm the connection works before trying VS Code.

Troubleshooting

  • “Could not establish connection to 'host'” – Check the SSH output (View > Output, select “Remote – SSH”). Common causes: wrong IP, port, or username; firewall blocking port 22; or the SSH service is not running on the server. Try ssh user@ip in a terminal to see the exact error.
  • “Permission denied (publickey,password)” – This means authentication failed. Verify your username and password, or that your key is correctly added to the server's ~/.ssh/authorized_keys.
  • “Host key verification failed” – This happens when the server's key has changed. Remove the old key from ~/.ssh/known_hosts (or the Windows equivalent) and try again.
  • VS Code hangs on “Setting up SSH Host” – This is often due to network issues or a slow server. Wait a bit, or try increasing the timeout in the SSH config (ConnectTimeout 30).
  • No terminal opens – Make sure you're connected to the remote (bottom-left should show “SSH: hostname”). Then open a new terminal with Ctrl+`.
  • Extensions not working – Some extensions require installation on the remote. Go to the Extensions view, find the extension, and click “Install in SSH: hostname”.

Frequently Asked Questions

Can I use VS Code Remote SSH on Windows?

Yes, as long as you have an SSH client (OpenSSH is built-in on Windows 10/11). You may need to enable it in Windows Features if it's not active.

Do I need a static IP for my VPS?

Not strictly, but a static IP makes it easier to connect consistently. If your IP changes, you'll need to update the SSH config each time.

Can I connect to multiple VPSs at once?

Yes, you can open multiple VS Code windows, each connected to a different host. Or you can use the Remote Explorer to switch between hosts in the same window, though only one is active at a time.

Is it safe to use password authentication?

It's less secure than key-based authentication because passwords can be brute-forced. For production servers, use SSH keys and disable password login.

What if my VPS uses a non-standard SSH port?

You can specify the port in the SSH config or in the connection command with -p. For example: ssh user@ip -p 2222.

Can I edit files as root?

Yes, if you connect as root. Otherwise, you may need to use sudo from the terminal to edit system files. VS Code doesn't support sudo directly, but you can open the file with a command like sudo code --remote ssh-remote+host /path (requires the Remote SSH extension).