forumisto
Posts: 386
Joined: Fri Mar 16, 2012 8:41 am

files and directorios permissions

Thu Mar 21, 2013 7:41 am

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)

xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Re: files and directorios permissions

Thu Mar 21, 2013 11:02 am

What are you using to share the directories? Relevent sections from /etc/exports or /etc/samba/smb.conf would be good to see.

klricks
Posts: 6443
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: files and directorios permissions

Thu Mar 21, 2013 1:10 pm

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.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

forumisto
Posts: 386
Joined: Fri Mar 16, 2012 8:41 am

Re: files and directorios permissions

Thu Mar 21, 2013 1:30 pm

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

User avatar
rnerwein
Posts: 52
Joined: Fri Feb 22, 2013 8:00 am
Location: bayrisch kongo - germany

Re: files and directorios permissions

Thu Mar 21, 2013 9:53 pm

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
"What is the robbing of a bank compared to the FOUNDING of a bank?" Berthold Brecht

unclejed613
Posts: 55
Joined: Sun Jan 15, 2012 10:49 pm

Re: files and directorios permissions

Fri Mar 22, 2013 4:35 am

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"....

Alchmist
Posts: 3
Joined: Fri Mar 17, 2017 5:52 am

Re: files and directorios permissions

Fri Mar 17, 2017 6:46 am

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?

User avatar
TracyLBaker
Posts: 39
Joined: Sat Feb 18, 2017 3:44 pm
Location: Phoenix, AZ

Re: files and directorios permissions

Fri Mar 17, 2017 7:02 pm

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

[email protected]:~ # umask
0022

[email protected]:~ # touch testfile-1
[email protected]:~ # mkdir testdir-1

[email protected]:~ # 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

[email protected]:~ # umask 0002
[email protected]:~ # touch testfile-2
[email protected]:~ # mkdir testdir-2

[email protected]:~ # 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

[email protected]:~ # umask 0000
[email protected]:~ # umask
0000
[email protected]:~ # touch testfile-3
[email protected]:~ # ls -l testfile-3
-rw-rw-rw- 1 root root 0 Mar 17 11:55 testfile-3
Red Hat Academy Professor - Estrella Mountain Community College
5 Pi 3 Model B+s: 1 headless media/NFS/SMB server - Raspbian Jessie, 1 Kali Linux w/fruitywifi, 1 headless CentOS 7 webserver (Apache, SELinux, firewalld, autofs, etc...), 2 in waiting

FlexibleSigmoid
Posts: 61
Joined: Sun Jul 03, 2016 1:33 am

Re: files and directorios permissions

Fri Mar 17, 2017 8:03 pm

Thanks for a great post on the details of umask. Very informative!

Rem97
Posts: 1
Joined: Sun Jul 29, 2018 9:26 pm

Re: files and directorios permissions

Sun Jul 29, 2018 9:33 pm

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

ghans
Posts: 7863
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: files and directorios permissions

Mon Jul 30, 2018 7:52 am

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
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Return to “General discussion”