Linux file default permissions - linux

I just set up a apache server on my Raspberry pi. To make the development easier I shared the /var/www/html folder with samba.
I'm able to create new files from my computer in the Pi folder, but they have the following permission :
-rwxrw---- 1 pi pi 52 juin 10 17:54 test.php
With those permissions Apache is not able to read the file.
So each time I need to send the following command to make the file readable by Apache :
chmod a+rwx test.php
Then my permission are :
-rwxrwxrwx 1 pi pi 52 juin 10 17:54 test.php
So ok, after sending this command, it's works... But I am trying to find the command to set up the default file permissions to "-rwxrwxrwx "
I'm new with linux so maybe it's easy to fix.... Do you have any ideas ?
Thanks a lot,
Maxime

Thanks for your answers.
the solution was to change the "create mask" value to 0775 in the smb.conf file.
Maxime

For changing default permissions of the file created, you can use umask command. umask is user mask which is used whenever a new file is created.
umask is a three digit number with octal base. First digit decides the user permissions, second is for group while third determines the permissions for others.
umask value is used in inverted/complemented form though. That means to determine the required umask value for the permissions you want, subtract the permissions (in octal form) from 666. The result should be used as your umask value. e.g. if you want to set default permissions to rw-r--r-- (which is 644 in octal) subtract 644 from 666. The result (022) is your umask value.
To set value for umask you can simply use:
umask 022
command.
For your case here, I think you can use
umask 000

The default umask value is 0022, which decides the default permission for a new file or directory. The default permission for a directory is 0777, for files the permissions are 0666 from which the default umask value 0022 is deducted to get the newly created files or directory permission.

Related

Permission inheritance of directories in Linux

So by default my / directory is chmod 555. I ran the following to test something out:
sudo chmod 777 /
mkdir /dss
sudo chmod 555 / # reset permissions
if I run stat /dss then it shows
File: ‘/dss’
Size: 6 Blocks: 0 IO Block: 4096 directory
Device: 10302h/66306d Inode: 5802557 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 1001/ssm-user) Gid: ( 1002/ssm-user)
Access: 2021-06-30 22:01:44.478434800 +0000
Modify: 2021-06-30 22:01:44.478434800 +0000
Change: 2021-06-30 22:01:44.478434800 +0000
I expected /dss to inherit 777 permissions from / at the time it was created? And if I create any subdirectories under /dss, they're all 755. What's happening here?
You are matching two different things in this question, chmod is a command to set the permissions for a specific path or file, you can do it recursively in differents ways but that you are asking is umask value that determinants the permissions given to a file when is created.
If you want to check the value setting, you have to execute the command “umask”, this could tell you the value as default that the user has to create files.
If you want to change the umask value you can run the following command to set it.
umask 022
Keep in mind that the numbers that are you described in the command above are the permissions that won't give to the file, so, in this case, will be generated with 755.
Please refer to the next table.
Number
Permission
4
read
2
write
1
execute
This command isn’t permanent, once you logout this will be lost and set as default, if you want to change the value in a permanent way you need to set up in “/etc/profile” or “bashrc” and add the command above, you can refer to[1].
BR.
[1] https://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

Redirected files are generated with NO permission

I have a shell script prepared and tested successfully in testbed (linux) server, and I have moved this to my production server (under same user, group which I have used in testbed) with read/write/execute permissions. when I execute script in production it gives error, because redirect files get generated in by script (in same folder) with no permission (--------), hence my scripting gets failed.
I had not faced this problem in testbed server, I have tested my script successfully under user level only.(not root user level)
I already tried giving user/group permission for my script folder/files, and user/group are same one's that I have successfully tested in testbed Linux server.
how I moved my script to production:
unzip -K script.zip
chmod 777 script.zip
cd scriptfolder
./execute.sh
generated redirect file (gmon.out) in same script folder
ls -lrt
---------- 1 user group 42023 May 15 10:00 gmon.out
expected redirected file
-rw-r----- 1 user group 42023 May 15 10:00 gmon.out
Please help
This is probably because of the umask, as noted by Socowi in the command.
Umask dictactes the permission of any new file you create.
You can check the current value of umask with the umask command.
You can change the umask in your profile file (like your .bashrc if you use bash) with the umask 0027 command, for instance.
For more information about umask :
https://fr.wikipedia.org/wiki/Umask
http://man7.org/linux/man-pages/man1/umask.1p.html

How to set different permissions for directories and files using umask and fuse

I use fuse to mount some directories on Ubuntu. The user should have rwx on directories and rw- on files.
Now doing this with setfacl is quite easy. Doing setfacl -R -d -m u::rwX,g::rwX,o::--- dir/ does the job perfectly fine.
But how to do this with umask?
What you should know about umask first is that umask is a mask; it is not a number to be subtracted.
It turns off permissions that would normally be granted.
Masking is not the same as subtracting, e.g. 666 masked with 001 is still 666 and 666 masked with 003 is 664.
The mask turns off permission bits. If they are already off, the umask makes no change.
Make sure you are in the directory you wanna assign permissions to and do the following:
this link answers exactly what you're looking for!
https://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
hope this helps.

linux umask for sudo and apache

I want to make 002 the system-wide umask for all users (in Ubuntu). I managed to do so for all regular users using the instructions provided by #ephemient (From this post, thanks for that!). However I got 2 more problems.
Firstly, when sudoing, the root user seems to follow it's own settings, making files with the permissions 644 (instead of 664).
Secondly, the apache user (www-data) also seems to follow it's own settings (the same used by root?), making files with the permissions 644 (instead of 664). I don't like to put umask 002 in /etc/apache2/envvars, I'd rather change the setting assigning the 002 umask to apache in the first place.
How can I tackle those last 2 issues?
I solved my own problems.
For the sudo permissions, I executed sudo visudo and added the line Defaults umask = 0002 to the end.
For the Apache user, I added the line umask 0002 to the end of the /etc/apache2/envvars (I couldn't find any better solution).

Linux set permissions to folder (ftp and Apache2)

I set up a folder (/srv/www/). In this folder, all Apache virtual hosts are located.
For example;
/srv/www/domain.com
/srv/www/domain2.com
I created a group ftp-users and executed the following commands:
groupadd ftp-users
chmod 755 /srv/www
chown root:ftp-users /srv/www
Whenever I upload a file to /srv/www/domain.com/public_html/ it gets CHMOD 600 by default, this has to be 755.
How do I do this?
Using Debian Squeeze, Apache and vsFTPd.
From the vsftpd manpage:
file_open_mode
The permissions with which uploaded files are created. Umasks are applied on top of this value. You may wish to change to 0777 if you want uploaded files to be executable.
Default: 0666
local_umask
The value that the umask for file creation is set to for local users. NOTE! If you want to specify octal values, remember the "0" prefix otherwise the value will be treated as a base 10 integer!
Default: 077
Play around with theese two values to achiev what you want ;)

Resources