Introduction - I want to build a Git server on GCP's free tier

9 min

language: ja bn en es hi pt ru zh-cn zh-tw

Hello, I'm incompetent.
I logged into GCP itself for the first time in a while, I guess?
It seems the last project I created was in 2016...
Image
It seems it gets updated when accessed, so My First Project feels like it's even older...
Wait, it's 2024 now, so that's 8 years ago... I must have been 15 years old!!!!
Time is cruel.
It feels like I've grown, but also regressed in some ways... no, regression also includes the meaning of evolution. Let's be positive.

As an aside, after eating delicious food on Friday, I feel like just lounging around.
Image
Image
Image

Introduction

I also have an OCI account, but I failed to choose the region correctly when I first registered, and I've left it untouched for over half a year? Even when I check it occasionally, there are never any free tier resources left.
I mean, for some reason, I'm the only one around me who can't use it... I probably thought 'minor regions surely have more resources!' and registered, which successfully blew up in my face.
Since I'll be using the Google ecosystem for work, I'd like to take this opportunity to set up a Git server on GCE.
Also, there's another reason: I just think it might be easier to back up data by having a Git server somewhere other than my home. Regarding the network, if only I use it, I probably won't be charged, and the reason I haven't used GCP until now is this:↓

Google Cloud Platform (GCP) free tier includes 1GB of outbound network traffic.

This is quite troublesome. Or rather, very troublesome. However, if I'm only using it as a personal Git server, it probably won't be much of a concern, so I've been vaguely thinking about it and planning to do it when I have free time.

I want to use it completely free

This kind of billing system becomes more confusing year by year, so you should always follow people who update their knowledge on completely free usage. Their detailed explanations are truly helpful.
Even so, I feel like the UI hasn't changed much from before, but it's more likely that my memory is just fading.
Create a VM instance with GCP's free tier
Server construction utilizing Google Cloud Platform (GCP) free tier

Quick user creation

As expected, the default Google account username feels strange, so I'll switch to root, create a user, and set it up for SSH access.

root@git-srv1:~# adduser haturatu
Adding user `haturatu' ...
Adding new group `haturatu' (1002) ...
Adding new user `haturatu' (1002) with group `haturatu (1002)' ...
Creating home directory `/home/haturatu' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for haturatu
Enter the new value, or press ENTER for the default
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] 
Adding new user `haturatu' to supplemental / extra groups `users' ...
Adding user `haturatu' to group `users' ...
root@git-srv1:~# usermod -aG sudo haturatu
root@git-srv1:~# su - haturatu
haturatu@git-srv1:~$ 

SSH configuration

haturatu@git-srv1:~$ vim .ssh/authorized_keys
haturatu@git-srv1:~$ chmod 600 .s
.ssh/                      .sudo_as_admin_successful  
haturatu@git-srv1:~$ chmod 600 .ssh/authorized_keys 
haturatu@git-srv1:~$ chmod 700 .ssh
haturatu@git-srv1:~$ 
haturatu@git-srv1:~$ sudo service sshd restart

Firewall settings

haturatu@git-srv1:~$ sudo apt install ufw
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  ufw
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 168 kB of archives.
After this operation, 878 kB of additional disk space will be used.
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B]
Get:2 https://deb.debian.org/debian bookworm/main amd64 ufw all 0.36.2-1 [168 kB]
Fetched 168 kB in 0s (1133 kB/s)
Preconfiguring packages ...
Selecting previously unselected package ufw.
(Reading database ... 68496 files and directories currently installed.)
Preparing to unpack .../archives/ufw_0.36.2-1_all.deb ...
Unpacking ufw (0.36.2-1) ...
Setting up ufw (0.36.2-1) ...

Creating config file /etc/ufw/before.rules with new version

Creating config file /etc/ufw/before6.rules with new version

Creating config file /etc/ufw/after.rules with new version

Creating config file /etc/ufw/after6.rules with new version
Created symlink /etc/systemd/system/multi-user.target.wants/ufw.service → /lib/systemd/system/ufw.service.
Processing triggers for rsyslog (8.2302.0-1) ...
Processing triggers for man-db (2.11.2-2) ...
haturatu@git-srv1:~$ sudo ufw allow 22/tcp
Rules updated
Rules updated (v6)
haturatu@git-srv1:~$ sudo ufw reload
Firewall not enabled (skipping reload) 
haturatu@git-srv1:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
haturatu@git-srv1:~$ sudo ufw reload
Firewall reloaded

Time to SSH

I've already placed the key in vim .ssh/authorized_keys, so all that's left is to SSH from the client PC (the laptop I'm operating).

alleycat:[haturatu]:~$ ssh -l haturatu gce-global-ip
The authenticity of host 'nyao-n' can't be established.
ED25519 key fingerprint is SHA256:nyannyan
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'nyannyan' (ED25519) to the list of known hosts.
Linux git-srv1 6.1.0-27-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.115-1 (2024-11-01) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
haturatu@git-srv1:~$ uname -a
Linux git-srv1 6.1.0-27-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.115-1 (2024-11-01) x86_64 GNU/Linux

It finished quickly!
Well, it got long because I kept pasting things, so Part 2 to follow.

Related Posts