dietpi file ownership question

Hi. Bear with me, this might be a stupid question but I’ll try and describe it succinctly:

I think I’m running my DietPi server in a pretty out-of-the-box manner as regards ownership and permissions. I move files in via NFS from another Linux box, and when they get there they’re owned by dietpi:dietpi.

Now, when it comes to moving, copying, renaming and deleting the files once they’re on the server, my method is to get in via SSH, drop into root and work on them that way. The user-level account username I’ve created for SSH doesn’t have permission to do much of anything with “dietpi’s files”. I don’t know how to “be” dietpi.

My question would be, and it occurs to me this is a very obvious and basic question, and is just something missing from my Linux knowledge: what’s a best-practice method for having non-root control of “my files”, when they’re owned by an account I don’t use (dietpi)? Are there multiple options?

I want to avoid being root as much as possible when it comes to file management. I don’t trust myself. :rofl:

My Linux skills are moderate at best, but wouldn’t the best option be to set the file ownership to a certain group and then assign the users to that group?

As long as the files are owned by say root:[your group name] or ssh:[your group name] you can just set the files and folder permissions to allow write/delete/move/read/execute to that group (I use chmod -R 775 /your/directory)

I think you are saying have dietpi and username be in the same group. Is that right?

This is the kind of thing I’ve never been able to get my head around but I’m trying to learn.

Yes. That is what I meant. I think this would solve your problem. Google has plenty of instructions if you do a search there.

I would try to add dietpi and username to group dietpi. I think the user dietpi already is, so maybe doing it with username is enough.

aftensleuk InfluentialSanction
Jep, using a shared group is easiest. Since most software titles by default are configured to use the dietpi group and create files with 775/664 permissions (which means the owner AND all members of the group have read+write permissions), I suggest you stick with this and add your user to the dietpi group as well:
usermod -aG dietpi username with “username” being the name of your custom login user.

Or you simply login as dietpi? It’s password it the same the root user password.
Or you become either root or dietpi via sudo, when required:
sudo -u dietpi command # Run command as user dietpi
sudo command # Run command as root
sudo -u dietpi -i # Start a subshell as user dietpi, run exit to return to parent shell
sudo -i # Same as above for root

For sudo, the user needs to be inside the sudoers list. If this is not yet the case (sudo not allowed):
echo ‘username ALL=NOPASSWD: ALL’ > /etc/sudoers.d/username

Thank you both. So helpful :slight_smile:

Did it solve your problem? :slight_smile: