Building an infinite Plex Media Server using Amazon Cloud Drive — For average computer users.

Private Wahts
9 min readSep 4, 2016

--

Recently I followed AMC’s Tutorial on how to build a PMS using ACD, the write up outlined the general gist of how to do it and what you need to do, but originally I was put off as there was a lot that I didn’t have the knowledge of. Now happy with my setup I thought that I would share my experience to help other people who were in a similar situation to me.

I’d also like to thank /u/IAmNotorious and MakeShift Ninja.

A lot of content has been taken from AMC’s Tutorial, he’s the brains behind all of this, I’ve simply rewritten my experience in what I feel is more of a tutorial that most people could follow.

It’s also worth noting I’m not by any means an experience Linux user, and there are probably better ways of doing things.

Step 1 — Get a decent VPS

I found a post of Reddit that recommended Digital Ocean for the VPS offerings. Personally I’ve found them extremely quick and reliable. Download from the server maxs out my 300Mbps broadband, and streaming is always quick and without buffering.

I went for the $20 option, 2 Cores, 2GB of memory and a 40GB SSD, this will be running Plex Media Server. I would go for a server that’s closest to you.

For my setup I chose to go for a second VPS with a 100GB of extra block storage on so that I can download content, unpack it, format it correctly and then upload to my ACD, as not to slow down my PMS, you can however disregard this option, this is my setup after all.

Step 2 — Installing Plex

First, you’re going to want to SSH into your VPS. I work on Macs so I use Terminal for this. To do this you simply type:

ssh root@xxx.xxx.xxx.xxx

Replace the X’s with your server IP address.

If it asks whether to allow connections and remember the server, type yes. You’ll then need to enter your password for the root user on your server, DigitalOcean normally email this to you when you set up your VPS.

Now we’re in, we’re going to want to download and install Plex.

cd ~
wget https://downloads.plex.tv/plex-media-server/1.1.3.2700-6f64a8d/plexmediaserver_1.1.3.2700-6f64a8d_amd64.deb
sudo dpkg -i plexmediaserver_1.1.3.2700-6f64a8d_amd64.deb

Now if we head over to http://yourserveripaddress:32400/web you should be greeted by the Plex login screen. You should be able to login using your Plex account.

We’re going to need to set Plex up with a user so it can do stuff!

sudo su
passwd plex
adduser plex sudo

Then lets give it a home directory on the server.

sudo mkdir /home/plex/
sudo chown plex /home/plex/

Step 3 — Connecting to Amazon Cloud Drive

We’re going to be using a script called acd_cli to connect to Amazon. It’s a command line interface that symlinks your ACD to a directory on your server so you can read it as a virtual drive.

We’re going to grab this from the acd_cli Github, along with some other dependencies. But first we need to install Python Setup tools.

sudo apt-get install python3-setuptools python3-appdirs python3-dateutil python3-requests python3-sqlalchemy
sudo easy_install3 -U pip

Now let’s grab acd_cli.

sudo pip3 install git+https://github.com/yadayada/acd_cli.git

Great, let’s see if it works.

acd_cli sync

If all has gone correctly it should ask you to authorise through the Amazon website. Sometimes it will open a browser window for you, or you can use this link.

Log in with your Amazon account and it will then download an oauth_data file.

Now I’m not a huge fan of doing everything in Terminal. If I’m uploading a file, I like to use a GUI where possible. I use an app called Transit for FTP. SFTP into your server using your server IP, root username and password.

Now navigate to the acd_cli folder by pressing CMD-Alt-G and entering the following directory.

/root/.cache/acd_cli/

Now drag the oauth_data file into this directory. Make sure that it doesn’t have any form of file extension.

Now go back to Terminal and press enter. If you’ve done everything correctly it should now sync.

If you accidentally pressed enter to early, don’t worry, just run acd_cli sync again.

