Connecting a Plex Media Server (Ubuntu) to a Shared Network Folder for its library

Andrew Murray
7 min readJul 29, 2018
Source: Wikimedia Commons

Setting up Plex on Ubuntu and want it to be able to use files from a local Server or NAS? A beginner’s guide to getting a network drive loading in a place that Plex (running on Ubuntu 16.04) can access it.

Finally putting this guide up here since I’ve constantly have forgotten how to do this, and there hasn’t been a single place with all of this info together.

This guide assumes the following:

  • You have a NAS or Server already sharing a network drive that requires a username and password to access, and it’s available on the local network at a static IP.
  • Plex Media Server is installed and running on Ubuntu
  • You are comfortable enough using Terminal to perform this operation
  • You don’t blame me if you mess up, as the following procedure can easily brick your Ubuntu machine if the changes to the /etc/fstab file we will be editing is done incorrectly.

My specific setup is using an old-ass Intel LGA 775 Dell running Ubuntu 16.04 LTS and a 4 Bay QNAP NAS that has a protected shared folder with the default properties. Both machines have their own Reserved IP/DHCP Addresses on my local network.

Step 0: Create new Local Directory to mount Shared Folder

Make a new folder, called media , within your current user’s home directory.

Run this command:

sudo mkdir media

WTF did I just type into my computer

sudo means run the following as an admin, mkdir means make a new directory (folder), and media is the name of the new folder. You can call it whatever you want, but I suggest media as it will not conflict with other default folders.

Advanced Usage

You can create this new directory anywhere, as long as it’s accessible by other user’s that do not have root access. Be cautious of using existing directories as they come with their own security permissions and quirks. I’ve read that trying to use a user’s video directory ends up locking out plex from doing any operations, so at least try to avoid that unless you like dealing with trouble.

Step 1: Find out the User and Group ID of the plex user

Plex Media Server has it’s own user that interacts with the shared drive, and we need to allow that user to access. Without giving the plex user access, it causes issues with Plex writing and doing other operations with these files.

Run this command to have the system show the details for the plex user:

sudo less /etc/passwd | grep plex

Which should respond with something that looks like this:

plex:x:123:456::/var/lib/plexmediaserver:/bin/bash

You will want to note the what numbers appear where my example shows :123:456: as that will be plex’s User ID and Group ID. Also, note Plex’s Home Directory where my example shows ::var/lib/plexmediaserver. We will need these values for Step 3 and Step 4.

WTF did I just type into my computer

sudo means run the following as admin, less shows the details of the response in a minimal way, /etc/passwd is the file which stores the system’s users, | means run the following command on the results of the previous command, and finally grep plex means filter the results to lines that contain the word plex… that way we don’t have to scroll through all the users on this system.

Advanced Usage

Instead of finding the plex user, you can reconfigure Plex to use any other user on the machine. Then, make sure you get the User ID and Group ID of that user instead for the rest of the instructions.

Step 2: Create a backup for the drive management file we will be changing

Run the following command to make a copy of your fstab file, as if you mess something up it will prevent your computer from starting up again.

cp -pa /etc/fstab /etc/fstab-old

That way, if something truly get’s f-’d up, you can use the contents of fstab-old to restore the original settings.

WTF did I just type into my computer

cp means copy a file somewhere, -pa are arguments that mean (p) “keep the existing permissions of this file” and (a) “this is an archive file, only copy the contents”, /etc/fstab is the file we are going to copy, /etc/fstab-old is the new file that will be the copy we just made.

Step 2: Save the credentials to log into the network drive

Let’s create a new file that we will store the username and password in order to log into the shared directory. Make sure to use Plex’s Home Directory mentioned in Step 1 to replace the bold part:

sudo gedit /var/lib/plexmediaserver/.mountaccess

This will open a text editor, in which you will want to add the following into this blank document:

username=your_username_for_shared_folder
password=your_password_for_shared_folder

Replace the parts in bold with the correct information for your setup. Make sure to save the file before closing.

WTF did I just type into my computer

sudo means run the following as admin, gedit means open a file (and create it if it doesn’t exist), /var/lib/plexmediaserver/.mountaccess is your Plex’s Home Directory plus what we are calling the new file (which is the .mountaccess part)

Advanced Usage

Obviously you can use whatever editor you would prefer, does not require gedit. I recommend placing the login credentials here just to help ensure you can find them in the future, since they are related to your Plex setup. They can be placed anywhere in the system you are most comfortable and provided whatever access as long as the system can read it at startup.

Step 3: Edit the drive management file to mount the shared folder on startup

Run the following to open the file we need to edit in a text editor:

sudo gedit /etc/fstab

This will open the text editor, and we need to add the following line at the very end of the file.

# Mounting Network Directory for Plex
//192.168.1.100/Plex /home/user/media/ cifs uid=123,gid=456,credentials=/var/lib/plexmediaserver/.mountaccess,iocharset=utf8 0 0

Everything highlighted in bold you’ll need to update with the setting for your own setup. Make sure to save before you close the window.

  • //192.168.1.100/Plex is the local IP for the server sharing the directory and the directory that is shared. Your computer will look here when it attempts to add the network drive.
  • /home/user/media is the location of the directory we made in Step 0, the user referenced is your username for the computer (if you don’t know it, run the command whoami). This will add the contents of the shared directory in this one and allow Plex to interact with them just like they are local files.
  • 123 is the User ID referenced in Step 1
  • 456 is the Group Id referenced in Step 1
  • /var/lib/plexmediaserver/.mountaccess is the Plex Home Directory plus the file name used in Step 3

WTF did I just type into my computer

Just like the previous step; sudo means run the following as admin, gedit means open a file (and create it if it doesn’t exist) /etc/fstab is the file that controls how all of your system’s drives are loaded on startup.

Advanced Usage

If you changed where you’re storing the username and password from the previous step, you’ll also want to update the credentials attribute in that added line.

Step 4: Remount all drives to see if it works

Once all the fields you edited are saved with your changes, run the following command to have the system load all the drives again:

sudo mount -a

If you do not get a response, then there was no error in the changes to /etc/fstab. If you did get an error, take another look at Step 3 and Step 2, making sure everything is spelled correctly.

Finishing Up

After running the command in Step 4, the network directory should be mounted on your computer and the files accessible. Go ahead and browse to them and see if they are there (should be in your home folder, inside media)

Next, restart your computer and check to make sure those files are still accessible. If so, then it’s safe to link Plex to the contents within media .

Troubleshooting

If the network directory is missing on startup

Run sudo mount -a and see if you get any errors. This tends to happen if either your username and password are not correct or if there is an error in what you added to /etc/fstab

If Plex can read the files, but not write files

This means that the plex user does not have the proper permissions to this drive. Make sure that the User ID and Group Id from Step 1 match what you specified in Step 3. This will give the user that Plex Media Server uses full access to the shared files.

If you are using Plex DVR and get an no write access to destination error when you try to record, then this is the same issue.

If your computer is bricked or will not boot properly

Ah, welp, this means that something in /etc/fstab is messed up. Google how to restore it properly, and grab the original settings for it in /etc/fstab-old .

--

--

Andrew Murray

Digital Product Designer, GraphQL API Developer, and UX Aficionado. Enjoys pulling concepts from the ether of ideas to make the real.