File ownership/permissions wrong after running file manager as root

I just found out that using Thunar and Caja as a superuser is screwing up file ownership and permissions.

I will be doing it via CLI, but I need help either with a bash script or an alias.

It will need to use replaceable parameters.

For ex.

mv file1 destination (where mv is actually sudo mv)

I hope that made sense.

When you launched caja as a super user, did you do it with “sudo caja” or “gksudo caja”?

The reason I ask is because you should never use “sudo” to start graphical applications as Root. You should, instead, use “gksudo” to run such programs. gksudo sets HOME=~root, and copies .Xauthority to a tmp directory. This prevents files in your home directory becoming owned by Root.

3 Likes

In addition to @stevecook172001’s important suggestion there’s one biggy I learned over the years.

If you have both your user and root instances of Caja or Thunar running, everything pasted into the root instance will be owned by root. If you want it to be owned by your user, paste it into the user instance.

Also, many are unaware that if you need to edit a text file as root there’s a right-click option “Open as administrator” that can be very handy.

This what I USED to use. :slight_smile:

#!/bin/bash 
# Ubuntu-Mate 16.04
#
#  This may work with other distros.
# 
# Start thunar without having to give password
#   
echo xxx | sudo -S thunar

I know linux is much safer than Wind***, but having to type my PW everytime gets really old.

I used ps -ef to show my process table. It does not show my password.

With a script like that on your system, anyone with access to it could manipulate, or delete any file on your system, with out entering a password.

No one has access to my system.

And would they not need my password ?

Thanks for caring. :slight_smile:

I've not tried this myself. But, have you tried:

echo xxx | gksudo -S thunar

Just tried it. Didn’t work. Still required password.

mmm…

I will have to figure this one out

Well, gksu/gksudo asks for password via GUI, so I don’t think it would read the standard input.

Just tried the following and it seems to work in that it allows caja to be opened as root with the correct file permissions, but without having to enter the gksudo gui password.

  1. Disable the requirement for the sudo password for the user with the following addition to the sudoers file:

yourusername ALL=NOPASSWD: ALL

where “yourusername” should be replaced with your actual user-name (mine, for example, is “stephen”)

  1. Create the following script:

sudo su <<EOF
caja
EOF

  1. Then execute that script to open caja as root with the proper file permissions attached to root and not the user
1 Like

Thanks.

I prefer using Thunar.

So, put Thunar in the script instead of Caja.

The point is, it opens the root file manager with the correct permissions and removes the requirement for the gui gksudo password.

That is what you wanted… right?

Actually, I have just logged out and back in and it seems even that script is not necessary. gksudo caja (or any other file manager you prefer) opens straight to root without the need for a password

Thanks. gksudo thunar does ask for a password.

No problem. Now I won’t mess up ownership of files.