Setup VS Code for remote development
Well in order to setup a remote environment, you need a DigitalOcean account, you can use my referral code below to get $100 for 60 days just to try these things out ๐
After you're done creating an account, let's move to the next step
Creating a Droplet
On the left menu, click on the Droplet button
Create a new droplet by clicking on the
"Create Droplet"
butonChoose a distro of your flavour (I choose Ubuntu for ease of use) and select your desired specs
Select the datacenter region closest to you for better latency
For Authentication, choose SSH keys and click on the "New SSH Key"
button below
Use the command
ssh-keygen
to generate an SSH key, and the file would be stored under~/.ssh/id_rsa.pub
(for Mac and Linux) andC:\<user_name>\.ssh\id_rsa.pub
(for Windows)
NOTE: The command ssh-keygen
might not work on Windows CMD or Powershell, use Git Bash
Finally, click on
"Create Droplet"
at the bottom and wait for a few minutes for it to spin up
Connecting to droplet via SSH
Copy the IP address
Go to your terminal, and type ๐
ssh root@<IP_ADDRESS>
- Example ๐
ssh root@127.0.0.1
- Example ๐
Once inside the Droplet, create a new
sudo
userCreate a new user ๐
adduser vscode
Add it to
sudo
group ๐usermod -aG sudo vscode
Login as the user ๐
su - vscode
Create a new
ssh
directory ๐mkdir ~/.ssh
Create a new file inside it ๐
touch ~/.ssh/authorized_keys
Copy the contents of
id_rsa.pub
file, present on your local PC and paste it inside theauthorized_keys
file you created on your DropletTo paste the contents into
authorized_keys
file, you can use any cli based text editor,nano
example below ๐Press Ctrl-X, then Y and then Enter to save the file
[OPTIONAL] Type
chmod 600 ~/.ssh/authorized_keys
to make sure other users don't access this file
Press Ctrl-D twice to logout from the Droplet and test ssh connection of this new user
vscode
Type
ssh vscode@<IP_ADDRESS>
to connect to your Droplet, but now as the uservscode
instead ofroot
VS Code Remote development
Add the Remote - SSH extension to VS Code
Go to VS Code, click on the bottom left button
Choose Connect to host
Type in
ssh vscode@<IP_ADDRESS>
Choose your
ssh
folderThen you can connect to your Droplet for remote development
A new window will open, with remote connection to your Drop
Now, you can make use of the VMs resources to build applications on the cloud