Use Visual Studio Code Remote-SSH Plugin for Remote Development

I have multiple remote Ubuntu servers for running Python scripts. Before that, I had two choices, using SSH to login remotely for development, or copying file to the remote servers after local development. But these are not very efficient. The Remote-SSH plug-in is very suitable for such usage scenarios. It can be developed locally via SSH, but the code is saved and run on the remote server.

Installation

After pressing Ctrl+Shift+X, search for remote ssh and install it.

Configuration

Add remote server information, the configuration file format is as follows.

Host [Host Name]
    HostName [IP Address]
    User [User Name]

Now that the configuration is complete, we can start remote development.

SSH Public Key Authentication

The problem is that we need to enter a password every time we develop remotely. We can use SSH Public Key Authentication to simplify this process. Another advantage of this is that it can improve security, which can prevent password being brute-forced.

Use the ssh-keygen command to generate SSH Key. The generated file is in the directory C:\Users\{username}\.ssh. Using PowerShell to push the public key to the server.

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh username@ipaddr "cat >> .ssh/authorized_keys"

Now using ssh username@ipaddr to verify that we can SSH to the remote server without password.

For security reasons, we can also disable the SSH Password Authentication. Configure the /etc/ssh/sshd_config as follows.

PasswordAuthentication no
ChallengeResponseAuthentication no

Then sudo systemctl restart ssh to restart the ssh service. If everything is fine, we can only using SSH key to login to the remote server.

References

How to Set Up SSH Keys on Ubuntu 20.04
Windows 10 OpenSSH Equivalent of “ssh-copy-id”
2 Simple Steps to Set up Passwordless SSH Login on Ubuntu
Remote Development using SSH
5 Steps: Setup VS Code for Remote Development via SSH from Windows to Linux system
How To Use Visual Studio Code for Remote Development via the Remote-SSH Plugin

Leave a Reply

Your email address will not be published.