Page 1 of 1

files and directorios permissions

Posted: Thu Mar 21, 2013 7:41 am
by forumisto
Hello
I'm having some "problems" with directories and files on an externel hard disk connected to my Rpi.
The HDD filesystem is ext4, and it has shared directories which I connect to them from other computers.
When a file is created, the permissions are -r--r--r--, but I have read that they has to have the permissions -rwxrwxrwx
How I do that all directories and files created in the external HDD have the permissions -rwxrwxrwx ?
Thanks

(Excuse my English)

Re: files and directorios permissions

Posted: Thu Mar 21, 2013 11:02 am
by xian
What are you using to share the directories? Relevent sections from /etc/exports or /etc/samba/smb.conf would be good to see.

Re: files and directorios permissions

Posted: Thu Mar 21, 2013 1:10 pm
by klricks
This will change all files in the current directory to [rwxrwxrwx]:
sudo chmod 777 *
Most would recommend against giving full access to all users so this would be better: (rwxrwxr..)
sudo chmod 774 *
Here is a chart:
http://www.askapache.com/security/chmod ... _0000_0777
But if you understand bit patterns then it can be done in your head without a chart.
7 = 111 = [rwx],
6 = 110 = [rw.]
5 = 101 = [r.x]
..
..
0 = 000 = [...]

You may also need to set user permissions of each file with the chown command.
This would change all files in the current directory to user root pi
sudo chown root:pi *

For more information
chmod --help
chown --help
or do Google search on these commands.

Re: files and directorios permissions

Posted: Thu Mar 21, 2013 1:30 pm
by forumisto
klricks wrote:This will change all files in the current directory to [rwxrwxrwx]:
sudo chmod 777 *
Most would recommend against giving full access to all users so this would be better: (rwxrwxr..)
sudo chmod 774 *
Here is a chart:
http://www.askapache.com/security/chmod ... _0000_0777
But if you understand bit patterns then it can be done in your head without a chart.
7 = 111 = [rwx],
6 = 110 = [rw.]
5 = 101 = [r.x]
..
..
0 = 000 = [...]

You may also need to set user permissions of each file with the chown command.
This would change all files in the current directory to user root pi
sudo chown root:pi *

For more information
chmod --help
chown --help
or do Google search on these commands.
I knew that option, but I want that files have those permission at creation time

Re: files and directorios permissions

Posted: Thu Mar 21, 2013 9:53 pm
by rnerwein
forumisto wrote:
klricks wrote:This will change all files in the current directory to [rwxrwxrwx]:
sudo chmod 777 *
Most would recommend against giving full access to all users so this would be better: (rwxrwxr..)
sudo chmod 774 *
Here is a chart:
http://www.askapache.com/security/chmod ... _0000_0777
But if you understand bit patterns then it can be done in your head without a chart.
7 = 111 = [rwx],
6 = 110 = [rw.]
5 = 101 = [r.x]
..
..
0 = 000 = [...]

You may also need to set user permissions of each file with the chown command.
This would change all files in the current directory to user root pi
sudo chown root:pi *

For more information
chmod --help
chown --help
or do Google search on these commands.
I knew that option, but I want that files have those permission at creation time
hi
you can set the umask - see: man umask
for system global usage you can use /etc/login.defs !!!! but this is global !!!!
ciao

Re: files and directorios permissions

Posted: Fri Mar 22, 2013 4:35 am
by unclejed613
it's a bad idea to set a file permission to 000. only root or the person that has write access to the folder can delete it, and i think the only thing that CAN be done with the file is to delete it. the only time anybody would ever want to use permission 000 is if only the presence of the file is required, and no contents are required..... reminds me of the old joke about "write only memory"....

Re: files and directorios permissions

Posted: Fri Mar 17, 2017 6:46 am
by Alchmist
Lets say for example I had a 1tb usb hdd attached to Rpi @ pi/mnt that contained a folder called Share

How exactly would I go about granting read/write privilages to both a networked windows pc & Rpi as well as increasing the Share folder size to say 500gb ?

Or is this even possible?

Re: files and directorios permissions

Posted: Fri Mar 17, 2017 7:02 pm
by TracyLBaker
klricks wrote:This would change all files in the current directory to user root pi
sudo chown root:pi *
Actually, this is slightly off. That command would set the user (owner) to root and the group to pi

This means that the owner of the file would be root and anyone in the pi group could read, write or execute the file(s) -- depending on the permissions, of course.

About umask, which is represented in octal:

The default umask in Raspbian is 0022. This means that when files are created, they will receive the permissions of rw-r--r--. Directories will get rwxr-xr-x (the x (executable) bit, for directories, means the directory can be accessed -- not executed.)

This is calculated by taking the kernel default values for files (0666) and directories (0777) and subtracting the umask value (0022) -- which gives an octal value of 0644 (rw-r--r--) for files and 0755 (rwxr-xr-x) for directories.

The umask value can be changed, and the change is global. It is done using the command: umask {octal_value}, and it only applies to those files and directories created after the change in the umask, for example:

Code: Select all

root@raspberry31415:~ # umask
0022

root@raspberry31415:~ # touch testfile-1
root@raspberry31415:~ # mkdir testdir-1

root@raspberry31415:~ # ls -ld ~/test*
drwxr-xr-x 2 root root 4096 Mar 17 11:50 /root/testdir-1
-rw-r--r-- 1 root root    0 Mar 17 11:50 /root/testfile-1

root@raspberry31415:~ # umask 0002
root@raspberry31415:~ # touch testfile-2
root@raspberry31415:~ # mkdir testdir-2

root@raspberry31415:~ # ls -ld ~/test*
drwxr-xr-x 2 root root 4096 Mar 17 11:50 /root/testdir-1
drwxrwxr-x 2 root root 4096 Mar 17 11:51 /root/testdir-2
-rw-r--r-- 1 root root    0 Mar 17 11:50 /root/testfile-1
-rw-rw-r-- 1 root root    0 Mar 17 11:51 /root/testfile-2
Because the kernel uses 0666 as its default for files, you cannot set a umask value to give rwxrwxrwx for files. Remember, the umask is subtracted from the kernel default. The best you can do is get rw-rw-rw, as in:

Code: Select all

root@raspberry31415:~ # umask 0000
root@raspberry31415:~ # umask
0000
root@raspberry31415:~ # touch testfile-3
root@raspberry31415:~ # ls -l testfile-3
-rw-rw-rw- 1 root root 0 Mar 17 11:55 testfile-3

Re: files and directorios permissions

Posted: Fri Mar 17, 2017 8:03 pm
by FlexibleSigmoid
Thanks for a great post on the details of umask. Very informative!

Re: files and directorios permissions

Posted: Sun Jul 29, 2018 9:33 pm
by Rem97
Hey,

sorry for poking this thread up again. I'am at the moment connecting a NTFS SSD to my RPI which seems to finally work.
The only problem is that it is completly read only :|
I have changed the settings in the fstab file which seem to 'work', cause when I look at the file properties I do have the permissions. And they change if I change them in the fstab file and reboot the Pi. But as soon as I try to make a folder or file it comes up with the error that it is read only. Even through the terminal with sudo mkdir.
Got Samba running and I can look in the files over the network. But not change them on Windows either nor making new folders.
Does someone have an idea what is going on?

Kind regards,

Rem97

Re: files and directorios permissions

Posted: Mon Jul 30, 2018 7:52 am
by ghans
Are you using NTFS-3G ? Are you sure the disk hasn't been marked as "dirty" ? This happens if you don't properly unmount / eject it and can only be fixed by Microsoft CHKDSK
on Windows...

ghans