Remote Development inside a Cloud VM with Visual Studio Code

In this article I describe how I use a Cloud VM for remote development inside Visual Studio Code and the steps I take to install some of the tools I usually use for development.

Configure SSH

All that is needed to connect Visual Studio Code to a remote machine is access via SSH. Usually in a cloud environment, the keys for SSH access are already setup during the creation of the virtual machine. If not, I set it up as described in my article about password-less SSH logins. Before I connect Visual Studio Code to the virtual machine, I usually log in via SSH and follow these steps to install some tools and configure the system:

Configure Hostname and Timezone

I make sure that the hostname and the timezone are set correct.

# check hostname
hostnamectl

# change hostname
sudo hostnamectl set-hostname foobar

# change also in /etc/hosts
sudo nano /etc/hosts

# check timezone
timedatectl

# set timezone
sudo timedatectl set-timezone Europe/Zurich

Disable the local DNS stub resolver

I disable the local DNS stub resolver in case I need another process to listen on port 53.

# disable local caching dns stub resolver
sudo sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf
sudo sh -c 'rm /etc/resolv.conf && ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf'
sudo systemctl restart systemd-resolved

Install Docker

I install Docker and make sure I’m able to run it without sudo.

# set up the docker repository
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager \
  --add-repo \
  https://download.docker.com/linux/fedora/docker-ce.repo

# install docker
sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin

# start docker
sudo systemctl enable docker
sudo systemctl start docker

# add user to docker group to run docker without sudo (requires logout/login to take effect)
sudo usermod -aG docker ${USER}

# check if in docker group
id -nG

Install Node.js via Node Version Manager

I install Node.js and some global packages.

# install node version manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
source ~/.bashrc

# install and use lts version
nvm install --lts
nvm use --lts

# install global packages
npm i -g yarn

Mount additional Disk

I mount an additional disk to store data on it in case I wipe the virtual machine.

# check disks
sudo fdisk -l

# partition disk
sudo parted /dev/sdb

# commands inside parted
mklabel gpt
mkpart primary 0GB 50GB
quit

# format disk
sudo mkfs.ext4 /dev/sdb

# mount disk
sudo mkdir /mnt/sdb
sudo mount /dev/sdb /mnt/sdb

# mount on boot
sudo nano /etc/fstab

# content to add
/dev/sdb     /mnt/sdb      ext4        defaults      0       0

# check if mounted
mount | grep sdb

I then create some symbolic links to that additional disk.

sudo mkdir /mnt/sdb/projects
sudo chown fedora:fedora /mnt/sdb/projects
ln -s /mnt/sdb/projects/ /home/fedora/projects

# link the docker volumes folder to the additional disk
sudo mkdir /mnt/sdb/docker-volumes
sudo systemctl stop docker
sudo rm -r /var/lib/docker/volumes
sudo ln -s /mnt/sdb/docker-volumes/ /var/lib/docker/volumes
sudo systemctl start docker