I am very inexperienced when it comes to using a command-line interface, Linux, and the concept of file and folder/directory permissions (among many other administrator-type things).
I have a server machine running Ubuntu Server that I used in the past to run game servers, and I would now like to put a Plex server on it for 24/7 access to my media library.
Every time I want to do something new with that machine, I research online, try to make sense of what I find, and write out all the steps I take so that I will be able to easily repeat them in the future. I just like to get things running and then leave it alone – I don’t have a good brain for command-line computing. I basically write a script (instructions) for myself to follow to set things up, and then follow that script every time I need to do it again. …But it’s OK, because I wasn’t trying to impress you anyway!
This time around, in addition to writing instructions for installing the Plex server, I am also adding instructions to make the machine as secure as possible. This includes establishing proper directory permissions, and I just can’t wrap my head around how it works and what is the best thing to do.
I had initially planned to restrict access to the Plex media directory to just my own user account, but now I am thinking that would block Plex and other programs from accessing those media files. I am not sure how exactly permissions work. If I run a program myself, does it have permission to access all the same files and directories as my own user account? Or do I need to run it with “sudo” privileges? What about a program/service that runs on its own at startup?
In at least one guide I found online for installing Plex, the author said I need to change the owner of my media directory to the user named “plex”, and also all of its subdirectories (by running sudo chown -R plex: [media directory] ).
I am afraid that if the “plex” account is the owner of the entire media library, I will no longer be able to access the media files and subdirectories myself, nor will other programs.
I previously used a program called “Syncthing” which worked really well for syncing files and folders/directories between my PC and server machine. Syncthing would be perfect for my Plex media library – I could just add files and folders to the media library on my PC and they should automatically appear on my server machine via Syncthing. And vice versa. It’s like Dropbox minus the cloud storage (and thus no storage limit other than hard drive size).
I am worried that if I change the ownership of my media library to the “plex” user, as it said to do in the guide I found, Syncthing will not be able to sync the files and directories, nor will I be able to access them myself. …But I really have no idea how any of this works and haven’t tried it yet. (I don’t even have an organized media library yet, nor have installed anything yet. Still writing my instructions.)
I suppose I could set the permission of the media directory so that ANYONE has full permission to access its contents, including Syncthing and myself, but my research seems to indicate this is not a good idea in terms of security. I don’t know what permission level is appropriate for the media library directory – I had initially figured 700, to restrict access to the owner. But if Plex, Syncthing, and myself all need access to the directory, and just “plex” is going to be the owner, I am not sure what to do.
I don’t even know if Syncthing has its own user account by default, like Plex apparently does, which I could perhaps put into a group with the “plex” user and then somehow give that group ownership of the media library directory. But then would I be able to access the contents myself, since my own account is no longer the owner, or do I need to add myself to the same group along with the “plex” user and “syncthing” user?
Or, will I be able to access the contents of any directory I don’t own by typing “sudo” in front of cd, or when running a program that needs to access those folders? Or does my account have special privilege already, without typing “sudo”?
If I use “sudo” when I run a program, does that give it access to any directory on the machine? Is that a wise thing to do? What about programs/services that run at boot – how to I ensure they have access to a directory that is not owned by the program’s own user account?
Furthermore, I don’t know what happens with newly added content AFTER the “plex” user becomes the owner of my entire media library and all its subdirectories. Every time I add new content to my media library, which would normally be via a Syncthing transfer from my PC, do I have to “chown” that content to the plex user again, every time??
There are clearly some basic thing(s) I don’t understand about file/directory permissions and how they affect the operation of programs, and I am having a hard time figuring it out on my own.
My goal is simply to maximize security or follow best practices while allowing Plex and Syncthing to run smoothly, and to be able to access the media directory and files myself when necessary.
I could probably tinker and figure some of this out for myself, but I don’t have a clear sense of what I am doing. And I don’t know what is best practice, what is normal to do, or what potential problems could arise down the road from my decisions.
I’d just like to get it right the first time, set it, and forget it.
It should be an awesome setup, using Plex with Syncthing.
I appreciate any help. Thank you!