dietpi file ownership question

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
InfluentialSanction
Posts: 13
Joined: Tue May 15, 2018 5:05 pm

dietpi file ownership question

Post by InfluentialSanction »

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. :lol:
aftensleuk
Posts: 30
Joined: Sun Jul 21, 2019 8:27 pm

Re: dietpi file ownership question

Post by aftensleuk »

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)
InfluentialSanction
Posts: 13
Joined: Tue May 15, 2018 5:05 pm

Re: dietpi file ownership question

Post by InfluentialSanction »

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.
aftensleuk
Posts: 30
Joined: Sun Jul 21, 2019 8:27 pm

Re: dietpi file ownership question

Post by aftensleuk »

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.
User avatar
MichaIng
Site Admin
Posts: 2294
Joined: Sat Nov 18, 2017 6:21 pm

Re: dietpi file ownership question

Post by MichaIng »

@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
InfluentialSanction
Posts: 13
Joined: Tue May 15, 2018 5:05 pm

Re: dietpi file ownership question

Post by InfluentialSanction »

Thank you both. So helpful :)
aftensleuk
Posts: 30
Joined: Sun Jul 21, 2019 8:27 pm

Re: dietpi file ownership question

Post by aftensleuk »

InfluentialSanction wrote: Sun Aug 04, 2019 12:25 pm Thank you both. So helpful :)
Did it solve your problem? :)
Post Reply