Part 2 - Configuring Raspberry Pi (Headless)

Yiğit (Yeet) Uyan
4 min readFeb 15, 2021

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.

1. Create User Accounts

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.

2. Update Root User (Optional)

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

3. Change Internal Hostname

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).

4. Change External Hostname

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

5. Set Local Domain Name

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 chapter is going to talk about setting up Postfix mail server, which will be the foundation for sending and receiving emails from your git server.

You can follow my future articles on building Internet of Things devices and general chat regarding to life at Google at Baking Pi — An IoT Blog. :)

--

--

Yiğit (Yeet) Uyan

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