Part 2 - Configuring Raspberry Pi (Headless)

This is the second post in the series of how to host your own git server on a Raspberry Pi

You have successfully set your Raspberry Pi in the previous post. We will now go over several configurations that can benefit your Pi. Getting these in before setting up any software tools will be key, as some of those systems will depend on these configurations.

Open up a terminal, connect to your Pi, and follow the steps below.

As in any new system, you will need to create user accounts for yourself and others that will use the Raspberry Pi. To add a new user, you can run the adduser command with super user (sudo) permissions as below:

sudo adduser <USER>

For any newly added user to be able to run commands with super user permission as well, you need add them to sudo users group:

sudo adduser <USER> sudo

You can verify if the user is successfully added to sudo users group by running groups <USER> (see if the list contains sudo).

Adding a user to sudo users will allow them to run sudo when they need, but Ubuntu will ask them to verify their password with each sudo command. This can be a very frustrating experience for your users. To prevent this, you can add an entry for the user in sudoers.d directory to disable password checks:

echo ‘<USER> ALL=(ALL) NOPASSWD: ALL’ | sudo tee /etc/sudoers.d/010_<USER>-nopasswd

Repeat these steps for all users that you want to add to your Pi.

Once you added new accounts for each user, you might also want to update the root user account that comes with Ubuntu. For this, use one of your new user accounts with sudo permission to run following command. This will update the username from <OLD-USER> (ubuntu) to <NEW-USER>:

sudo usermod -l <NEW-USER> <OLD-USER>

Once the name is changed, you also will need to move the home folder of the root user to represent the new username:

sudo usermod -m -d /home/<NEW-USER> <NEW-USER>

Changing the name of a user will preserve their groups, though a new entry to sudoers.d has to be added to re-allow using sudo without password checks:

echo ‘<NEW-USER> ALL=(ALL) NOPASSWD: ALL’ | sudo tee /etc/sudoers.d/010_<NEW-USER>-nopasswd

Another useful configuration is to change the default hostname that comes with the operating system (ubuntu). Changing the name at this step will only affect the internal representation of Raspberry Pi.

sudo nano /etc/hostname

The command above will open the hostname file in the nano editor. Type in the desired hostname and save (CTRL+X).

In order to get a hostname that is also recognized by other devices in your local network, we need to adjust some settings in our router. If you haven’t already specified a <HOSTNAME> in the DHCP settings in Part 1, now is the time to do so (LAN > DHCP Server).

Router DHCP Server - Assigning a Hostname

Your router also comes with an option to set a domain name for the local network. This makes your devices accessible through the specified <DOMAIN>.

Router LAN Setting — Configuring Domain Name

Similarly, your Raspberry Pi will be accessible to computers on the local network as <HOSTNAME>.<DOMAIN>. You can use this address to establish an ssh connection with your Pi, or host local services accessible through HTTP.

Our goal is to host our local git server at https://git.<HOSTNAME>.<DOMAIN>

Congratulations — Configuring your Raspberry Pi wasn’t that hard after all. Next post is going to talk about setting up Postfix mail server, which will be the foundation for sending and receiving emails from your git server.

Systems Engineer, specialized in building Internet of Things (IoT) devices and applications. Harvesting crops at Google. 💻

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store