The latest Raspberry Pi 4B comes with a Gigabit ethernet port, up to 4GB RAM and 2 USB3 port. Because of its low power supply, Raspberry Pi 4 surely has the capability of working as an affordable file server to back up and share files from anywhere on your local network. In other words, all your local devices have can not only backup your important files to the Raspberry Pi, but also plays movies stored in the Raspberry Pi. You can even plug external drives to it to enlarge the disk space. In this tutorial, we will use Samba to set up a file server on your Raspberry Pi 4.
Samba is the Linux implementation of the SMB/CIFS file sharing standard used by Windows PCs and Apple computers, and widely supported by media streamers, games consoles and mobile apps. With Samba activated you can quickly copy files from a computer on your network to a Raspberry using wireless LAN (or a direct Ethernet connection).
First we need to update and upgrade the apt source and package list:
sudo apt-get update sudo apt-get upgrade
Then we can install the Samba:
sudo apt-get install -y samba-common-bin sudo apt-get install -y samba
First we create a folder under pi:
sudo mkdir -m 1777 /home/pi/share
Now we need to modify the configuration of Samba:
# backup the original configuration file sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup # edit the configuration file sudo vim /etc/samba/smb.conf # add the following content at the end
share folder full permission:
sudo chmod -R 777 /home/pi/share
Change the default Samba password for user
sudo smbpasswd -a pi
Lastly, we need to restart the Samba service to apply all changes:
sudo /etc/init.d/smbd restart
In some cases you might want to set a private folder for yourself only. Here is how you should do it:
Create a new user
adduser username. The
/home/username folder will be created, and you need to type the password.
Edit Samba config
sudo vim /etc/samba/smb.conf, add a new block as above and modify as follow:
[share], we added
valid userbecause we want
usernamehas access to the share folder like others.
[username], we change the
publicsince we don't want others to see this folder.
Then we change the
sudo smbpasswd -a username
Lastly we restart the smb service again.
You’ll now be able to find your Raspberry Pi file server (named RASPBERRYPI by default) from any device on your local network. If you’ve left smb.conf’s default settings as they are, it will appear in a Windows network workgroup called WORKGROUP.
Sometimes you will need to reboot your other devices if you modify the configuration file later.
- Ideally you might want to connect your Raspberry Pi to the local network through the Gigabyte ethernet port since the WiFi may not work as fast and stable as the ethernet cable. Also make sure to use CAT.5E or CAT.6 ethernet cable and your router also has Gigabyte port.
- If you want to expand your disk space by plugging in external USB drives, make sure the disk is correctly mounted by Raspberry Pi and condifured in