Pertinent Steps to Configure a Linux Server to Share Files
In this article I walk quickly through *most* of the steps needed to set up a file server for home sharing for a DIY networked attached storage (NAS). Spoiler alert: it is very basic and uses Samba. Yes, some of you might be thinking I really ought to check out an honest-to-goodness server for NAS such as OpenMediaVault. Yes, I did in fact go that route at first but then opted to do things manually. I am a control freak. There. I said it.
Important: all of the steps in this article assume a local network, you will need to be take additional steps if you plan on exposing your network to the Internet!
Before we Begin
Talk is great and so are helpful articles but before doing any of the subsequent steps you will need a machine on your local network that can be used for file sharing. See my article on MaximusNAS in this regard.
Label your machines where practical to minimize confusion!
For this article, ‘Client’ is the machine on your local network that you use to configure the Server, and ‘Server’ is the machine being configured as your NAS.
There are lots of articles out there on installing Ubuntu so I do not plan on going into a lot of detail here. Did I mention this was supposed to be quick-and-dirty? I have my own list of favourite repos and other goodies that I like to include during a fresh install, perhaps this is the subject for a future article!
See my article on Get SSH Working on a Raspberry Pi 4. Once SSH is configured, perform an initial test by logging into the Server from the Client.
Try to interact with the Server via SSH from this point onwards.
Option 1 — Build RAID from Scratch
I must admit that this section needs further work! I was lucky in that I already had a RAID from another machine that I brought over to the new Server.
What are your experiences in building RAID from scratch?
One point worth mentioning is that once your RAID is set up, create a filesystem with a unique name. Avoid special characters such as
# in the volume name.
Option 2 — Initial Setup of Existing RAID
See this post, this one and this one on how to migrate an existing RAID in Ubuntu with
Install the RAID manager via:
sudo apt-get install mdadm
Scan for the old RAID disks via:
sudo mdadm — assemble — scan
Next, update initramfs via:
sudo update-initramfs -u
Identify all drives for this Ubuntu machine:
sudo fdisk -l
There will likely be many drives to choose from! Make a note of specific drive connected to your RAID, identified by physical size as applicable. For this tutorial the desired drive is named:
Make a new directory to serve as the mount point for your RAID:
sudo mkdir -p /media/<server_user>/<drive_name>
Mount the drive to the newly-created mount point:
sudo mount /dev/md123 /media/<server_user>/<drive_name>
Initial Setup of Shared Folder on RAID
Make a single folder on your drive to get the correct permissions for the Server. Navigate to your drive then:
Wait until Samba is configured before populating the other shares.
Important: Do not name your shares with special characters such as
#. Doing so will make your life miserable, particularly if you plan on using NFS to share your folders. Creating shares with
[a-z][A-Z] as well as underscores and numbers
[0–9] appears to work fine, provided the first letter is
Set-up and enable Samba sharing for the newly-mounted drive; see my article on Setting up for Success with Samba for details. Confirm the new Samba share is available from your Client machine.
Interactive SSH is nice but it has limitations. VNC is a good alternative if you need graphical access to your Server. See this super helpful tutorial by DigitalOcean to get you set up with VNC.
I have also built a quick Shell script to help get SSH set-up for secure VNC sessions:
echo ‘Starting SSH for VNC, open remmina to VNC to toni, use localhost:5901’
# Start SSH.
ssh -L <port>:<ip>:<port> -C -N -l <server_user> <server_ip>
Finalize Setup of Shared Folders
This part assumes you have an empty set of folders on your Client that you wish to use as shared folders on your Server. With Samba up-and-running and the drive on your Server shared with your Client, proceed with copying the empty folders to the Server. See this post for details. SSH to your Server then run the following commands to copy the permissions from the initial folder we created a few steps ago. Copy its permissions to the other folders:
Important: be sure you are in the correct folder before performing the following steps to ensure you are changing the ownership and group of the correct folders!
chown — reference=BUp *
chgrp — reference=BUp *
If the permissions of your shared folders are set to
root, root you will likley get the following error when running a service such as
rsync from a different machine to copy and back-up items:
sync: failed to set times on “/destination/.”: Operation not permitted (1)
If this is the case you need to set the ownership and group for your shared folders on the Server:
sudo chown <server_user> /Share_A
sudo chgrp users /Share_A
Repeat these commands for additional shares as appropriate, see this post for details.
This was a very abridged look at how to set up a file server for a home network. I think the term ‘file server’ is probably very generous but I am sticking with it! What are your experiences with setting up servers, particulary for home use?
1 thought on “Network-Attached Storage at 50,000 Feet”
Pingback: Go for the Gold with your Disk I/O! – steadynotion.com