Restrict access on a mounted device (Linux) - linux

The challenge is to allow access to only one directory on the mounted device for all users.
I have an external hard drive. I mount it using the command
sudo mount -o umask=0007,gid=0,uid=0 /dev/sdb1 /mnt/SAMSUNG/
I need to make one directory available for reading/writing to other users on this device. I cannot do this via sudo chmod 777 /mnt/SAMSUNG/my_directory, the command has no effect.
Is there some other way to do this? Maybe I'm doing something wrong?

When mounting the NTFS file system (/mnt/SAMSUNG/), there is no possibility of mounting a specific directory.

In your sudo chmod 777 /mnt/SAMSUNG/my_directory command you give
The user, rwx (Read, Write and Execute) permissions
The group, rwx permissions
And Everyone else rwx permissions
Inside of /mnt/SAMSUNG/my_directory is the thought that there should be more directories that is specific for other accounts?
If that is the case and the users are local you could do something like this:
sudo chown someuser:someuser /mnt/SAMSUNG/my_directory/someusersdir && sudo chmod 770 /mnt/SAMSUNG/my_directory/someusersdir

Related

Unable to change directory or file permission [chmod question]

I am trying to change the permission of a file to 444 (read-only).
This directory resides in a NTFS drive. All files in this drive seem to be owned by root.
This is the present permissions for the directory.
drwxrwxrwx 1 root root 0 Jul 23 11:41 xxx_directory
I've tried sudo bash and then execute chmod 444 xxx_directory to no avail.
The expected outcome was dr--r--r-- for xxx_directory.
Thoughts? Thank you.
The directories need at least R-X
First, create a mount point in a terminal using 'mkdir'. Then, type the following line to mount the partition with options 'permissions':
sudo mount /dev/sdXN -t ntfs-3g -o permissions [Mount point]
Example:
sudo mount /dev/sdb1 -t ntfs-3g -o permissions /media/Data/
Then, you will be able to edit the permissions of the files on the NTFS partition with 'chmod' and 'chown' !
Check thia reference LINUX - MOUNT NTFS PARTITION WITH PERMISSIONS
You should at least require the x permission for directories otherwise you won't be able to cd into it.
You can specify the permissions (via fmask and dmask) while mounting the partition ( or in fstab if an entry is there).
An example of an fstab entry :
#mounting by UUID
UUID=<partition UUID> /mount/point ntfs-3g user,uid=1000,gid=1000,dmask=0022,fmask=0033
This would give all directories in that partition drwxr-xr-x parmissions. Any file created will get .rw-r--r-- permissions. And the ownership would be by the user with uid 1000 so he can change permissions (without sudo)

Cannot create a file because of permissions

I want to create a file in sys/kernel/security folder in Linux.
But sudo touch test returns permission error.
After sudo chmod 777 /sys/kernel/security it fails, so I tried to change permissions for /sys folder (yes, I know this is a bad way) and sudo -i. Files does not creates, but in all cases it sets correctly - drwxrwxrwx.
And now I actually have no ideas, so I hope to your tips.
Thanks.
/sys/kernel/security is Linux Kernel Security Module (LSM) space where kernel security module can show their data both r/w.
mount | grep security
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
This is another virtual file system mounted of /sys. You can't create files here and there is no meaning at all to create files here.
See, securityfs details here!

Change permission on /usr with a sudo chmod 644 /usr

I am a trainee programmer and I have sometimes my head in the clouds..
My collegues were messing with my professional computer with ssh connections. One of them told me that the best way to prevent it was to secure my computer. In order to do this, I accidentally change the permissions on the /usr directory.
What I did just for testing was :
sudo chmod 644 /usr
Now I can't use my computer anymore! I can't change the permission back since I am not sudo anymore. On my desktop all my applications shutdown.
Is there a way to revert a chmod 644 on /usr?
There is some important work related stuff on this computer and my internship will probably be terminated if I can't recover the access to important files.
Please help !!
This command need a Sudoers password:
sudo chmod 644 /usr
So either you have a sudo password and can change the right to this file with:
sudo chmod 755 /usr
Or you friends messed with you...
You can do it by:
adding your self to sudoers on boot...
https://askubuntu.com/questions/70442/how-do-i-add-myself-back-as-a-sudo-user

Change permission of mnt directory files

I am not able to change the permission of files inside mnt directory.
Only owner (mysql) is having the rights to rwx but I am logged in using root still it is not able to change the permissions.
Is there any way of doing this?
First, it should be chmod -R 777 jol_main with -R, not -r.
Second, it seems that jol_main is on partition that is mounted as read-only. You can remount it as read-write with:
sudo mount -o remount,rw /dev/sdd3 /mnt/usb
( or without sudo if you are already a root )

How can I allow *any* user to read files from `/sys/kernel/debug/...`?

How can I allow any user to read files from /sys/kernel/debug/...? While creating a debugfs file, I realized that only root on my ubuntu machine can access the debugfs files in /sys/kernel/debug/..., even for only reading. Now while googling, I came across this article on lwn which talks about permissions on debugfs. Finally, are there any other distributions which allow any user to read from /sys/kernel/debug/test/TestFile where testFile is a file created through debugfs API? I have checked on Debian and Ubuntu machines but I cannot access /sys/kernel/debug except when logged in as root.
You could try
sudo vi /etc/init/mounted-debugfs.conf
and change
script
chmod 0700 "${MOUNTPOINT}" || true
end script
to
script
chmod 0755 "${MOUNTPOINT}" || true
end script

Resources