Skip to content

Instantly share code, notes, and snippets.

@mukaschultze
Last active March 6, 2022 01:50
Show Gist options
  • Save mukaschultze/1167a104ca245a57508e4df66d6c686a to your computer and use it in GitHub Desktop.
Save mukaschultze/1167a104ca245a57508e4df66d6c686a to your computer and use it in GitHub Desktop.
Free Arch Linux on GCP

Arch Linux on GCP

If you want to learn more about this image check out its GitHub repo

VM Setup

Download and setup gcloud SDK on your machine.

Create a new instance with the following settings:

export INSTANCE_NAME='my-machine'
export USERNAME=$USER
export SSH_KEY=$(cat ~/.ssh/id_ed25519.pub)

gcloud compute instances create $INSTANCE_NAME \
        --zone="us-east1-b" \
        --machine-type="e2-micro" \
        --metadata="ssh-keys=${USERNAME}:${SSH_KEY}" \
        --no-service-account \
        --no-scopes \
        --boot-disk-size=30 \
        --image-project="arch-linux-gce" \
        --image-family="arch"

The settings above should only use your free tier quota and won't be charged unless you have other projects on your account that are already using the free tier.

SSH into the machine via the IP shown in the output of the previous command and the username set in $USERNAME. If you missed the output you can run gcloud compute instances lists to list the running instances and their IPs.

Update the machine and keyring:

# Run the following commands as root
sudo bash

# Replace default mirrors with the official arch mirror.
echo 'Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist

# Update keyring and then update the system. Check the troubleshooting guide in
# the link below if you're having package signature errors.
# https://wiki.archlinux.org/title/Pacman/Package_signing#Invalid_signature_errors
pacman -Syy archlinux-keyring && pacman -Syyuu

# You can now reboot your system to make sure everything is working fine.
reboot

Sane defaults

SSHD Config

By default, the image comes with PermitRootLogin and PasswordAuthentication disabled, so no need to change sshd configs.

Pacman configs

By default the image doesn't come with any text editor installed, you can install one by sudo pacman -S nano. You can then run EDITOR=nano sudoedit /etc/pacman.conf and uncommend the #Color line to enable colored output from pacman. You may also want to add the ParallelDownloads = 20 below the #VerbosePkgLists line to speed up package installations.

User password and sudo acesss

The installation image creates a default user password, you can change that by running sudo passwd "$USER".

By default, google manages root access for users through a daemon by adding and removing the google_sudoers group to users.

Common packages

Yay

You might want to install yay as an AUR helper, you can do so by running:

sudo pacman -S --needed git base-devel
cd /tmp
git clone https://aur.archlinux.org/yay-bin.git
cd yay-bin
makepkg -si
yay -Y --gendb && yay -Syu --devel && yay -Y --devel --save

UFW

You can install and enable Uncomplicated Firewall (UFW) easily by running:

yay -S ufw # Or 'pacman -S' if you haven't installed yay
sudo ufw allow ssh
sudo ufw enable

Docker

Install docker and docker-compose, then enable and start its services:

yay -S docker docker-compose # Or 'pacman -S' if you haven't installed yay
sudo systemctl enable --now docker.service
sudo systemctl enable --now containerd.service
sudo usermod -aG docker $USER # Add current user to docker group
newgrp docker # Reload groups

neofetch output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment