0

Obviously, I own my home directory. But this is a problem if I want to protect some of its children (in particular the dot-folders) with a sticky bit from accidents. Because the sticky bit on my home directory only protects its contents from me if neither they nor their parent is owned by me. I can chown root the dot-folders, but this apparently doesn't stop me from renaming, moving, or deleting them if I own the home folder.

I'm sure there is some way to do what I want under Linux. The question is: what is the least roundabout way? I'd prefer if I could avoid resorting to using stuff like mount.

Obviously I also still want to be able to freely move, create and delete files in Home other than said folders, as well as the contents of said folders. I just need those folders to stay where they are.

Justification:

The reason I need to protect my dot-folders from myself is that I'm using Steam Deck's lousy mouse emulation. It's very easy to accidentally drag and drop stuff instead of just clicking it. Accidentally moving your .local directory while using a Desktop environment that continuously reads from and writes to that directory is very annoying. Imagine not being able to launch a terminal in that situation because all the shortcuts stopped working. Suffice it to say switching to a console using ctrl+alt+f-keys is not really an option if you don't have a real keyboard and the virtual keyboard doesn't even have f-keys and you can't launch it anyway because Steam just stopped working because it uses the .local folder for everything.

Blindspots
  • 3,472
sonofevil
  • 117

1 Answers1

1

I will have to do more testing, but so far it appears this works decently:

  1. Set sticky bit on home:

    chmod +t ${HOME}
    
  2. Make sure you are in the owner group of home and group has rwx permission:

    chown :<yourgroup> ${HOME}
    chmod 770 ${HOME}
    
  3. Grant ownership of your home dir to root:

    sudo chown root ${HOME}
    
  4. rwx your group on the directory you wanna protect, and set root as owner:

    chown :<yourgroup> ${HOME}/.local
    chmod 770 ${HOME}/.local
    sudo chown root ${HOME}/.local
    

Explanation:

Root ownership on your home directory seems weird, but group rwx ensures you still can edit its contents. But contents owned by root are protected, thanks to the sticky.

If you now protect one of the subfolders by granting ownership to root you can no longer rename, move or delete it. But if you want to retain the ability to edit that subfolder's contents, you first need to grant your group rwx.

In summary: Owner (both of the sticky folder and its children) overrides the sticky protection, but group does not.

Caveats:

Not having user ownership of your home directory doesn't sit quite right with me, but this is the most straightforward solution I could come up with.

Also Dolphin file manager does not seem to understand that the sticky overrides group permissions on subfolders (it does understand other sticky arrangements), and will still display the option to rename/move/delete in the context menu - but the operation will fail.

Edit: Apparently the sticky doesn't grant anything in this setup, it only protects. So setting it on the subfolders is pointless. I have edited my answer accordingly.

sonofevil
  • 117