Using Google Cloud free/always free products it has to offer we can create a small yet powerful free virtual machine (a Google Cloud Compute Engine product) to learn the basics of Linux administration or to leverage our skills into production.
cloud.google.com/free - 1 F1-micro instance per month |
|
All we need it's a google account with billing enabled. Indeed, even if the aforementioned F1-micro VM benefit of Google free lines of products (cloud.google.com/free), we still need billing enabled, to be able to use this free product. Of course, no one says it has to be the salary credit card here, I've managed to enable the billing using a Monese virtual card attached to a Monese bank account. So you can go ahead, open a Monese account, top-up some money via bank transfer or credit card if you prefer (needed only for Monese account activation) and you are ready to go. Anyway, if you don't have yet the billing activated, you should have at your choice a Google Cloud billing activation method to be used when required.
The first F1-micro Google Compute Virtual Machine
Go to Google Cloud Console, use the top-left hamburger navigation menu, and go to Compute Engine->VM Instances, then hit the 'Create [Instance]' button. And that's simple.
Here we have to stick with a VM configuration that fits into free/always-free Google Compute Engine offers. We have to choose the correct region, zone, machine type, and other settings accordingly to Google documentation
Compute Engine - 1 non-preemptible f1-micro VM instance per month |
|
Chose the desired machine name, a region from above, a zone, and set Machine configuration to f1-micro machine type, general purpose N1 series, and the Sandy Bridge CPU platform.
GCE VM configuration, step 1 |
|
The boot disk (30GB) is Debian 10, can be chosen by clicking the 'Change [boot disk]' where we select Debian 10 and change the size to 30GB - standard persistent disk.
GCE VM configuration, step 2, the Debian Linux boot disk and the service account |
|
The 'Identity and API access', Service account, could be set to 'No service account'.
The firewall: if you are going to use this machine for web-based projects then HTTP/S traffic should be allowed.
GCE VM configuration, step 3, firewall for HTTP trafic |
|
The machine security
Just check all security-related checkboxes around here and add the public part of an ssh access key (using ssh keys is the most secure method of accessing a headless Linux server).
GCE VM configuration, step 4, general security and ssh keys for terminal access |
|
help_outline To generate a secure pair of ssh keys use your terminal (from Ubuntu/macOS) and run:
ssh-keygen -t ecdsa -f ~/.ssh/a-ssh-key-name-here -C your-lowercased-name-here
cat ~/.ssh/a-ssh-key-name-here.pub
The machine disk/s
Here we can encrypt the disk by using a custom-supplied key and the code for generating such a disk encryption-key is:
echo -n '12345678901234567890123456789012' | base64
GCE VM configuration, step 5, hdd security |
|
The machine networking
To reserve a public IP we have to go to Networking and edit the 'default' Network interface. This is a two step action.
GCE VM configuration, step 6, the network and the public IP |
|
|
And that's it regarding the hardware configuration, take another look to ensure you will not be billed for the configuration, and if everything looks well then we can go ahead, save/create the machine then ssh connect to it after all (using a terminal emulator).
|
First steps inside our Debian Linux headless server
Connect to the server using the key generated with the ssh-keygen command, and the public IP address of the server:
ssh your-lowercased-name-here@12.34.56.789 -i ~/.ssh/a-ssh-key-name-here
As the F1-micro VM machine-type is using a small amount of memory, we can free-up some memory (actually ~100MB of RAM) by getting rid of some google injected software and by enabling 2GB of swap memory.
But first, we have to do some updates and small configs regarding the server configuration.
sudo apt update sudo apt install locales export PATH=$PATH:/usr/sbin sudo dpkg-reconfigure locales #look for and mark for installation en_US.UTF-8 sudo nano /etc/default/locale # add LANG and LC_ALL sequence to the file LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 # then close the file (Ctrl+X, Save (Y), Enter/Return) sudo apt install bash-completion sudo nano /etc/profile #add bash_completion (if --- fi sequence) to the end of the file if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi # then close the file (Ctrl+X, Save (Y), Enter/Return) # remove google software sudo apt remove --purge google-cloud-sdk python-google-compute-engine python3-google-compute-engine google-osconfig-agent google-compute-engine-oslogin google-guest-agent sudo apt autoremove #and upgrade sudo apt upgrade
Then we can allocate 2GB from HDD space to be used as SWAP memory.
sudo fallocate -l 2g /mnt/swap sudo chmod 600 /mnt/swap sudo mkswap /mnt/swap sudo swapon /mnt/swap echo '/mnt/swap swap swap defaults 0 0' | sudo tee -a /etc/fstab
And reboot the machine afterall sudo reboot
If after the reboot machine name (hostname) is changed (to debian), the command to change to the desired one is: sudo hostnamectl set-hostname your-desired-machine-name-as-declared-in google-console
, and if you want to monitor the server resources usage, the htop sudo apt install htop
will help a lot.
And that's it, the server is freed-up of unnecessary resource eatings, has 2GB or swap memory, and is available 24h for the need.
Resources used on the barebone Debian 10 Linux server |
|
Enjoy!