Visual Studio Code is a source-code editor application that is widely used by developers. In this VS Code, there are many extensions that can help developers in writing and developing their applications. On this occasion, I will discuss one of the extensions from VS Code that can be used to remotely access the server. If you usually use Terminal, PuTTy, KiTTy, Termius and so on. I suggest you to start trying remote servers using VS Code. Alright, according to the title of my article, I will provide information about how to remote server with visual studio code. Let’s start!
Install Extension Remote – SSH in Visual Studio Code ¶
The first step you have to do is :
- Open your Visual Studio Code application,
- Go to the Extensions Menu,
- Search “Remote – SSH”,
- Click Install.
Access Remote – SSH with Visual Studio Code ¶
After you install the Remote – SSH extension, you can immediately use it to remotely access the server by :
- Go to the Remote Explorer Menu,
- Click the Dropdown Button on SSH Targets,
- Click Button + to add SSH configuration to the server you want to remote,
- Enter the SSH configuration (example standard format: ssh -p [port] [user]@[host] ) for your server,
- Click Enter to confirm, then select the path where the configuration will be saved (default path : ~/.ssh/config ),
- Once saved, your server configuration will appear in the SSH Targets list,
- On the Host server that you have saved, Click the Button in the right corner (when hovered it will appear “Connect to Host in New Window”) to perform Remote SSH,
- Enter your SSH password (if prompted),
- Once connected, click Open Folder to open the default folder to be remote,
- Select the folder you want to remote, then click OK,
- If there is a notification “Do you trust the authors of the files in this folder?” , you can click “Yes, I trust the authors” to agree.
If you have a large number of remote servers, I suggest you to edit the ~/.ssh/config configuration file manually, so that when you want to remote server with vscode, all the servers you have will appear automatically in the SSH Targets list.
Creating SSH configuration file ¶
Open ~/.ssh/config file with any editor
vim ~/.ssh/config
Enter the configuration below as many servers as you have
Host [Hostname] HostName [IP Public] Port [Port SSH] User [User SSH] IdentityFile ~/.ssh/id_rsa
Little explanation :
Host [Hostname] | Replace [Hostname] section with the server name you want to provide. |
HostName [IP Public] | Replace [Public IP] section with your server’s public ip. |
Port [Port SSH] | Replace [SSH Port] section with your ssh server port. |
User [User SSH] | Replace [User SSH] section with your ssh server user. |
IdentityFile ~/.ssh/id_rsa | Use this if you want to save your ssh password with the command ssh-copy-id |
Examples like this :
Host lukems.com HostName 192.168.1.1 Port 22 User root IdentityFile ~/.ssh/id_rsa
Make that configuration as many servers as you have. If done, all you have to do is re-open Remote – SSH in vscode, then all your servers are listed on the SSH targets list. It will be more or less like this later :
Well, that’s the information about how to remote server with visual studio code that I can share. The rest, you can explore on your own about its use. Hopefully this information is useful for all readers. Thank you 😀
0 Comments