Simple Debian 11 (Bullseye) Media Server

Published on August 31, 2022 at 9:44 pm by LEW

Introduction

Late last night, for a variety of frustrating reasons, I decided to do a complete rebuild of my local cloud server as a very basic media server using plain vanilla Debian 11 (Bullseye).

The current version of the cloud server I am running is similar to the previous verison I used prior to making the big move. That was back when I was not behind Carrier Grade Network Address Translation (CGNAT), and I could access the cloud server via the Internet using Dynamic Domain Name Service (DDNS).

With my current Internet Service Provider (ISP), my priorities have boon forcibly changed. Without jumping through several of hoops of setting up a Virtual Private Network (VPN) for port forwarding, it is basically impossible to access any  local server from the Internet. So there is not a lot of incentive to continue using cloud storage, when I can get better performance on the same hardware from a Network Attached Storage (NAS) solution.

The final coffin nail was a small bit of upgrade hell I went through with the cloud server software. Running a cloud server is a bit more complex than simple file sharing. And it is not the first time I have had a cloud server break during upgrade. This time, as previously stated, there was no good reason to keep the cloud server. A rebuild was much quicker and simpler.

Reviewing the Options

I looked at a number of options like “TrueNas Scale”, “Open Media Vault”, “Rockstor”and “Openfiler” to name a few. Something different and really interesting I did this time around, was spend a significant amount of time looking at other peoples problems by browsing the various forums and wikis. This helped convince me I needed something simple that I understood in its entirety, and could easily fix when the need arose.

Additionally, a realistic review of my actual needs showed me I needed something simpler. Most of the per-builds offered a lot of features, and introduce a lot of complexity I don’t really need or want.

That is why, in the end, I decided to cobble together a NAS from plain vanilla Debian.

Hardware Overview

As is my common practice when starting a new project of this type, I like to review the hardware I will be using first. This can sometimes have an effect on the later configuration, and it is better to know about it now.

For the base of this build I am using an off the shelf mini PC from the year 2015. The entire computer is about 11.5cm x 11.5cm x 3.5cm.

It uses a CORE I5-5300 dual core 2.3 GHz processor and has 16 GB of DDR3 RAM. It has a 232 GB M.2 drive installed. There is space in the case for a 2.5” drive, which I am filling with a 1.8 TB 5400 RPM SATA hard drive from one of my spare parts bins.

There are a several USB 3 ports and a 1GHz Ethernet port. However the only video out is through a mini display port. So this will require an adapter for the initial setup.

The computer uses a 19 V DC power adapter, and I estimate it should consume no more than 10 to 15 watts running under average load.

Software Overview

For the OS I thought about Ubuntu server for about a second then rejected the idea. In the past I have had a large number of issues with it, and I am not a fan of Conical’s snap package manager (as far as I can tell parts of it appear to be somewhat proprietary). It might be fine for a desk top, but for a simple server, I want to know, or be able to find out about everything running on it.

I also rejected Fedora because of problems I have consistently had with the OS in the past. Arch is to bleeding edge for a server build. So this leaves me with a base Debian 11 install.

Base Debian Install

For information on a base install of Debian, please refer to this post. The only deviations I made were for a static IP address, and how I partitioned my drives.

A static IP address, as far as I am concerned is a requirement for servers. Technically you could map out the MAC address of the computer to a static DHCP grant on your router (something I should look into for a later post).

As far as drive partitioning, on the M.2 drive I created a EFI partition, a swap partition, a /var partition, a /tmp partition, and a root partition.

The hard drive became one large /home partition. Since I do no plan on using any public SMB shares, every user will need their own folder on in the /home directory. Which basically means that is where all files are going to be stored.

Additional Software Installation

Initially, for the installation of additional software, you will need to be logged in as root. Later we can use a regular user account with elevated privileges.

If you are already logged in as a regular user you can use the following command to switch to the root user.

su -l root

You will need to provide the root password. The -l option starts the new user as if they did a normal login, setting up the environment.

Install openssh: Use the following commands to install ssh, check its version, and determine if it is running. The package installer should have take care of this, but it never hurts to check.

apt install openssh-server
ssh -V
systemctl status ssh

After this you can move to another computer and attempt an ssh login. Note on Debian, by default, you must log in to ssh as an unprivileged user, and not root.

If successful, at this point you can disconnect the monitor and keyboard from the server.

Install sudo: Next we want to install sudo so we can administer the system as an unprivileged user. We want to make sure we are su to root (see above) before continuing. Use the following commands to install and configure sudo.

apt install sudo
adduser <username> sudo

The first command installs the program, and the second command adds your unprivileged user to the sudo group. Replace username with your actual user name.

Exit root, and log out. When you log back in, you can use the following command to validate you have sudo privileges.

sudo -v

From this point forward, we will be using sudo privileges to modify the server.

Install SAMBA: Now we want to install the samba program to enable SMB/CIFS protocols. Note that installing samba will install a lot of dependencies. Use the following commands to install and verify operation (note the use of sudo).

sudo apt install samba
sudo systemctl status smbd

By default Debian has a pretty good configuration file for samba, located at /etc/samba/smb.conf. However there is one change we will need to make.

Towards the bottom of the smb.conf file is a section called [homes]. In this section the “read only” parameter is set to yes. If we actually want to write to our server share, this needs to be set to no.

To use samba, we need to create a samba user. For a samba user to be created, a local user must already exist, you created one during the initial install.

To authorize this user in samba, we need to add them and give them a password. Note the password can be the same as your login credentials. Use the following command.

smbpasswd -a <userName>

To test this configuration, restart your samba server and try mapping the user to a drive letter on a separate Windows Computer.

sudo systemctl restart smbd

The format for mapping the share will be similar to this.

\\<ip address>\<username>

Adding Users

Next, since I will be streaming media, I need to first create a local media account, then create a samba user. The following sequence of commands should do this.

sudo useradd -m <media user name>
sudo passwd <media user name>
sudo smbpasswd -a <media user name>

Note: If the user has the same name and password as a Windows user, then you will not need to log in form Windows. If either the user name or password is different, then you will be prompted for login credentials.

Optional Cockpit Installation

I ma including this optional piece of software for those who really want a Graphical User Interface (GUI). There is a program called cockpit available in the Debian repertoires that provides your server with a web interface. It has a lot of dependencies, and is totally optional. There is nothing you cannot do on the web interface that you cannot do from the command line.

To install, run, and verify the program, use these commands.

sudo apt install cockpit cockpit-pcp
sudo systemctl start cockpit
sudo systemctl status cockpit

Note the cockpit-pcp module allows viewing historical data in the web GUI.

Once cockpit is running, point your web browser at your server IP address and port 9090. For example if your server IP address was 192.168.15.5, you would enter;

192.168.15.5:9090

You will get a certificate security warning from your browser, but you can click though it, as it is caused by cockpit using a self signed certificate (which is fine as long as your LAN remains private and not connected to the Internet). You then log in with your credentials for the server, and you get a nice web GUI to play with.

Conclusion

In this post we turned a basic Debian install into a headless (ssh) media server using the SMB/CIFS protocol. Since this protocol is used by Windows, while no the most secure or efficient, it is a common denominator across most devices.

I could not really come up with good justification for adding additional protocols like FTP or NFS. If needed, these are fairly easy to install and run alongside samba.

We also covered installing the cockpit program as an optional web GUI for your server.

Add New Comment

Your email address will not be published. Required fields are marked *