Page 1 of 1

Calibrating permissions

Posted: Tue Sep 19, 2023 2:19 pm
by Jakob77
Is there an elegant way to test and calibrate the MX permissions for user files and folders.?

I suspected ClipGrab to give some downloaded files the permission to run like programs but after a closer look I am not so sure ClipGrab is to blame.
The last five files I downloaded did not have the wrong permission but after I did a copy to an external USB solid drive they were changed so they all got permissions to run as programs.

Any ideas about how that can happen or if it is common.?

I have only discovered it by coincidence and I see nothing else wrong with the computer. In fact for me to see it has never run better.
Afterwards I tested a file copy from folder to folder on the internal drive, and that looks okay.
All copy jobs was done with Thunar.

A Terminal command that can set permissions correctly for all files (picture- and video clips) in a folder and all its sub folders can maybe do what is needed.?


QSI for the computer where I want to reset privileges:

Code: Select all

System:    Kernel: 5.10.0-25-amd64 [5.10.191-1] x86_64 bits: 64 compiler: gcc v: 10.2.1 
           parameters: BOOT_IMAGE=/boot/vmlinuz-5.10.0-25-amd64 root=UUID=<filter> ro quiet splash 
           Desktop: Xfce 4.18.1 tk: Gtk 3.24.24 info: xfce4-panel wm: xfwm 4.18.0 vt: 7 
           dm: LightDM 1.26.0 Distro: MX-21.3_x64 Wildflower January 15  2023 
           base: Debian GNU/Linux 11 (bullseye) 
Machine:   Type: Laptop System: Dell product: Latitude E7240 v: 01 serial: <filter> Chassis: 
           type: 9 serial: <filter> 
           Mobo: Dell model: 060GR9 v: A00 serial: <filter> BIOS: Dell v: A08 date: 02/18/2014 
Battery:   ID-1: BAT0 charge: 28.2 Wh (100.0%) condition: 28.2/45.0 Wh (62.7%) volts: 8.5 min: 7.6 
           model: LGC-LGC5.9 DELL J31N73B type: Li-poly serial: <filter> status: Full 
CPU:       Info: Dual Core model: Intel Core i5-4300U bits: 64 type: MT MCP arch: Haswell 
           family: 6 model-id: 45 (69) stepping: 1 microcode: 26 cache: L2: 3 MiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 19954 
           Speed: 1191 MHz min/max: 800/2900 MHz Core speeds (MHz): 1: 1191 2: 1199 3: 1235 
           4: 1141 
           Vulnerabilities: Type: gather_data_sampling status: Not affected 
           Type: itlb_multihit status: KVM: VMX disabled 
           Type: l1tf mitigation: PTE Inversion; VMX: conditional cache flushes, SMT vulnerable 
           Type: mds mitigation: Clear CPU buffers; SMT vulnerable 
           Type: meltdown mitigation: PTI 
           Type: mmio_stale_data status: Unknown: No mitigations 
           Type: retbleed status: Not affected 
           Type: spec_rstack_overflow status: Not affected 
           Type: spec_store_bypass 
           mitigation: Speculative Store Bypass disabled via prctl and seccomp 
           Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer sanitization 
           Type: spectre_v2 mitigation: Retpolines, IBPB: conditional, IBRS_FW, STIBP: 
           conditional, RSB filling, PBRSB-eIBRS: Not affected 
           Type: srbds mitigation: Microcode 
           Type: tsx_async_abort status: Not affected 
Graphics:  Device-1: Intel Haswell-ULT Integrated Graphics vendor: Dell driver: i915 v: kernel 
           bus-ID: 00:02.0 chip-ID: 8086:0a16 class-ID: 0300 
           Display: x11 server: X.Org 1.20.11 compositor: xfwm4 v: 4.18.0 driver: 
           loaded: modesetting unloaded: fbdev,vesa display-ID: :0.0 screens: 1 
           Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x286mm (20.0x11.3") 
           s-diag: 583mm (23") 
           Monitor-1: DP-1-1 res: 1920x1080 hz: 60 dpi: 82 size: 597x336mm (23.5x13.2") 
           diag: 685mm (27") 
           OpenGL: renderer: Mesa DRI Intel HD Graphics 4400 (HSW GT2) v: 4.5 Mesa 20.3.5 
           compat-v: 3.0 direct render: Yes 
Audio:     Device-1: Intel Haswell-ULT HD Audio vendor: Dell driver: snd_hda_intel v: kernel 
           bus-ID: 00:03.0 chip-ID: 8086:0a0c class-ID: 0403 
           Device-2: Intel 8 Series HD Audio vendor: Dell driver: snd_hda_intel v: kernel 
           bus-ID: 00:1b.0 chip-ID: 8086:9c20 class-ID: 0403 
           Sound Server-1: ALSA v: k5.10.0-25-amd64 running: yes 
           Sound Server-2: PulseAudio v: 14.2 running: yes 
Network:   Device-1: Intel Ethernet I218-LM vendor: Dell driver: e1000e v: kernel port: f080 
           bus-ID: 00:19.0 chip-ID: 8086:155a class-ID: 0200 
           IF: eth0 state: down mac: <filter> 
           Device-2: Intel Wireless 7260 driver: iwlwifi v: kernel modules: wl port: f040 
           bus-ID: 02:00.0 chip-ID: 8086:08b1 class-ID: 0280 
           IF: wlan0 state: up mac: <filter> 
           IF-ID-1: wwan0 state: down mac: <filter> 
Bluetooth: Device-1: Intel Bluetooth wireless interface type: USB driver: btusb v: 0.8 
           bus-ID: 1-1.3:3 chip-ID: 8087:07dc class-ID: e001 
           Report: hciconfig ID: hci0 rfk-id: 5 state: up address: <filter> bt-v: 2.1 lmp-v: 4.0 
           sub-v: 500 hci-v: 4.0 rev: 500 
           Info: acl-mtu: 1021:5 sco-mtu: 96:5 link-policy: rswitch hold sniff 
           link-mode: slave accept service-classes: rendering, capturing, audio 
Drives:    Local Storage: total: 238.47 GiB used: 179.87 GiB (75.4%) 
           SMART Message: Unable to run smartctl. Root privileges required. 
           ID-1: /dev/sda maj-min: 8:0 vendor: Samsung model: SSD SM841 mSATA 256GB 
           size: 238.47 GiB block-size: physical: 512 B logical: 512 B speed: 6.0 Gb/s type: SSD 
           serial: <filter> rev: 3D0Q scheme: MBR 
Partition: ID-1: / raw-size: 230.47 GiB size: 225.79 GiB (97.97%) used: 179.87 GiB (79.7%) 
           fs: ext4 dev: /dev/sda1 maj-min: 8:1 
Swap:      Kernel: swappiness: 15 (default 60) cache-pressure: 100 (default) 
           ID-1: swap-1 type: partition size: 8 GiB used: 0 KiB (0.0%) priority: -2 dev: /dev/sda2 
           maj-min: 8:2 
Sensors:   System Temperatures: cpu: 52.0 C mobo: 43.0 C sodimm: SODIMM C 
           Fan Speeds (RPM): cpu: 3987 
Repos:     Packages: note: see --pkg apt: 2040 lib: 1031 flatpak: 0 
           No active apt repos in: /etc/apt/sources.list 
           Active apt repos in: /etc/apt/sources.list.d/debian-stable-updates.list 
           1: deb http://deb.debian.org/debian bullseye-updates main contrib non-free
           Active apt repos in: /etc/apt/sources.list.d/debian.list 
           1: deb http://deb.debian.org/debian bullseye main contrib non-free
           2: deb http://security.debian.org/debian-security bullseye-security main contrib non-free
           Active apt repos in: /etc/apt/sources.list.d/mx.list 
           1: deb http://mirrors.dotsrc.org/mx-packages/mx/repo/ bullseye main non-free
Info:      Processes: 201 Uptime: 3h 20m wakeups: 2 Memory: 7.67 GiB used: 1.55 GiB (20.2%) 
           Init: SysVinit v: 2.96 runlevel: 5 default: 5 tool: systemctl Compilers: gcc: N/A 
           alt: 10 Client: shell wrapper v: 5.1.4-release inxi: 3.3.06 
Boot Mode: BIOS (legacy, CSM, MBR)

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 2:22 pm
by Eadwine Rose
Select all, right click, properties, permissions.

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 2:25 pm
by Charlie Brown
Jakob77 wrote: Tue Sep 19, 2023 2:19 pm...
A Terminal command that can set permissions correctly for all files (picture- and video clips) in a folder and all its sub folders can maybe do what is needed.?..
Just the -R flag (Recursive)

Code: Select all

sudo chown -R yourusername:yourusername /path/...
or first

Code: Select all

id
command and see your user id (generally it's 1000 for the 1st created user especially on Debian...) then , i.e. :

Code: Select all

sudo chown -R 1000:1000 /path/...

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 2:35 pm
by Charlie Brown
Oh, I noticed this just now:
Jakob77 wrote: Tue Sep 19, 2023 2:19 pm... changed so they all got permissions to run as programs ...
Thunar (as mentioned above) is simpler, but in a terminal sudo chmod -x ... will remove that permission .

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 3:24 pm
by towwire
Is there an answer for this one?
Jakob77 wrote: Tue Sep 19, 2023 2:19 pm
The last five files I downloaded did not have the wrong permission but after I did a copy to an external USB solid drive they were changed so they all got permissions to run as programs.

Any ideas about how that can happen or if it is common.?
In post #3 @Charlie Brown answered the following.
A Terminal command that can set permissions correctly for all files (picture- and video clips) in a folder and all its sub folders can maybe do what is needed.?

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 4:47 pm
by Jakob77
Eadwine Rose

Yes, Thunar is very elegant for single files and a couple of folders.
That is also how I discovered it is a bit out of order. :-)





Charlie Brown

Thank you.
If the folder is ~/Music
And it has some different sub folders 'jazz', 'rock' etc.
Do you think this looks like a correct syntax that will take the permission to run as program away from all the files in one shot:

Code: Select all

sudo chmod -x -R ~/Music/*.*

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 5:52 pm
by Charlie Brown
Jakob77 wrote: Tue Sep 19, 2023 4:47 pm...
And it has some different sub folders ... Do you think this looks like a correct syntax ...

Code: Select all

sudo chmod -x -R ~/Music/*.*
Yes, but no :D

If we do it in bulk, then, those which do not already have x (executable) may become problematic, new issues may occur.

Therefore, a safer way:

Normally it's

644 for files ( rw-r--r-- )

and

755 for directories ( drwxr-xr-x )


... So, you can first go to that folder (using the file manager) then "Open Terminal Here", then

Code: Select all

chmod 644 *
Just * instead of *.* because that one won't include the files with no extension. Or, you can of course do it as *.mp3 etc.


... But this time the sub-directories (just the sub-directory itself, not their contents) will also be 644 , you can chmod 755 foldername to turn them back to normal, one by one.

Yes, this will affect just the files and folders in that directory (not recursive) cause it may cause new issues, doing them one by one will be better.

Re: Calibrating permissions

Posted: Tue Sep 19, 2023 7:19 pm
by DukeComposed
Charlie Brown wrote: Tue Sep 19, 2023 5:52 pm Normally it's

644 for files ( rw-r--r-- )

and

755 for directories ( drwxr-xr-x )
Normally in a situation like this, I'd invoke a find command to chmod the directories to 0755 (or whatever I choose) and another find command to chmod the files to 0644 (or whatever I choose). I also began wondering about the exact nature of calibrating file permissions, since UNIX admins usually just set them and forget them until something comes along to break those permissions. Then we set them again and forget them again.

So I checked the man page for find and discovered that, of course, someone's already thought about this problem and one can search for files with (or without) an exact permission mask.

So I tested this feature by creating a directory called test and two files with two different permissions, then running a find command to print the files that do not have a permission mode of 0644:

Code: Select all

mkdir test
cd test
ls

touch one.txt two.txt
chmod 0644 one.txt
chmod 0700 two.txt
find . -type f \! -perm 0644
./two.txt
Running find this way will be able to print out any and all files (or with "-type d", all directories) that do not have the permission mode given. This is a great way to check for files that do not have the correct permissions and they can be corrected individually, if needed.

Re: Calibrating permissions

Posted: Wed Sep 20, 2023 4:08 pm
by Jakob77
Thank you very much.
I have to look more into the code before I ask more about it.
If I mess things up and create new issues when I with Thunar remove permission to run as a program on all files in a folder, then I am afraid I have already messed up before I asked here.




Can the reason for the problem be that the external SSD solid USB drive has been formatted by Windows 10 ?
I can't change the file permissions with Thunar on the USB drive, not even as root.
But after restoring on the target computer I can.

Re: Calibrating permissions

Posted: Wed Sep 20, 2023 5:22 pm
by FinalFox420
Jakob77 wrote: Wed Sep 20, 2023 4:08 pm Can the reason for the problem be that the external SSD solid USB drive has been formatted by Windows 10 ?
I can't change the file permissions with Thunar on the USB drive, not even as root.
But after restoring on the target computer I can.
You're very close to the answer.
This usuallly happens when the files were moved to a type of Filesystem that doesn't support the same permissions as ext4,FFS, etc.

This can be tested/reproduced by creating a file on your linux drive (which is probably ext4) and setting custom permissions, then moving it to a FAT32 formatted USB drive.
Like

Code: Select all

touch file
chmod 400 file
mv file /mnt/fatusb/
ls -al /mnt/fatusb/
and observe that the perms are different.

Reading the section 'Mount options for fat' in 'man mount' shows some useful options for this situation 'uid, gid, umask, dmask, fmask'.

Re: Calibrating permissions

Posted: Wed Sep 20, 2023 7:17 pm
by DukeComposed
Jakob77 wrote: Wed Sep 20, 2023 4:08 pm Thank you very much.
I have to look more into the code before I ask more about it.
If I mess things up and create new issues when I with Thunar remove permission to run as a program on all files in a folder, then I am afraid I have already messed up before I asked here.
"chmod 0644 filename" will change the permissions of filename to readable. This is normally the "right" permissions for a regular file to have. There are exceptions.

"chmod 0755 dirname" will change the permissions of dirname to readable + executable. This is normally the "right" permissions for a regular directory to have. There are exceptions.

"find dirname -type f" will return a list of all files in and beneath dirname.

"find dirname -type d" will return a list of all directories in and beneath dirname.

This should be enough knowledge to get you started on figuring out how to find and change permissions on almost anything.

Extra credit: find supports an "-exec" argument that can used to run a command on the files/directories it returns. It also supports a "-perm" argument I mentioned earlier, and "\!" can be used to negate the permissions check, i.e., "find dir -type d \! -perm 0755" should give a list of all directories and subdirectories that do not have mode 0755.
Jakob77 wrote: Wed Sep 20, 2023 4:08 pm Can the reason for the problem be that the external SSD solid USB drive has been formatted by Windows 10 ?
Absolutely correct. Windows filesystems, including FAT32, exFAT, and NTFS don't handle UNIX-style file modes in the same way and so using different operating systems to move files around can be troublesome. The "mtree" program can useful here, since it can check the contents of a file tree, write down the permissions of those files and directories, and save them to disk as a "spec file". It can also then repair those permissions later on if you provide the spec file.

Re: Calibrating permissions

Posted: Wed Sep 20, 2023 8:17 pm
by Charlie Brown
Jakob77 wrote: Wed Sep 20, 2023 4:08 pm... been formatted by Windows 10 ...
I wish you told that at the very beginning. The above are according to ext4 etc.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 7:26 am
by Jakob77
I don't hope it is a serious problem because it is growing.
I restored a whole computer with data from the external drive, and all the files from there has permission to run as programs.


It was my idea to just find a command or write a script that could fix it for all files and sub folders with files.
However, it might not be that easy to make if we can't separate files and folders, and before it is made it is important to know how well it can do the job.
To do that it is at least important to know what files we are dealing with. If I for instance run it in my ~/bin folder to fix files and sub folders there, then I will afterwards have to add permissions again to my scripts in bin.
The files in the bin folder I have put there myself so I know about them. I could be wrong but I see no problem in that.

If we look at the whole home folder in a MX full basic install the same way how many files are there with permission to run as programs. If it is only a couple we can maybe run a cure for whole home, and then afterwards switch the couple back in place again.
Yes, I walk like a cat around a hot plate and share some more thoughts.




DukeComposed

Thank you very much for more tips.
It will be a struggle to get my head around it but I am working on it.



Charlie Brown

Yes, but I had no idea that could be the problem.
I have never seen it before, and I have never thought much about it. I always thought I in general should be able to trust the system when a copy was done without errors.

Do you use gpt and ext4 on all drives with no exceptions then.?

It looks like fat32 is the default setting in the MX format tool, and I don't see any warnings in the menu or help.
I find it scary that it looks like it is taken for granted, that it is common knowledge.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 7:34 am
by Charlie Brown
Jakob77 wrote: Thu Sep 21, 2023 7:26 am... Do you use gpt and ext4 on all drives with no exceptions then.?..
No, I just mean ext4 (and such Linux file systems) is better for Linux-related things, especially permissions/ownerships (as already mentioned above, Microsoft filesystems already won't keep/care them).. and , say ntfs just for sharing files bw. both systems (make easy to access from both OSs ) ...

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 8:29 am
by thomasl
This is a script (called chmodr) I've used for a long time to change permissions for whole trees (as you've seen copying big directory trees from NTFS or FAT volumes can produce "wrong" permissions):

Code: Select all

#!/bin/bash
sudo find ./ -type d | while read DIR ; do sudo chmod $1 "${DIR}" ; done
sudo find ./ -type f | while read DIR ; do sudo chmod $2 "${DIR}" ; done
Start in the directory which you want to change, give the permissions for dirs and files and it'll do its job recursively:

Code: Select all

chmodr 755 644
Nowadays I'm doing two things WRT this. First I mount all NTFS or FAT volumes with the "right" permissions to start with. Secondly, I replaced the find command with a utility called fd (https://github.com/sharkdp/fd for details) which is faster, easier to use and at least for certain tasks more powerful. YMMV.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 10:38 am
by Jakob77
A lot of things are scary today. I also have a USB backup disk I dare not look at. lol




I am very grateful for more code, I just don't understand it well enough to use it yet.



As a peasant in scripting I would like a little feedback on this simple idea for a script to calibrate a folder for instance ~/Music and its sub folders (all files are just music files) :





1) Somehow establish a copy of the whole tree with folders but without files.


2) Then use chmod with 0755 on all the folders in the tree with no files


3) And use chmod with 0644 on the other tree with all the files.


4) Afterwards copy/combine in a way so the folders in the empty tree overwrites the folders in the tree with all the files.





Could that be a simple and okay way to go.?

I don't have the code for 1 or 4 yet.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 10:58 am
by Jakob77
Charlie Brown wrote: Tue Sep 19, 2023 5:52 pm
Jakob77 wrote: Tue Sep 19, 2023 4:47 pm...
And it has some different sub folders ... Do you think this looks like a correct syntax ...

Code: Select all

sudo chmod -x -R ~/Music/*.*
Yes, but no :D

If we do it in bulk, then, those which do not already have x (executable) may become problematic, new issues may occur.
I have to ask problematic how, what issues.?
Could it perhaps help to make them all +x first and then -x all.?
To me it looks like a big advantage if it is possible to reduce the edit to only the one privilege we want to change.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 11:44 am
by thomasl
Jakob77 wrote: Thu Sep 21, 2023 10:38 amA lot of things are scary today. I also have a USB backup disk I dare not look at. lol

I am very grateful for more code, I just don't understand it well enough to use it yet.
It's certainly better to be careful than to rush headlong into disaster :eek: However in the long run it'd pay if you tried to understand the basics as these things will pop up again and again.

For instance, the short (and not so hard to understand) script I showed above can be used for many similar purposes by simply changing the "chmod" part... but you'd have to have some idea what you're doing as recursive scripts and commands can be as powerful as they can be destructive... if misused.

So it always pays to double-check whether such a script (or command) works as intended, eg with one or more test runs on a set of dummy files/directories. Or you could prefix the actual command ("chmod ...") with an echo statement like this:

Code: Select all

#!/bin/bash
find ./ -type d | while read DIR ; do echo chmod $1 "${DIR}" ; done
find ./ -type f | while read DIR ; do echo chmod $2 "${DIR}" ; done
This will simply list the actions to be taken but not perform them.

Additionally, as long as you don't want to modify system directories the sudo bits are not necessary (as shown in the modified script).

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 11:46 am
by fehlix
Jakob77 wrote: Thu Sep 21, 2023 10:38 am A lot of things are scary today. I also have a USB backup disk I dare not look at. lol

I am very grateful for more code, I just don't understand it well enough to use it yet.

As a peasant in scripting I would like a little feedback on this simple idea for a script to calibrate a folder for instance ~/Music and its sub folders (all files are just music files) :

1) Somehow establish a copy of the whole tree with folders but without files.

2) Then use chmod with 0755 on all the folders in the tree with no files


3) And use chmod with 0644 on the other tree with all the files.


4) Afterwards copy/combine in a way so the folders in the empty tree overwrites the folders in the tree with all the files.

Could that be a simple and okay way to go.?

I don't have the code for 1 or 4 yet.
The above may solve your wrong file permission issue now for the files which have copied with wrong permissions.

But that's wrong strategy to get proper file permissions for files copied back from external NTFS/exFAT USB-DATA .
Instead set file permission during mount for the external Data-USB, which do have file systems types vfat[FAT32], exFAT or NTFS. Permissons for all files and directories will be set at once, when mounted e.g. with Thunar,
by placing this udisks2-conf file /etc/udisks2/mount_options.conf:

Code: Select all

# This file contains custom mount options for udisks 2.x
# placed at /etc/udisks2/mount_options.conf
# Refer to http://storaged.org/doc/udisks2-api/latest/mount_options.html
[defaults]
vfat_defaults=uid=$UID,gid=$GID,dmask=0002,fmask=0113,shortname=mixed,utf8=1,showexec,flush
vfat_allow=uid=$UID,gid=$GID,flush,utf8,shortname,umask,dmask,fmask,codepage,iocharset,usefree,showexec
# common options for both the native kernel driver and exfat-fuse
exfat_defaults=uid=$UID,gid=$GID,dmask=0002,fmask=0113,iocharset=utf8,errors=remount-ro
exfat_allow=uid=$UID,gid=$GID,dmask,errors,fmask,iocharset,namecase,umask
# ntfs3, ntfs-3g and the legacy ntfs kernel driver options
ntfs_defaults=uid=$UID,gid=$GID,dmask=0002,fmask=0113,windows_names
ntfs_allow=uid=$UID,gid=$GID,umask,dmask,fmask,locale,norecover,ignore_case,windows_names,compression,nocompression,big_writes,nls,nohidden,sys_immutable,sparse,showmeta,prealloc

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 4:03 pm
by Jakob77
thomasl

Thank you. I need to start my test computer soon.



fehlix

Thank you.
Yes, prevention is a much better strategy than cure.
I hope to be able to do the prevention just by choosing the best way to format:
viewtopic.php?t=77258
If more is needed I suppose you send it out in an automatic update.?

The script in quest is meant for repair when prevention has failed.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 4:45 pm
by fehlix
Jakob77 wrote: Thu Sep 21, 2023 4:03 pm thomasl

Thank you. I need to start my test computer soon.



fehlix

Thank you.
Yes, prevention is a much better strategy than cure.
I hope to be able to do the prevention just by choosing the best way to format:
viewtopic.php?t=77258
If more is needed I suppose you send it out in an automatic update.?

The script in quest is meant for repair when prevention has failed.
No prevention or script needed if you follow my advice given for data files.
For executable files to backup, do backup with tools to keep permissions, e.g place them into tar,
or use a permission-keeping filesystem as backup file system.

Re: Calibrating permissions

Posted: Thu Sep 21, 2023 6:07 pm
by DukeComposed
Jakob77 wrote: Thu Sep 21, 2023 10:38 am As a peasant in scripting I would like a little feedback on this simple idea for a script to calibrate a folder for instance ~/Music and its sub folders (all files are just music files) :

1) Somehow establish a copy of the whole tree with folders but without files.
2) Then use chmod with 0755 on all the folders in the tree with no files
3) And use chmod with 0644 on the other tree with all the files.
4) Afterwards copy/combine in a way so the folders in the empty tree overwrites the folders in the tree with all the files.

Could that be a simple and okay way to go.?

I don't have the code for 1 or 4 yet.
This is entirely too much work for what you need to do. The find command knows the difference between files and directories, so there is no need to mess with two separate trees and try to merge them together. You've been given several examples of how to use find, with examples that can fix all files or all directories in one operation, or both with thomasl's script. You have all the instructions you need.

If you mess up and set all files to have the wrong permissions, which you admit they already have, you can run find again and fix it.

Re: Calibrating permissions

Posted: Fri Sep 22, 2023 4:07 am
by Jakob77
How about .thunderbird.?

In all this mess I do feel a little lucky that my strategy so far always has been not to restore more than I need.
So for instance .config and .mozilla are not infected.
But I think the .thunderbird permissions for files and folders has to be checked thoroughly.

That is if Firefox and Mozilla don't do it automatically on regular basis.
If they don't maybe it could be worth asking them to do it.?

I don't know how to do it, and I have used backup with random format for years.
It might only be me who has been under informed about backup format for years but if there are many more out there I think this is a frustration we ought to spare them from, if we can.






DukeComposed

Thank you very much for your feedback.
But I understand your way is to edit one file at a time and that is a huge work when it is a lot of files in different folders.

Re: Calibrating permissions

Posted: Fri Sep 22, 2023 5:01 am
by DukeComposed
Jakob77 wrote: Fri Sep 22, 2023 4:07 am But I understand your way is to edit one file at a time and that is a huge work when it is a lot of files in different folders.
thomasl has explicitly told you what his script does and how it does it. Emphasis added:
thomasl wrote: Thu Sep 21, 2023 8:29 am This is a script (called chmodr) I've used for a long time to change permissions for whole trees (as you've seen copying big directory trees from NTFS or FAT volumes can produce "wrong" permissions):

Code: Select all

#!/bin/bash
sudo find ./ -type d | while read DIR ; do sudo chmod $1 "${DIR}" ; done
sudo find ./ -type f | while read DIR ; do sudo chmod $2 "${DIR}" ; done
Start in the directory which you want to change, give the permissions for dirs and files and it'll do its job recursively:

Code: Select all

chmodr 755 644

Re: Calibrating permissions

Posted: Fri Sep 22, 2023 1:43 pm
by Jakob77
DukeComposed wrote: Fri Sep 22, 2023 5:01 am
Jakob77 wrote: Fri Sep 22, 2023 4:07 am But I understand your way is to edit one file at a time and that is a huge work when it is a lot of files in different folders.
thomasl has explicitly told you what his script does and how it does it. Emphasis added:
thomasl wrote: Thu Sep 21, 2023 8:29 am This is a script (called chmodr) I've used for a long time to change permissions for whole trees (as you've seen copying big directory trees from NTFS or FAT volumes can produce "wrong" permissions):

Code: Select all

#!/bin/bash
sudo find ./ -type d | while read DIR ; do sudo chmod $1 "${DIR}" ; done
sudo find ./ -type f | while read DIR ; do sudo chmod $2 "${DIR}" ; done
Start in the directory which you want to change, give the permissions for dirs and files and it'll do its job recursively:

Code: Select all

chmodr 755 644
Yes, thank you again. That is one and not a several, but it looks really good, and even better since you confirm the code.
But I do hope you agree I have to know what the right file settings are supposed to be, before I for instance just edit the whole .thunderbird tree.

Re: Calibrating permissions

Posted: Fri Sep 22, 2023 9:56 pm
by Jakob77
thomasl wrote: Thu Sep 21, 2023 8:29 am This is a script (called chmodr) I've used for a long time to change permissions for whole trees (as you've seen copying big directory trees from NTFS or FAT volumes can produce "wrong" permissions):

Code: Select all

#!/bin/bash
sudo find ./ -type d | while read DIR ; do sudo chmod $1 "${DIR}" ; done
sudo find ./ -type f | while read DIR ; do sudo chmod $2 "${DIR}" ; done
Start in the directory which you want to change, give the permissions for dirs and files and it'll do its job recursively:

Code: Select all

chmodr 755 644
Nowadays I'm doing two things WRT this. First I mount all NTFS or FAT volumes with the "right" permissions to start with. Secondly, I replaced the find command with a utility called fd (https://github.com/sharkdp/fd for details) which is faster, easier to use and at least for certain tasks more powerful. YMMV.

Thank you very much. :thumbup:
I have been testing it a little now, and it looks to me it is some real magnificent code I can be proud to copy.

I want to make a script that solves it in specific folders if they exist.
For instance with a sequence like this for '~/Music' :

Code: Select all

  
            if [ -d "$HOME/Music" ] ; then
find ~/Music -type d | while read DIR ; do chmod 755 "${DIR}" ; done

fi


            if [ -d "$HOME/Music" ] ; then

find ~/Music -type f | while read DIR ; do chmod 644 "${DIR}" ; done

fi

I wonder if there perhaps is something I can write instead of "~/Music" so it will work in all languages.?

Re: Calibrating permissions

Posted: Fri Sep 22, 2023 10:12 pm
by DukeComposed
Jakob77 wrote: Fri Sep 22, 2023 9:56 pm I want to make a script that solves it in specific folders if they exist.

I wonder if there perhaps is something I can write instead of "~/Music" so it will work in all languages.?
The only thing I'd point out about thomasl's script is that find does not need to pipe its output to a while loop. This works just the same:

Code: Select all

find . -type d -exec chmod 0755 {} \;
That said, where his script says "sudo chmod $1" and "sudo chmod $2", the $1 and $2 refer to command-line arguments, the first and the second, respectively.

So if you edit it to something like this:

Code: Select all

#/bin/sh
find $1 -type d -exec chmod $2 {} \;
find $1 -type f -exec chmod $3 {} \;
The script can be run like "my_chmod.sh ~/Music 0755 0644" and will search the first argument, ~/Music, and replace the permissions on the directories with the second argument, 0755, and then replace the permissions on the files with the third argument, 0644. This prevents you from needing to hardcode any paths or permissions into the script.

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 6:40 am
by Jakob77
Thank you, I am glad it does the same so I for now can stay with the version I already have begun to test.







About this:
I wonder if there perhaps is something I can write instead of "~/Music" so it will work in all languages.?

Maybe not but if anyone knows a simple code for it please let me see it.

I think it can make a big difference.

In English it is "~/Music" in Danish it is "~/Musik" and so on..
That means if I don't find an international code, then the script will only be compatible with one language, or it will be huge.

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 8:46 am
by thomasl
DukeComposed wrote: Fri Sep 22, 2023 10:12 pmThe only thing I'd point out about thomasl's script is that find does not need to pipe its output to a while loop. This works just the same:

Code: Select all

find . -type d -exec chmod 0755 {} \;
Indeed. After switching from Windows to MX (and stumbling head first into the wonderful world of Linux file permissions :eek: ) this was among the very first bash scripts I created... after yet another tree copied from an NTFS volume, with all the perms scrambled :mad: . At some point I did what @fehlix has suggested further up and am now mounting those volumes as 755/644.

These days I have mostly abandoned such short scripts; instead I rely much more on zsh functions and a nice selection of powerful utilities.

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 3:31 pm
by Jakob77
Okay, I intend to calibrate the permissions in my home folder by building more to this script that I have named 'permicali':

Code: Select all

#!/bin/bash
# This script is being developed to calibrate permissions for some user files and folders in Linux MX 21.3
# Link to general script template: https://forum.mxlinux.org/viewtopic.php?p=725990#p725990
# Link to code and discussion: https://forum.mxlinux.org/viewtopic.php?p=745301#p745301

# Hovedsekvens begynd

case $1 in



# Sekvens begynd
    'Music'|'music'|'Musik'|'musik')

    
            if [ -d "$HOME/Musik" ] ; then
find ~/Musik -type d | while read DIR ; do chmod 755 "${DIR}" ; done

fi

            if [ -d "$HOME/Musik" ] ; then

find ~/Musik -type f | while read DIR ; do chmod 644 "${DIR}" ; done

fi

        ;;
# Sekvens slut
# Sekvens begynd
    'Billeder'|'billeder'|'Pictures'|'pictures')

    
            if [ -d "$HOME/Billeder" ] ; then
find ~/Billeder -type d | while read DIR ; do chmod 755 "${DIR}" ; done

fi

            if [ -d "$HOME/Billeder" ] ; then

find ~/Billeder -type f | while read DIR ; do chmod 644 "${DIR}" ; done

fi

        ;;
# Sekvens slut
# Sekvens begynd
    'Videoklip'|'videoklip'|'Videoclip'|'videoclip')

    
            if [ -d "$HOME/Videoklip" ] ; then
find ~/Billeder -type d | while read DIR ; do chmod 755 "${DIR}" ; done

fi

            if [ -d "$HOME/Videoklip" ] ; then

find ~/Billeder -type f | while read DIR ; do chmod 644 "${DIR}" ; done

fi

        ;;
# Sekvens slut
# Sekvens begynd
    'all')


        echo ''
        echo 'Option "all" is not ready yet'
        echo ''

        ;;
# Sekvens slut
# Sekvens begynd
    '-h'|'--h'|'help'|'-help'|'--help'|'/h')
        echo 'WARNING: Repair script under development, not tested'
        echo "Use: '${0##*/}' [Argument] - Calibrate permissions for files and folders."
        echo ''
        echo ''
        echo ''
        echo 'Arguments:'
        echo '  none                Shows way to help'
        echo '  help                Shows this help'
        echo '  musik               Calibrate sub folders and fils in ~/Musik'
        echo '  billeder            Calibrate sub folders and fils in ~/Billeder'
        echo '  videoklip           Calibrate sub folders and fils in ~/Videoklip'
        echo ''
        echo ''
        echo '  all                 Calibrate all user folders mentioned above'
        echo ''
        echo 'Examples of use:'
        echo '"'${0##*/}' musik"    Calibrate sub folders and fils in ~/Music'
        echo '"'${0##*/}' all"      Calibrate permissions in ~/Musik, ~/Videoklip and ~/Billeder'
        ;;
# Sekvens slut
# Herunder kommandoen, som benyttes, når intet argument forinden er blevet genkendt.
    *)
            echo ''
            echo 'Help syntax: "'${0##*/}' -h"'
            echo ''
        ;;
# Herover kommandoen, som benyttes, når intet argument forinden er blevet genkendt.

esac
# Hovedsekvens slut.




As you can see the folder names in the script are hard coded in Danish so it will need some edit before it can be used for another language. I might make an English version also if there is a demand for it but I still don't know if it ends up being worth sharing.



My plan is now, guided by the task, to go from folder to folder and make a specific script sequence for each one.

I don't know how far I will get, that also depends on the demand and the skills others wants to put in it.

However, I think I at least have to fix these user folders if I can:


~/Music

~/Pictures

~/Videoclip

~/bin

~/.thunderbird

~/.restore

~/.icons

~/Documents

~/Desktop



Do you know any files in them folders that are not supposed to be chmod 0644 ?
Or folders that are not supposed to be chmod 0755 ?


I know some files in ~/bin but I believe they are easy to calibrate.
Maybe launchers in Desktop are also not that difficult to handle.
I don't know about ~/.icons
~/.thunderbird and its files are important but I am almost blank.


Where can I find information about the correct state for permissions.?

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 4:00 pm
by Charlie Brown
You can compare with those on live session.

Say, "open terminal here" (or first cd to that path) and:

Code: Select all

stat -c '%a %n' *
one by one (on live session) and have a look.


Or state the path and even save in a text file to inspect later :

i.e.

Code: Select all

stat -c '%a %n' .icons/* > Anyname.txt
(Anyname.txt will be in home folder, as you might already know you can state a path for it, too)


(Though this is not recursive)

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 4:58 pm
by Charlie Brown
... Or, if you want it recursive and including everything in home folder, a crazy way:

Code: Select all

ls -laR > permissions.txt

Code: Select all

sed -i '/-rw-r--r--/d' permissions.txt

Code: Select all

sed -i '/drwxr-xr-x/d' permissions.txt
The 755 (for directories only) and 644 (for files only) lines will be deleted. It still has more than 20,000 lines but at least you can have a look scrolling if there's something very important to you ... (Do this on live session with a user terminal, no root sudo su etc..)

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 5:54 pm
by Jakob77
Thank you Charlie Brown, yes.
I have also made a copy of a new users home folder to a shared folder so I can compare.
And this command can maybe be helpful for log files:

Code: Select all

ls -lah
And it already shows it is much more complicated than I like.
I see you use the same and thank you for warning me before I use it and faint. ;-)



It suddenly hits my mind... :poke:





Jakob77 wrote: Thu Sep 21, 2023 10:58 am
Charlie Brown wrote: Tue Sep 19, 2023 5:52 pm
Jakob77 wrote: Tue Sep 19, 2023 4:47 pm...
And it has some different sub folders ... Do you think this looks like a correct syntax ...

Code: Select all

sudo chmod -x -R ~/Music/*.*
Yes, but no :D

If we do it in bulk, then, those which do not already have x (executable) may become problematic, new issues may occur.
I have to ask problematic how, what issues.?
Could it perhaps help to make them all +x first and then -x all.?
To me it looks like a big advantage if it is possible to reduce the edit to only the one privilege we want to change.

@DukeComposed

Can 'find' find only the files with permission to run like programs and chmod them '-x' .?

Re: Calibrating permissions

Posted: Sat Sep 23, 2023 6:34 pm
by DukeComposed
Jakob77 wrote: Sat Sep 23, 2023 5:54 pm Can 'find' find only the files with permission to run like programs and chmod them '-x' .?
As I said:
DukeComposed wrote: Wed Sep 20, 2023 7:17 pm Extra credit: find supports an "-exec" argument that can used to run a command on the files/directories it returns. It also supports a "-perm" argument I mentioned earlier, and "\!" can be used to negate the permissions check, i.e., "find dir -type d \! -perm 0755" should give a list of all directories and subdirectories that do not have mode 0755.
If you run "man find" it will give you a comprehensive list of options that find supports. Perhaps more importantly here, there is a section labeled "EXAMPLES" that can show you how to run find with the "-perm" argument to look only for files with a certain mode.

I found a useful illustrated guide to UNIX file permissions online, courtesy of the amazing Julia "b0rk" Evans: https://i.pinimg.com/originals/fb/65/0a ... 3fc608.jpg

That guide will explain what find is doing in this example:

Code: Select all

mkdir test
cd test
touch one two three four
chmod 0700 one
chmod 0770 two
chmod 0777 three
find . -type f -perm /111
./three
./one
./two
I also could've written it "find . -type f -perm /u=x,g=x,o=x", if that's easier to parse.

Re: Calibrating permissions

Posted: Sun Sep 24, 2023 6:52 pm
by Jakob77
Thank you.



@Charlie Brown


In a new .thunderbird I find approximately 50 files with five different permissions:

700
777
755
644
600

I don't know how smart this syntax is but I think it gives a good output for further work if needed:

Code: Select all

find .  -printf "%m %f %g\n" | column -t
And the output I could spend a cosy time knitting with chmod for lines for the script something like this:

Code: Select all

chmod 644 ~/.thunderbird/profiles.ini
next file and so on..... this far it looks okay in theory.



However...

In my backup I find more than 2.000 files with only two different permissions:

777
755

There are a lot more files, different filenames and different folders.
And maybe some permissions are changed on purpose.


How am I ever going to be able to solve this correctly.?


Is it unfair to name it a security hole in Thunderbird and expect the Thunderbird developers to fix it.?

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 4:59 am
by Eadwine Rose
Jakob77 wrote: Sun Sep 24, 2023 6:52 pm Is it unfair to name it a security hole in Thunderbird and expect the Thunderbird developers to fix it.?


Report to the TB people if there is a TB problem.

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 8:01 am
by fehlix
Jakob77 wrote: Sun Sep 24, 2023 6:52 pm In a new .thunderbird I find approximately 50 files with five different permissions:

Is it unfair to name it a security hole in Thunderbird and expect the Thunderbird developers to fix it.?
Where do you see a "security hole"?
The top Thunderbird profile folder ".thunderbird" within users home
provides only access for the user (and root) for all files and folder underneath:

Code: Select all

ls -nd .thunderbird/
drwx------ 6 1000 1000 165 Sep 10 19:56 .thunderbird/
Suggest, to study a bit about access rights in rgrd to permissions and ownership in linux file systems.
HTH

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 12:57 pm
by Jakob77
fehlix

I hope there are more defense lines without holes than just that one.
I think it is about holding the fort and that takes more than one defense line.
If you let the fort full of Trojan horses without doing anything about it for years it is not really optimal for holding the fort. No good and no safety in that. It is just an extra unnecessary risk.

And maybe it is easy to put it right for those who knows the program.


Eadwine Rose wrote: Mon Sep 25, 2023 4:59 am
Jakob77 wrote: Sun Sep 24, 2023 6:52 pm Is it unfair to name it a security hole in Thunderbird and expect the Thunderbird developers to fix it.?
Report to the TB people if there is a TB problem.
I thought you had already done that. :-)
Do you know the best place to do it.?

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 1:49 pm
by Eadwine Rose
Google :) Pretty sure you're smart enough to know where to find the place to report something on TB. :)

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 4:34 pm
by Jakob77
Yes, I can always do more.
It might just take a little longer. ;-)
If I am the only user being concerned it is also a logic consequence that the priority will be lowered.


~/Desktop and ~/.icons are already put in for advice on an external page:
https://forum.xfce.org/viewtopic.php?pid=73293#p73293

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 4:59 pm
by fehlix
Suggest, to get this topic moved into Chat area, as I don't see any really HELP requests. Advice's have been given. OP may consider to perform some self-education exercises to get an understanding of relationship between permissions and ownership on different file systems and security of Linux systems.
Thanks

Re: Calibrating permissions

Posted: Mon Sep 25, 2023 5:44 pm
by Eadwine Rose
Moved

Re: Calibrating permissions

Posted: Tue Sep 26, 2023 9:35 am
by Jakob77
Chat is fine with me but I can't take credit for the education.
I was getting nowhere if it wasn't for the friendly people who bother to give me answers.
I can spend more than half a day just failing to make %M work with ls
But if this issue hadn't grown it would have been solved to perfection long ago.

Now, as the folders are getting more complicated I don't know about the quality anymore but I think Felix draws an interesting line in the sand, and I would like to dwell by it a little.
What are the safe user folders permissions supposed to be.?

Do we agree it is 700 for:

700 .thunderbird
700 .mozilla


And 755 for the rest:


755 .conky
755 .config
755 Documents Dokumenter
755 Desktop Skrivebord
755 Pictures Billeder
755 Download Hentet
755 Public Offentligt
755 Videoclip Videoklip
755 Music Musik
755 Templates Skabeloner

?

how about ~/bin and ~/.icons

?


Is someone now going to tell me that all this doesn't matter because the main user folders permissions are protecting all its sub folders.? ;)

Re: Calibrating permissions

Posted: Tue Sep 26, 2023 9:48 am
by Eadwine Rose
I think @fehlix meant that you need to read up more on things to learn.

self-education means: not asking for help on forums, but finding info out and about on your own.

Re: Calibrating permissions

Posted: Tue Sep 26, 2023 1:59 pm
by Jakob77
No matter how much I read I might never get my head around the "find" syntax but it is really an amazing command.
This one works better than the one I used before.
It goes directly to the folder (~/.config) no matter where the Terminal is opened, and the output for this job is almost like candy:

Code: Select all

find ~/.config -printf "%M %m %p\n" | column -t
Sending output to a logfile can also be done:

Code: Select all

find ~/.config -printf "%M %m %p\n" | column -t > ~/config-perm.log










About ~/.icons I have decided to erase all added mouse cursors so there will be only the user panel icons left.

That is just:

.svg
.png
.txt
and a couple more



chmod will then be used accordingly to my list of general permissions for specific files:

Eks:

Code: Select all

chmod 644 ~/.icons/*.txt

644 for:

*.txt
*.jpg
*.xcf
*.odt
*.ods
*.gif
*.png
panelbackup - *.tar.xz



777 for:

*.svg
*.desktop


755 for:

scripts
*.desktop



This is also a home made list like the one about the folders.
Some more valid doc would be very okay.


But this was my cure for ~/.icons

Re: Calibrating permissions

Posted: Thu Sep 28, 2023 8:11 am
by Jakob77
Except for ~/.thunderbird I am now almost done making the script that fixes permissions for all files and folders that has to come from my backup, when I do a new MX install.
It is all hard coded for my tree so it is not worth sharing, and permissions can be an endless discussion, but if someone wants to discuss a folder or two, I hope there is still room for it here.


The folder discussion .... I am experimenting with internal fencing the farm some more by making folder permissions more restrictive. It might cause dysfunctionality at some point, so it is not a recommendation but I am a little curious about where that point is, and maybe others knows about it and wants to share their experience.

Both about that and the script, I believe it is best to make it on individual basis because only the user her/himself knows about the data that needs to be restored and how they are going to be used. No one else can know the folders or what is in them.

For me it has been rough to realize that permissions in my backup are messed up.
But like always in MX, we find ways to solve the issue and come out stronger... and maybe even faster.
I guess the commands I have been guided to use in this subject, when they are put in my script, can correct permissions for my whole restore (except .thunderbird) in less than two seconds. And afterwards it is brought up to a higher standard than ever before. - Thank you. :thumbup:

Re: Calibrating permissions

Posted: Mon Oct 02, 2023 3:44 pm
by FinalFox420
Jakob77 wrote: Thu Sep 28, 2023 8:11 am Except for ~/.thunderbird I am now almost done making the script that fixes permissions for all files and folders that has to come from my backup, when I do a new MX install.
It is all hard coded for my tree so it is not worth sharing, and permissions can be an endless discussion, but if someone wants to discuss a folder or two, I hope there is still room for it here.
I would not recommend hardcoding anything like this, you are bound to miss something or run into even stranger issues. Just make a fresh bkp with a properly formatted drive that supports file modes/permissions ex. ext4

OR if you need windows to hold the backup AND still preserve permissions, there is a tar option "-p" which will preserve your perms.
This is my recommendation for backups in general as it will preserve directory structure and offer many more features like compression.

tar might seem harder, but it will save you lots of time in other ways, just read up on "man tar".

Again you can mount FAT partitions with different default perms with "uid, gid, fmask, dmask, umask" under the section "mount options for fat" within "man mount".

Re: Calibrating permissions

Posted: Tue Oct 03, 2023 3:04 am
by Jakob77
FinalFox420 wrote: Mon Oct 02, 2023 3:44 pm
Jakob77 wrote: Thu Sep 28, 2023 8:11 am Except for ~/.thunderbird I am now almost done making the script that fixes permissions for all files and folders that has to come from my backup, when I do a new MX install.
It is all hard coded for my tree so it is not worth sharing, and permissions can be an endless discussion, but if someone wants to discuss a folder or two, I hope there is still room for it here.
I would not recommend hardcoding anything like this, you are bound to miss something or run into even stranger issues. Just make a fresh bkp with a properly formatted drive that supports file modes/permissions ex. ext4
I don't know if I misunderstand and maybe you have a point that MX can run okay anyway, but it is hard for me to see the point in doing a completely correct backup of permissions that are badly messed up.
By hardcoded I meant created with commands fitting my tree and the files in it. I can't really see what is wrong with that. I think missing a file or two will be better than missing them all, and I don't know what you mean by stranger issues.?
I believe it is good for safety when text files, pictures and videos are forbidden to run as programs.
And I am so happy now I have the codes in a script. I don't have to remember them, and the cure for a whole data restore is very fast.
If I was using code from the Terminal line by line it would be slow and the risk of something going wrong would be much bigger. For instance if the command for '~/Pictures' was used in '~/' it would be a disaster.

Re: Calibrating permissions

Posted: Fri Oct 20, 2023 1:03 pm
by Jakob77
I thought we were digging into the bottom of this but andymx has a backhoe with an impressive long arm, and he actually picked up something about extended permissions (ACL) I would like to clarify in this context:

Meaning of a + at the end of permissions
viewtopic.php?t=77604

Code: Select all

setfacl
setfacl 2.2.53
setfacl --help
-x, --remove=acl remove entries from the ACL(s) of file(s)
-X, --remove-file=file read ACL entries to remove from file
-b, --remove-all remove all extended ACL entries
-k, --remove-default remove the default ACL

I don't know what option to choose yet but since ACL is not used or needed in MX, will it not be logic to remove ACL from all files and folders as a part of the permission calibration routine.?








Edit 9dec2023:

I have not taken it further yet but I have located the main problem to ntfs
I should have used ext4 on the drive for my copy backup.


I have asked in Thunderbird forum but they don't answer:

File- and subfolder permissions hacked and messed up
https://support.mozilla.org/da/forums/s ... last=86169

Re: Calibrating permissions

Posted: Sun Dec 17, 2023 10:32 am
by Jakob77
Maybe I have finally found a peasant solution for .thunderbird so I can get rid of the permissions made by ntfs allowing all files to run like programs.


The rationale is as follows:

I have for many years used Fat32 for my backup, .thunderbird included.
And it looks like Fat32 takes all those permissions away, so if I just do that again and restore, the illness in quest will be cured.
There are some symbolic files I can't copy to Fat32 but Thunderbird doesn't seem to care.
So I assume it doesn't matter.

Any objections.?


I'm in the process of testing it and I can't see anything wrong.
Except, I think, something about the very important grumpy fehlix point:
viewtopic.php?p=745703#p745703
The restored .thunderbird directory has lost its restrictive permissions so they have to be fixed.

Code: Select all

chmod 700 ~/.thunderbird
Any objections.?

Re: Calibrating permissions

Posted: Sun Dec 17, 2023 11:00 am
by Eadwine Rose
Why are you asking an English question related to a technical issue in a Danish forum as a social question?? Of course you are not getting help.

Ask in a proper spot. Start here:

https://support.mozilla.org/en-US/products/thunderbird

Re: Calibrating permissions

Posted: Sun Dec 17, 2023 11:17 am
by Jakob77
@Eadwine Rose

Since you always recommend me to ask mozilla questions about the Thunderbird backup and restore in MX because it is so much better, maybe you could try it please. I can't find my way, and all I got out of it so far is trouble and wasting a lot of time.
I suppose you have also seen but maybe forgotten this example:
viewtopic.php?p=756161#p756161

Re: Calibrating permissions

Posted: Sun Dec 17, 2023 11:22 am
by Eadwine Rose
I am not your assistant, my answer was given, and that is all I know.

Re: Calibrating permissions

Posted: Thu Jan 04, 2024 11:59 am
by Jakob77
I finally managed to find a better way back into Mozilla.
So with a backpack loaded with all the good knowledge I got from this subject I have asked about .thunderbird permissions again.
If I am not the only Thunderbird user in the whole world who ever messed up the .thunderbird permissions with a wrong backup disk and want to fix it we can hope the final solution comes from them:
https://support.mozilla.org/en-US/questions/1435505

Re: Calibrating permissions

Posted: Thu Jan 04, 2024 1:20 pm
by Eadwine Rose
As a side note, reading the post on the mozilla forum. I use ntfs on my backup disk, and I have been doing so for years and years. I need those files to also be accessible to Windows.

So I doubt that in itself is the cause.

Re: Calibrating permissions

Posted: Thu Jan 04, 2024 1:41 pm
by CharlesV
Jakob77 wrote: Thu Jan 04, 2024 11:59 am I finally managed to find a better way back into Mozilla.
So with a backpack loaded with all the good knowledge I got from this subject I have asked about .thunderbird permissions again.
If I am not the only Thunderbird user in the whole world who ever messed up the .thunderbird permissions with a wrong backup disk and want to fix it we can hope the final solution comes from them:
https://support.mozilla.org/en-US/questions/1435505
Exactly what "final" solution are you looking for here? The question was answered QUITE a while back... copying files to an ntfs volume *looses* all linux rights, and as such, when you copy them back, you are pretty assured it will have lost rights there.

So.. this is NOT a "thunderbird issue" .. this is user issue. Your crossing two different file platforms and without a little adjustment .. yup.. problems. ( ie if that usb drive was fat32.. you would not have this issue - and even better ext4 ;-/ )

The reason Eadwine get's away with this is that she is doing it correctly for windows use and not bringing those files back into her linux system.

Re: Calibrating permissions

Posted: Thu Jan 04, 2024 2:19 pm
by Eadwine Rose
True.. files that I need on Windows are basically text files and docs and such, IFFFF I need them.


TB doesn't get loaded in there at all, that is a Linux exclusive.

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 5:22 am
by Jakob77
CharlesV

This subject is about a lot more than Thunderbird. Thunderbird is just the last issue that has not been clarified to the bone.
Back in the good old Ubuntu days the users were told to use Windows to format USB-drives for backup.
Changing permissions was also something we were told to be very careful with.
Ubuntu software could not do the format well enough.
And about two years ago I had a USB-drive that Mint could not format but Windows did it.
For many years format has been the only good reason for me to keep a Windows computer in my house.
In MX it looks like that eventually can change because the format tool is better.
You can always blame the user for not knowing enough so this is not an excuse, just an explanation.

You have claimed before that Thunderbird is stronger than we might think, and I am tempted to agree.
After all the mess it still works, and a few days ago I searched for a mail from 2019 and found it.
However it is still a mess, and I think it needs clarification, if not for functionality then for safety.

Thunderbird seems so close to be compatible with Linux backup to ext4, fat32 AND ntfs.
What I hope this will bring is that the Thunderbird developers build in a code that automatically will fix the rest.
With the great codes provided for this subject it looks like a task it should be possible to overcome.
Can't you imagine how much good it will do for Thunderbird to be able to make that official instead of leaving the users to feel unsafe.?
I can.! :-)

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 10:27 am
by CharlesV
Jakob77 wrote: Fri Jan 05, 2024 5:22 am CharlesV

This subject is about a lot more than Thunderbird. Thunderbird is just the last issue that has not been clarified to the bone.
Sorry, I disagree. Thunderbird HAS been clarified 'to the bone' as far as permissions go! It is NOT a software's job to maintain permissions across operating systems - and for many reasons, including security!
Back in the good old Ubuntu days the users were told to use Windows to format USB-drives for backup.
Changing permissions was also something we were told to be very careful with.
Ubuntu software could not do the format well enough.
And about two years ago I had a USB-drive that Mint could not format but Windows did it.
For many years format has been the only good reason for me to keep a Windows computer in my house.
In MX it looks like that eventually can change because the format tool is better.
You can always blame the user for not knowing enough so this is not an excuse, just an explanation.
Not sure what 'good old days' your referring too, but formatting drives has pretty much been just that. Now, the TYPE of format and where it can and cannot be used is an entirely different thing - with both linux and windows 'catching up' a bit when formatting - and you have always had to do it a certain way to get compatibility.
You have claimed before that Thunderbird is stronger than we might think, and I am tempted to agree.
After all the mess it still works, and a few days ago I searched for a mail from 2019 and found it.
However it is still a mess, and I think it needs clarification, if not for functionality then for safety.

Thunderbird seems so close to be compatible with Linux backup to ext4, fat32 AND ntfs.
What I hope this will bring is that the Thunderbird developers build in a code that automatically will fix the rest.
With the great codes provided for this subject it looks like a task it should be possible to overcome.
Can't you imagine how much good it will do for Thunderbird to be able to make that official instead of leaving the users to feel unsafe.?
I can.! :-)
Again, it is NOT Thunderbird devs that should ever be in charge of changing permissions or rights etc for a drive or area. What if I WANT my email folders to be locked down and not have the ability to change? (As in a simple method to archive and not modify files.) Or what if those files are restricted to a certain user...

The issue of a users rights belongs at the drive level. And when you toss in compatibility issues, like what this topic started off on.. you have to realize as the user when your messing up. Moving files to a drive that destroys the linux rights, then moving them back is a PERFECT example of what a user needs to be aware of - not the software, not the OS, the user. (It might help to have a warning message that rights are being removed - but otherwise - this is PEBKAC ! ( And I *NEVER* use that term! )

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 12:40 pm
by Jakob77
CharlesV

I understand the Thunderbird developers has to be careful with what they do for a skilled user like you.
But if they want to supply my demand they also have to think about how they up to some degree can make Thunderbird foolproof.

I don't know how many conditions it takes but I guess a prompt can solve it.? :
Thunderbird can see that some permissions for files and folders are changed.
If you want the permissions changed back to normal private default, Thunderbird can do it for you.
Do you want that.?

Yes or No

Oh yes I want that. :-)


In fact I want it so much that I am already beginning to test the result of these two Terminal commands:

Code: Select all

find ~/.thunderbird -type d | while read DIR ; do chmod 700 "${DIR}" ; done

Code: Select all

find ~/.thunderbird -type f | while read DIR ; do chmod 600 "${DIR}" ; done

I want Mozilla to verify it but as far as I can see Thunderbird still works well afterwards.




And I might have discovered something about ext4 that makes it even more relevant.
If I move .thunderbird to another folder and move it back again the permission is still 700
But if I copy it back to ~/ then the .thunderbird folder is changed to 755
No, I don't really believe my own eyes yet.

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 1:07 pm
by j2mcgreg
@Jakob77 wrote:
I understand the Thunderbird developers has to be careful with what they do for a skilled user like you.
But if they want to supply my demand they also have to think about how they up to some degree can make Thunderbird foolproof.
What's their incentive to do so? To them, you are just one drone in an ever changing vast hive of user bees. They charge us user bees nothing for their product and we are free to tinker with it as we wish.

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 1:20 pm
by CharlesV
Which is precisely as it should be!

The fact that YOU dont understand it does not mean that it is wrong - it means ... you dont understand it!

if you copy files to a new location unless you copy the files permissions with that copy, those files are deemed to be NEW in the folder you copy them to, and are placed under the existing folders permissions. This IS how it is done! ( linux 101 )

cp
vs
cp -p

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 2:11 pm
by DukeComposed
CharlesV wrote: Fri Jan 05, 2024 1:20 pm Which is precisely as it should be!

The fact that YOU dont understand it does not mean that it is wrong - it means ... you dont understand it!

if you copy files to a new location unless you copy the files permissions with that copy, those files are deemed to be NEW in the folder you copy them to, and are placed under the existing folders permissions. This IS how it is done! ( linux 101 )
We're now at 7 pages -- and counting -- of a thread that boils down to "I copied Linux files to a Windows file system and it lost the original permissions, let's make this Thunderbird's fault".

Beyond using "cp -p" to preserve file permissions, there's "tar -cp" for creating archive files that do the same thing. And there's mtree for creating spec files to compare and repair arbitrary file permissions. (The mtree-netbsd package is not installed by default in MX Linux, which is a shame.) These are all basic system administration tools. They come with comprehensive man pages and there are hundreds if not thousands of tutorials for their usage online. They are, as you point out, "Linux 101". Everybody has at some point accidentally run rm -rf on the wrong directory. Everybody has pooched their file permissions at some point. Most people have rendered their system unbootable somehow and had to reinstall.

These are not bugs. These are just a part of learning. One can litigate how Thunderbird is at fault for a simple mistake that was made in ignorance forever, but it will not fix the simple fact that understanding these systems, how they work and interact, will be far more useful than posting on forums like this one how one free program needs to spend its developer resources making it resistant to your whoopsie-daisies.

Re: Calibrating permissions

Posted: Fri Jan 05, 2024 2:13 pm
by CharlesV
@DukeComposed Well said... and with that - locking the topic.