To use VS Code Remote SSH for remote development on a VPS, install the "Remote - SSH" extension in VS Code, configure a connection using your VPS IP address and SSH key or password, and connect via the Remote Explorer. This setup allows you to edit files, run terminal commands, and debug code directly on your server as if the files were stored on your local machine, without needing to manually upload files via FTP or SFTP.
What You'll Need
- A computer with Visual Studio Code installed.
- A Virtual Private Server (VPS) running a supported Linux distribution (most common distros like Ubuntu, Debian, CentOS, and Fedora are supported).
- SSH access to the VPS (an IP address, a username, and either a password or a private SSH key).
- An active internet connection.
Step-by-Step
- Install the Remote - SSH Extension Open Visual Studio Code on your local machine. Click on the Extensions icon in the Activity Bar on the left side (or press Ctrl+Shift+X). In the search bar, type "Remote - SSH". Find the extension published by Microsoft and click Install. Note that menu labels and icons may differ slightly depending on your OS version or VS Code update.
- Generate and Upload SSH Keys (Recommended)
While you can use a password, SSH keys are more secure and prevent you from having to type your password every time you open a folder. On your local machine, open a terminal and run
ssh-keygen -t rsa -b 4096. Press Enter to accept the default file location. Once generated, copy the public key to your VPS. On Linux or macOS, usessh-copy-id username@your_vps_ip. On Windows, you can manually append the contents of yourid_rsa.pubfile to the~/.ssh/authorized_keysfile on your server. - Initiate the Remote Connection
Click the green "Open a Remote Window" button (a small icon with two brackets
><) located in the bottom-left corner of the VS Code window. A command palette will appear at the top of the screen. Select "Connect to Host..." from the dropdown menu. - Configure the Host
Select "+ Add New SSH Host..." from the list. VS Code will ask you to enter the SSH connection command. Type
ssh username@your_vps_ip(replacing username and IP with your actual credentials) and press Enter. VS Code will then ask which configuration file you want to update; usually, the default path (e.g.,C:\Users\Name\.ssh\configor~/.ssh/config) is the correct choice. - Connect to the VPS Click the green button in the bottom-left corner again, select "Connect to Host...", and choose the IP address or alias you just saved. A new VS Code window will open. If prompted, select the platform of the remote host (Linux, Windows, or macOS). If you are using a password instead of a key, you will be prompted to enter it at the top of the window.
- Open a Remote Folder Go to File > Open Folder. VS Code will show the file system of the VPS. Navigate to your project directory (e.g., /var/www/html or /home/username/project ) and click OK. The window will reload, and you will now see your remote files in the Explorer sidebar.
- Install Extensions on the Remote Server Notice that your local extensions are not automatically available on the VPS. Open the Extensions view again.
Common Mistakes
One of the most frequent errors is attempting to connect to a VPS that has a firewall blocking port 22. If you cannot connect, ensure that your VPS provider's security group or the server's internal firewall (like UFW or firewalld) allows incoming SSH traffic from your local IP address.
Another common mistake is using a user account that lacks the necessary permissions to edit files in the target directory. For example, if you open a folder in /var/www but your SSH user is not the owner of that folder, you will see "Permission Denied" when trying to save files. Avoid running the VS Code server as root; instead, change the ownership of your project folder using sudo chown -R username:username /path/to/folder on the VPS terminal.
Users often forget that the Remote SSH extension installs a small "VS Code Server" binary on the VPS. If your VPS is extremely resource-constrained (e.g., a micro-instance with 512MB of RAM), the server may crash or fail to start, leading to constant disconnection. Ensure your VPS has at least 1GB of RAM for a smooth experience.
Tips
To make connections faster, use an SSH config file. Instead of typing the IP every time, open your config file (File > Preferences > Settings, search for "Remote.SSH: Config File") and add an alias. For example:
Host my-vps HostName 123.456.78.90 User ubuntu IdentityFile ~/.ssh/id_rsaNow, you can simply select "my-vps" from the host list.
Use the integrated terminal (Ctrl+`) to run commands. This terminal is already authenticated and connected to your VPS, so you don't need to open a separate Putty or Terminal window to restart your web server or run git commands.
If you are working with a team, consider using a Jump Host (Bastion server). You can configure the ProxyJump directive in your SSH config file to route your VS Code connection through a secure gateway before hitting the internal VPS IP.
Troubleshooting
If the connection hangs or fails to connect, the first step is to check if you can connect via a standard terminal. Open your command prompt or terminal and run ssh username@your_vps_ip. If this fails, the issue is with your network, SSH keys, or server firewall, not with VS Code.
If you see an error stating "Could not establish connection to...", try clearing the remote server's VS Code components. On your local machine, open the Command Palette (Ctrl+Shift+P) and run "Remote-SSH: Kill VS Code Server on Host...". Select your host and try reconnecting. This forces VS Code to reinstall the server binary on the VPS, which fixes corrupted installation issues.
If you are prompted for a password repeatedly even though you have SSH keys set up, check the permissions of your .ssh folder on the VPS. The .ssh directory should have permissions 700 (drwx------) and the authorized_keys file should have permissions 600 (-rw-------). Use chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys to fix this.
In cases where the connection is unstable, check the "Remote-SSH: Log" in the Output panel. This log provides the exact SSH command VS Code is using. You can copy this command and run it in a separate terminal to see the detailed error messages provided by the SSH daemon.
Frequently Asked Questions
Does this slow down my VPS performance?
The VS Code Server is lightweight, but it does consume some CPU and RAM. On very small VPS instances, you may notice a slight increase in memory usage. If the server becomes unresponsive, consider increasing the VPS RAM or using a more lightweight editor like Vim.
Can I use this with a Windows VPS?
Yes, but the Windows VPS must have the OpenSSH Server feature enabled and configured. The process is similar, though you will select "Windows" as the platform when prompted by VS Code.
Is it safe to use passwords instead of SSH keys?
It is functional, but not recommended. Passwords are susceptible to brute-force attacks. SSH keys provide significantly stronger security and enable a seamless "single sign-on" experience within VS Code.
What happens if my internet connection drops?
VS Code will attempt to reconnect automatically. Any unsaved changes in the editor are typically cached locally, but since the terminal is running on the remote server, any running processes (like a dev server) will continue to run in the background unless they are tied to the specific SSH session.
Do I need to install VS Code on the VPS?
No. You only install the full VS Code application on your local computer. The extension automatically installs a headless "server" component on the VPS to handle file operations and terminal execution.
Can I use Git with Remote SSH?
Yes. You can use the built-in Source Control tab in VS Code. It will execute Git commands on the VPS, meaning your commits and pushes happen directly from the server to your repository.