Computers, Laptops & Tablets Accessories & Hardware How to Set up Raspberry Pi as a NAS Server Access your files anywhere on your network. by Nicholas Congleton Writer Nick Congleton has been a tech writer and blogger since 2015. His work has appeared in PCMech, Make Tech Easier, Infosec Institute, and others. our editorial process Twitter LinkedIn Nicholas Congleton Updated on July 24, 2020 Accessories & Hardware Raspberry Pi The Quick Guide to Webcams Keyboards & Mice Monitors Cards HDD & SSD Printers & Scanners Tweet Share Email One of the Raspberry Pi's many functions is as a budget Network Attached Storage (NAS) device. Commercial NAS solutions are often costly and restrictive. The Pi is inexpensive and lets you configure a server however you like and pair it with most hard drives. When you create a Raspberry Pi NAS server, you'll have more than enough power to handle the everyday tasks of the home NAS. In addition, the Raspberry Pi 4 has USB 3.0 ports for faster file transfer. What You'll Need Before you get started, you'll need a few things to put together your NAS: A Raspberry Pi 3B or 4.A MicroSD card, 16 GB or greater.A case for your version of the Pi.A power supply that's compatible with the Pi.An Ethernet cable.A USB hard drive with its own power supply. Install Raspbian Raspbian is the default operating system for the Raspberry Pi. It's the only one made by the Raspberry Pi foundation and is based on Debian Linux. The utilities used in this guide to create the network attached storage are Linux file-sharing services that come from Raspbian. Open a browser and download the latest version of Raspbian Lite from the Raspberry Pi foundation. Unpack the Raspbian ZIP file. It expands significantly, so be sure you have enough space. Choose a utility to flash the Raspbian image file onto the SD card. This guide uses balenaEtcher because it's simple and works on Windows, Mac, and Linux. If you have another option that you prefer, use that instead. Go to the balenaEtcher download page, and download the latest release for your OS platform. Install. This will be different depending on the operating system, but the installer is fairly straightforward. The defaults should be fine for most systems. Open balenaEtcher. In the first column to the far left, select the image file you extracted for Raspbian. In the center column of Etcher, choose the microSD card to write to. Ensure that everything is correct, then select Flash. Before you remove the microSD, locate the new boot partition on the card using the operating system's file manager. Mount boot if you need to, and place an empty file called ssh in the partition. The file should be empty, and ssh shouldn't have any extension. This file tells the Pi to enable SSH remote access when it starts up. Unmount or eject any partitions from the microSD, and remove it from the computer. To assemble the Pi, put it in its case, then insert the microSD. Connect the Pi to your network using a wired connection. Leave it wired for the best performance, but you can change this later. Power on the Pi. This starts the Raspberry Pi and begins the setup process. During this process, it resizes the disk image to fill the microSD card. Don't stop this setup. It should always be done after everything else is connected. Give the Pi a few minutes to get started, then open a terminal on the computer to connect over SSH. This can be the built-in OpenSSH feature on Windows 10, PuTTY, or a regular terminal window on Linux or Mac. Find the Raspberry Pi's IP address. The easiest way is to open the connected device list on your router. The Pi is called raspberrypi by default, and it is listed under that hostname on the router. Enter the username for the Pi, which is pi, and the IP address on the SSH client. It looks something like this: $ ssh pi@192.168.1.150 When you connect, enter the Pi's password. The default is raspberry. How to Set up a Network File System A Network File System (NFS) is a convenient way to share files between Unix-like systems, including Linux and Mac. However, NFS is more difficult on Windows. So, if your network is primarily made of Windows PCs, you may want to skip this option. If you have Macs, Linux PCs, or other Raspberry Pis you plan to share files with, it might be worth the effort to set up an NFS. Connect to the Pi over SSH. Install the required NFS server package with the following command: $ sudo apt install nfs-kernel-server Use the Nano text editor to open the NFS exports file on the Pi: $ sudo nano /etc/exports This file contains a list of folders you want to make available over NFS. On the left side, list the path to the folder. On the right, specify which computers can connect and the options for the connection. Start a new line, and enter the path to the file share: /path/to/share Press Tab to move to the right side. Then, enter the IP address range of your home network. Most home networks are on the 192.168.1.X range. To tell the server to accept all IP addresses in the range, end the address with a zero followed by a backslash and the number 24. The command looks like this: /path/to/share 192.168.1.0/24 Add the options for the share. There are several to choose from. If you want a good default, use the example below to read and write files and sync files with the server to prevent conflicts and corruption. /path/to/share 192.168.1.0/24(rw,sync,no_subtree_check) Add as many shares as you like. When you're done, save and exit Nano. Restart the NFS server to apply your changes. $ sudo systemctl restart nfs-kernel-server When the server comes back up, you have access to the NFS shares. How to Set up Samba for Network Shares Samba lets Linux machines create Windows network shares. Most computers are compatible with Samba and can mount its shares. Samba also has the advantage of allowing you to restrict access to certain users with a password. Install Samba on the Raspberry Pi using the following command: $ sudo apt install samba With Samba installed, edit its configuration to create the shares. Use the Pi's Nano text editor to open the Samba configuration: $ sudo nano /etc/samba/smb.conf Find the workgroup entry under Global Settings. If you never changed your Windows workgroup, leave this as-is. If you have, set workgroup equal to your current workgroup name. workgroup = WORKGROUP There are many more settings. To set up a basic server, though, you don't need most of these. Scroll down to the Share Definitions section. Go to the [print$] section, then set browseable to no. This isn't necessary, but you aren't using the Pi as a print server, so that share only clutters things up. Scroll to the bottom, where you'll create your shares. Each Samba share starts with a name in square brackets. That's the name your share appears as when you connect to it on another computer. Name the share. [Your Share] The settings for the share go underneath it, indented three spaces. Add a comment about what the share is. [Your Share] comment = Just some networked files Add the path to the directory. path = /path/to/share Choose whether you want the share open to everyone or only certain users. Samba refers to users that aren't signed in as guests. Set guest ok to either yes or no. guest ok = no Choose whether you want the people connected to the share to be able to write and create files or only read files. read only = no If you don't allow guests, set which users are valid to access the share. valid users = user1, user2 Your share should look something like this: [Your Share] comment = Just some networked files path = /path/to/share guest ok = no read only = no valid users = user1, user2 Start your next share the same way. You can create as many as you need. When you're done, save and exit. Create user accounts for your users. They need a user account on the Pi, so set up minimal ones. $ sudo useradd -m -G users -s /bin/bash username Set a password for each user. $ sudo passwd username Set up a Samba password for each user. $ sudo smbpasswd -a username Restart Samba to access your shares over the network. $ sudo systemctl restart smbd Was this page helpful? Thanks for letting us know! Get the Latest Tech News Delivered Every Day Email Address Sign up There was an error. Please try again. You're in! Thanks for signing up. There was an error. Please try again. Thank you for signing up. Tell us why! Other Not enough details Hard to understand Submit