Okay, we’ve now connected our Amazon Cloud Drive to our server. We can create a directory for our ACD to be mounted to. We’re also going to add one called ‘encrypted’, we’ll be using that later.

This time we want to login with Plex just to save any file permission errors in the future, so close your terminal window. Open a new one and SSH in like so:

ssh plex@xxx.xxx.xxx.xxx

Now let’s create the directories.

cd /home/plex/
mkdir cloud-drive
mkdir encrypted

Then we mount our virtual drive like so:

acd_cli mount /home/plex/encrypted

Step 4 — Adding our virtual drive to our Plex Library

Off the bat, because we’re not local to our Plex Server it’s not going to let us fiddle around with it’s settings and set it up. So we’re going to have to trick it into thinking that we are, by using an SSH Tunnel.

We’re going to use a app called SecurePipes to do this. You can download it from here. I think the Windows equivalent is Putty.

Click the add button at the bottom left and click Add Local Forward.

Once this is set up, click the SecurePipes icon in your menu bar and click Plex Tunnel.

You should now be connected to your server via an SSH tunnel.

Open up your browser and go to http://localhost:32400/web/

This should open up a Plex login window, enter your details and hit login.

You should get a notification that saying that there is a nearby server to claim. Click claim, and Plex will probably ask you to login again and name your server.

A couple of notes:

Due to the way acd_cli works, Plex’s autoscan feature will not work. You will manually have to refresh your libraries when you add new media.

If you find that Plex isn’t finding your files even on a refresh, you can simply run these commands via SSH.

acd_cli umount /home/plex/encrypted
acd_cli mount /home/plex/encrypted
acd_cli sync

Or just ‘acd_cli sync’ by itself.

So far, we’ve installed Plex on our VPS and connected our Amazon Cloud Drive.

Step 5 — Adding Encryption

Now I’m not sure about other people, but when I’m using any form of cloud storage I don’t particularly like the idea of anyone being able to look through my files. So we’re going to be using a encryption system called ENCFS.

The main concept behind it is that we generate a key using our server and encrypting the files using that key. So in essence unless we upload that key to our Amazon Cloud Drive (Which I strongly advise against) there is no way that Amazon could decrypt the files to see what they are.

We’re going to be doing this on our second server as this is going to be downloading .rar’s and extracting them. We’re also going to need space for the encrypted files too. So we’re going to need 2–3x the space that your downloads take up.

So if you’re downloading 30GB, you’re probably going to need 90GB or more. With the block storage options, it works out pretty cheap.

Make sure you follow this guide of mounting your volume storage: https://cloud.digitalocean.com/support/suggestions?article=storage-how_to_create_and_attach_volumes_to_droplets&page=0&query=volume

You should be given a volume name ie ‘volume-nyc1-XX’.

Let’s jump straight in.

We need to login to our second server using terminal again.

ssh root@yoursecondserveripaddress

We did this earlier, so you should know how it’s done.

Installing ENCFS

First we need to install ENCFS on our server, we can do this by running:

sudo apt-get -y install encfs

Follow the setup and you should get a confirmation that it’s been installed, easy right?

Creating the directories

We’re going to want to create 2 directories to contain our files. One called ‘encrypted’ and the other ‘unencrypted’.

So let’s do that.

cd /mnt/yourvolumename/
mkdir encrypted
mkdir unencrypted

Generating the key

Now we need to mount a directory for encfs to create our key for us

encfs /mnt/yourvolumename/encrypted /mnt/yourvolumename/unencrypted

You’ll then be prompted for your encryption settings, default is fine. It will ask you to create a password, make sure you keep this safe and back it up.

Now anything that we place in the unencrypted folder will appear in our encrypted folder. Make sure to keep your folder structure consistent in the unencrypted folder.

Now we have setup our encfs a key will have been generated in our ‘encrypted’ folder. To access this we need to first unmount it.

fusermount -u /mnt/yourvolumename/unencrypted

