try.directtry.direct

SSH from Visual Studio Code (VS Code) or Visual Studio

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

  1. 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 pressing Ctrl+Shift+X.
    Search for "Remote Development" and install the Remote Development extension pack by Microsoft.
  2. Open Remote-SSH After the extension is installed, press F1 to open the Command Palette.
    Type Remote-SSH: Connect to Host... and select it.
  3. Configure SSH Hosts
    You will be prompted to configure your SSH hosts.
    If you don’t have any configured, select Configure SSH Hosts... and then select a file (e.g., ~/.ssh/config).
  4. 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

  1. Open Connection Manager
    Open Visual Studio.
    Go to Tools > Options > Cross Platform > Connection Manager.
  2. Add a New Connection
    In the Connection Manager, click "Add".
    Select SSH as the connection type.
  3. 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.
  4. 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.