Using SSH to connect to a server from Visual Studio (VS) can be done using the built-in features of Visual Studio Code (VS Code) or Visual Studio. Here are instructions:
Visual Studio Code
Install Remote Development Extension Pack
- Open Visual Studio Code.
Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressingCtrl+Shift+X
.
Search for "Remote Development" and install the Remote Development extension pack by Microsoft. - Open Remote-SSH After the extension is installed, press
F1
to open the Command Palette.
TypeRemote-SSH: Connect to Host...
and select it. - Configure SSH Hosts
You will be prompted to configure your SSH hosts.
If you don’t have any configured, selectConfigure SSH Hosts...
and then select a file (e.g.,~/.ssh/config
). - Add SSH Host Add a new SSH host entry in the
~/.ssh/config
file. It should look something like this
Host example
HostName example.com
User yourusername
IdentityFile ~/.ssh/id_rsa
Replace "example" with your server IP or a domain name. Replace yourusername with root or trydirect (secondary user)
Save the file.
5. Connect to SSH Host
Press F1
to open the Command Palette again.
Type Remote-SSH: Connect to Host...
and select your configured host (e.g., myserver
).
A new VS Code window will open, connected to your remote server.
Visual Studio
- Open Connection Manager
Open Visual Studio.
Go toTools
>Options
>Cross Platform
>Connection Manager
. - Add a New Connection
In the Connection Manager, click "Add"
.
SelectSSH
as the connection type. - Configure Connection
Enter the connection details:
Host name: The IP address or hostname of your server.
Port: The SSH port (default is 22).
User name: Your SSH username.
Authentication type: Choose either Password or Private Key.If using a private key, specify the path to your SSH key file.
Click "OK"
to save the connection. - Connect to Server
In the Connection Manager, select your newly added connection.
Click "Connect"
.
Additional Tips
- SSH Keys: Ensure you have copied your SSH PEM file to the right directory.
- Remote Explorer in VS Code: Once connected in VS Code, you can use the Remote Explorer sidebar to manage files, open terminals, and work with your remote environment.
By following these steps, you should be able to use SSH to connect to a server from both Visual Studio Code and Visual Studio.