How to connect to a remote server in vscode?
Aug 12, 2025 am 01:49 AM- Installing Remote - SSH extension; 2. Configure local SSH access and recommend using SSH keys; 3. Enter host information through the command panel or connect using ~/.ssh/config file; 4. After connecting, open a folder on the remote server to edit. VS Code will automatically install remote extensions and provide complete development functions. Before connecting, you need to ensure that the SSH service is normal, the firewall allows ports and the key permissions are correct, and finally achieve a remote development experience that is almost consistent with local development.
To connect to a remote server in VS Code, you can use the Remote - SSH extension, which allows you to edit and run code directly on a remote machine as if you were working locally. Here's how to set it up:

1. Install the Remote - SSH Extension
- Open VS Code.
- Go to the Extensions view by clicking the Extensions icon in the Activity Bar or pressing
Ctrl Shift X
. - Search for "Remote - SSH" (published by Microsoft).
- Click Install .
This extension enables SSH-based connections to remote servers, containers, or WSL.
2. Set Up SSH Access
Make sure you can connect to your remote server via SSH from your terminal or command line.

Requirements:
- SSH client installed on your local machine.
- On Windows: Use OpenSSH (available in Windows 10), or install via WSL.
- On macOS/Linux: SSH is usually pre-installed.
- Server address, username, and authentication method (password or SSH key).
Recommended: Use SSH Keys (More Secure)
Generate an SSH key pair if you don't have one:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Copy your public key to the remote server:

ssh-copy-id user@your-server-ip
Test connection:
ssh user@your-server-ip
3. Connect Using VS Code
Option A: Quick Connect via Command Palette
- Press
Ctrl Shift P
to open the Command Palette. - Type "Remote-SSH: Connect to Host..." and select it.
- Choose "Enter host name or URL..."
- Enter your SSH connection string:
user@your-server-ip
Example:
john@192.168.1.100
- Select an SSH config file to update (usually
~/.ssh/config
). - VS Code will save the host and try to connect.
Option B: Use SSH Config File
Edit your local SSH config file:
- Location:
~/.ssh/config
(create it if it doesn't exist) - Add an entry:
Host myserver HostName 192.168.1.100 User john Port 22 IdentityFile ~/.ssh/id_rsa
Now, in VS Code:
- Open Command Palette (
Ctrl Shift P
) - Run "Remote-SSH: Connect to Host..."
- Select "myserver" from the list
4. Open a Folder on the Remote Server
After connecting:
- You'll see a new VS Code window with a green indicator at the bottom-left showing the connection status.
- Click "Open Folder" in the remote window.
- Enter a path like
/home/john/projects
or/tmp
. - VS Code will display the remote files and allow full editing, terminal access, debugging, etc.
All extensions (like Python, ESLint) will be installed on the remote machine automatically.
Tips & Troubleshooting
Connection fails? Check:
- SSH service is running on the server (
sudo systemctl status ssh
) - Firewall allows port 22
- Correct username and IP
- Proper SSH key permissions (
chmod 600 ~/.ssh/id_rsa
)
- SSH service is running on the server (
Use different port? In SSH config:
Port 2222
Need to forward X11 or use specific options? Add them in
~/.ssh/config
.Working over slow connection? Consider compressing SSH:
Compression yes
That's it. Once connected, you can work on the remote server seamlessly with full IntelliSense, Git support, and terminals. The experience feels almost like local development.
Basically, just get SSH working first, then let the Remote - SSH extension do the rest.
The above is the detailed content of How to connect to a remote server in vscode?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ToautomaticallyformatPythoncodeinVSCode,installBlackusingpipinstallblack,installtheofficialMicrosoftPythonextension,setBlackastheformatterinsettings.jsonwith"python.formatting.provider":"black",enableformatonsavebyadding"edit

Yes,debuggingaPerlscriptinVSCodeispossibleusingthePerlDebugAdapterandPerlLanguageServerdespitelackingnativesupport.First,ensurePerlisinstalledandverifywithperl-v,theninstallthePerl::LanguageServermoduleviacpanPerl::LanguageServerorcpanmPerl::Language

To debug Python scripts, you need to first install the Python extension and configure the interpreter, then create a launch.json file to set the debugging configuration, then set a breakpoint in the code and press F5 to start the debugging. The script will be paused at the breakpoint, allowing checking variables and step-by-step execution. Finally, by checking the problem by viewing the console output, adding logs or adjusting parameters, etc., to ensure that the debugging process is simple and efficient after the environment is correct.

Yes, VSCode can debug Scala applications through Metals extension. First, install the Metals extension and import the Scala project. Make sure to enable the debug adapter and enable metals.enable-debugging-features in the settings. Then set breakpoints in the main method or test. Start debugging through the "Debug" option of F5 or the code lens. Debug parameters can be configured with launch.json to support local running and remote JVM additional debugging. During debugging, pay attention to ensuring that the code is executed and the build has been imported successfully, and finally implement variable checking and single-step execution functions similar to other IDEs.

Yes, VSCode can debug Rust programs, but it requires installing rust-analyzer, CodeLLDB extension and lldb or gdb debugger. After configuring launch.json and setting breakpoints, you can start debugging through F5, check variables, step-by-step execution and evaluate expressions. Although it is not as convenient as JavaScript and other languages, efficient debugging can be achieved through correct configuration.

Use drag and drop labels, right-click menus, shortcut keys (such as Ctrl\) or command panel to split the editor; 2. After splitting, you can form editing groups with vertical, horizontal or grid layouts; 3. Switch between groups by dragging labels or using shortcut keys (such as Ctrl 1/2/3); 4. You can adjust the segmentation size, move files between panes, and navigate errors across segmentation; 5. Use the right-click menu or the "JoinAllEditors" command to manage and merge segmentation; 6. You can configure the behavior of automatically opening files on the side in the settings; the segmentation editor is flexible, suitable for code comparison, writing and reconstruction, and can be seamlessly integrated into the workflow.

VSCode's portable mode allows running from USB drive or any folder without installing, all data is stored in local folders. 1. Download the ZIP version and decompress it to the target location; 2. Create a folder named data in the same directory as the executable file; 3. After VSCode detects the data folder, it automatically enables portable mode, and saves settings, extensions, caches, etc.; 4. Keep the environment consistent when used across devices, but be careful that the extensions relying on system tools may not work, and the version needs to be updated manually to finally realize a complete portable development environment.

VisualStudioCode supports automatic save function, which can be enabled through settings; after opening the settings, search for "AutoSave", select "Files:AutoSave" and set to "onFocusChange" or "afterDelay" and other modes. If you select "afterDelay", you can further set "files.autoSaveDelay" to adjust the delay time, or directly configure it by editing the settings.json file. After enabling it, it can effectively prevent the loss of work content without affecting the history of revocation. Finally, select the appropriate mode according to the personal workflow.