Now if we SFTP into our directory we should see a file called ‘.encfs6.xml’, you may need to enable invisibles files in Transmit. This can be done using CMD-Shift-B.

We’re going to need to move this to our main /mnt/yourvolumename/ directory. We’re also going to rename it to simply ‘encfs.xml’.

Download a local copy of this file.

So in your /mnt/yourvolumename/ directory we should have:

encfs.xml
encrypted
unencrypted

Connecting to ACD — again.

We’re going to need to connect our second VPS to Amazon Cloud. This involves going through setting up acd_cli again. Go back to Step 3 and repeat, however DO NOT create the directories again or mount the Amazon Drive.

Enabling Encryption

Now we’ve generated our keys and connected our second server to ACD. Remember we moved our key out of the encrypted directory as we don’t want it being uploaded. Let’s now mount encfs again, but this time we’re going to tell it where to find the key.

ENCFS6_CONFIG='/mnt/yourvolumename/encfs.xml' encfs /mnt/yourvolumename/encrypted/ /mnt/yourvolumename/unencrypted/

It should prompt you for your password, if it asks you for your security settings you’ve done something wrong.

Now you can try adding a file into the unencrypted directory. If a file then appears in your encrypted directory with an obscure filename you’ve done everything perfectly.

Step 6 — Uploading to Amazon Cloud Drive

Now, the exciting part. We’re going to try uploading to your ACD.

Remember I said to keep directory structures consistent?

If you’re uploading Movies and TV Shows from iTunes or similar I’d recommend keeping a structure set by FileBot.

Movies
- Movie Title (Year).mkv
TV Shows
- TV Show Title
- Season 1
- TV Show Title - S01E01 - Episode Name.mkv

Okay, so you need to create a folder in unencrypted called Movies, and added a file into it.

Has a folder with a file appeared in encrypted? Yes? Good. Let’s upload it.

acd_cli upload /mnt/yourvolumename/encrypted/* /

This will upload the contents of your encrypted directory to the root of your ACD.

If you are not intending to upload to the root directory of Amazon Cloud Drive, append to /.

You should now get a progressbar as your file uploads. When it’s finished simply run:

acd_cli sync

Step 7 — Decrypting for our PMS

Now that we’ve uploaded some encrypted files, we need to go back to our first VPS — the one running PMS and tell it how it decrypt our files.

So SSH into our first server using the Plex user.

We need to install encfs on this server so lets do that:

sudo apt-get -y install encfs

Go through the setup as usual but this time we’re not going to generate a key. We need to upload the encfs.xml file that we downloaded earlier. We’ll upload it into ‘/home/plex/’.

Just to be on the safe side, we’re going to unmount our ACD.

acd_cli umount /home/plex/encrypted

Now remount it:

acd_cli mount /home/plex/encrypted

The next step is to tell encfs to decrypt our ‘encrypted’ folder and mount a virtual decrypted version in our ‘cloud-drive’ folder. So we run:

ENCFS6_CONFIG='/home/plex/encfs.xml' encfs /home/plex/encrypted /home/plex/cloud-drive

Then we’ll run:

acd_cli sync

Head over to https://app.plex.tv/web/app and login, you should see your server listed. Now add a Movie library, under add folders you should see ‘cloud-drive’ select that, and then within that you should see ‘Movies’ (if you’ve followed this guide). Click next and it should scan your directory for media.

If all has gone to plan you should now see the home movie that you uploaded to test it out. Voila! Pat yourself on that back, you have done it. You now have an infinitely scalable Plex server.

It is entirely possible to only have one server for this setup, I opted for 2 mainly as I wanted the server that I’m downloading on to be separate from my PMS.

Ending notes

If this guide helps anyone please comment and let me know. I’m glad I can finally give back to a community that has given so much. If you have any problems I’ll do my best to help.

I’m also in the future planning to share my experiences using DDL sites to download onto my VPS and uploading to ACD. Along with using odrive to upload files straight to ACD without using command line.

--

--