Unable to change directory or file permission [chmod question] - linux

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)

Related

Restrict access on a mounted device (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

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 )

Locked out of cifs mounted storage

I've been using this line in /etc/fstab for mounting a storage device to my host:
//url.to-my-storage.com/mystorage /mnt/backup cifs
iocharset=utf8,rw,credentials=/etc/backup-credentials.txt,uid=1000,gid=1000,file_mode=0660,dir_mode=0770
0 0
I was mounting it to another host, and I ran this to protect the files from change through the new host:
chmod -R 444 /mnt/backup
(I tried to protect the storage from writing from this host, which turned out to change the mode of all the storage files)
I assume the missing executable permissions what causing me this:
$ sudo mount -a
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
I tried unmounting and mounting again, that didn't help, got the same permission error when using the mount command.
ls the dir shows this:
$ ls -la /mnt/backup
?????????? ? ? ? ? ? backup
HELP !
Dismounting a "Locked Out" Network Drive
To dismount a "locked out" network drive, you can try to force the unmount:
umount -f -t cifs /mnt/backup
If you are having trouble dismounting a drive, make sure that you don't have a console open somewhere where the current working directory (CWD) on the drive which you are trying to dismount, or have a file open in an editor or player somewhere or such.
Properly Mounting a Network Drive
You should add your permissions in your mount options rather than trying to apply them afterwards. You would want to replace these mount options:
rw,file_mode=0660,dir_mode=0770
with
ro
Currently you are mounting your CIFS drive as read-write (rw), giving files read-write permission (file_mode=0660) and directories read-write-execute (dir_mode=0770). Simply mounting the drive as read-only (ro) should suffice. (If you do need to fine tune the file and dir modes, rather use umask.)
I would also advise you to double check whether you are using uid and gid correctly: if the user ID or group ID used gets deleted, that could also lead to problems.
References
https://linux.die.net/man/8/mount
https://en.wikipedia.org/wiki/File_system_permissions
https://oracletechdba.blogspot.com/2017/06/umount-lsof-warning-cant-stat-cifs-file.html
https://stackoverflow.com/a/40527234/171993

mkdir: cannot create directory `pgsql': Permission denied

I want to create directory like below:
ajs#ajs-HP-Compaq-dc5800-Small-Form-Factor:/usr/local$ mkdir pgsql
mkdir: cannot create directory `pgsql': Permission denied
But I am getting error:
Permission denied
How can I resolve and create directory pgsql in this location /usr/local$
Kindly suggest me, hope for reply.
Thanks
You have to check your user name to have permission for creating directory in the folder /usr/local$
Check your permission for the folder by the command
ls -ltr /usr
Link to refer about file permissions.
You are getting a Permission denied error because you do not have access rights to create a directory in /usr/local. You can determine the access rights for these directories by using the stat command. The output will look something like this.
$> stat -c '%n %A %G %U' /usr /usr/local
/usr drwxr-xr-x root root
/usr/local drwxr-xr-x root root
Now double check who you are. You can use the whoami command or the id command invoked below twice to reveal both username and group.
$> id -un; id -gn
In the stat output, root:root owns both /usr and /usr/local and only the owner may create (write) new directories based on the access rights. In order to create the directories, I'd recommend either becoming root or trying the command with sudo. If this is not possible, I'm afraid you'll have to create the directory elsewhere or contact the administrator of that machine.
You probably have to be root to do such things in /usr/local.

Sshfs as regular user through fstab

I'd like to mount a remote directory through sshfs on my Debian machine, say at /work. So I added my user to fuse group and I run:
sshfs user#remote.machine.net:/remote/dir /work
and everything works fine. However it would be very nice to have the directory mounted on boot. So I tried the /etc/fstab entry given below:
sshfs#user#remote.machine.net:/remote/dir /work fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user 0 0
sshfs asks for password and mounts almost correctly. Almost because my regular user has no access to the mounted directory and when I run ls -la /, I get:
d????????? ? ? ? ? ? work
How can I get it with right permissions trough fstab?
Using option allow_other in /etc/fstab allows other users than the one doing the actual mounting to access the mounted filesystem. When you booting your system and mounting your sshfs, it's done by user root instead of your regular user. When you add allow_other other users than root can access to mount point. File permissions under the mount point still stay the same as they used to be, so if you have a directory with 0700 mask there, it's not accessible by anyone else but root and the owner.
So, instead of
sshfs#user#remote.machine.net:/remote/dir /work fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user 0 0
use
sshfs#user#remote.machine.net:/remote/dir /work fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user,allow_other 0 0
This did the trick for me at least. I did not test this by booting the system, but instead just issued the mount command as root, then tried to access the mounted sshfs as a regular user.
Also to complement previous answer:
You should prefer the [user]#[host] syntax over the sshfs#[user]#[host] one.
Make sure you allow non-root users to specify the allow_other mount option in /etc/fuse.conf
Make sure you use each sshfs mount at least once manually while root so the host's signature is added to the .ssh/known_hosts file.
$ sudo sshfs [user]#[host]:[remote_path] [local_path] -o allow_other,IdentityFile=[path_to_id_rsa]
REF: https://wiki.archlinux.org/index.php/SSHFS
Also, complementing the accepted answer: there is a need that the user on the target has a right to shell, on target machine: sudo chsh username -> /bin/bash.
I had a user who had /bin/false, and this caused problems.

Resources