Folder permission issue
Solution 1
Directories require the executable flag, so try sudo chmod -R 776 /tmp/test
.
Linux/Unix requires the execute bit in order for the user to enter a directory and access its contents, this includes listing what is inside it. Directory execute flags behave differently than a file's read flag.
Files within can be 666
however.
Solution 2
Directory permissions are slightly different than standard file permissions. Instead of read/write/execute like a file, directory permission bits are as follows:
4 (r--)
: The directory's contents can be shown (ls
)
2 (-w-)
: The directory's contents can be modified (create/delete/rename)
1 (--x)
: The directory can be accessed withcd
or similar.
Note that for directories, the w
permission will not take effect unless x
is also set.
In your case, your permission is set to bit 6 (rw-
), which has the following effects:
- You can see the contents of the given folder
- You can not see the metadata for the folder
- You are not permitted to
cd
to that folder or any child folders - You can not edit the metadata (as
x
is not granted) - You are not permitted to open any file within this part of the directory tree
To fix this, simply re-add the x
bit to the file:
chmod a+x /path/to/file
This is also why the default folder permission is either 0755
or 0775
while files tend to be 0644
or 0664
: folders, unlike files, are effectively useless without x
.
Related videos on Youtube
Shameerariff
Updated on September 18, 2022Comments
-
Shameerariff over 1 year
Kindly do not consider this as duplicate. I have created a folder as root in the directory /tmp/test/ as well as some subfolders too. I have changed the permission to read and write for all the users and groups, including the root.
$ sudo chmod -R 666 /tmp/test/
on issuing the
$ ls -l /tmp/test/ ls: cannot access '/tmp/test/db': Permission denied ls: cannot access '/tmp/test/sp': Permission denied total 0 d????????? ? ? ? ? ? db d????????? ? ? ? ? ? sp
I get like this, Here I am unable to create a new file or directory.$ printf 'test' >/tmp/test/sp/test
bash: /tmp/test/sp/test: Permission denied It sounds confusing to me.
-
steeldriver over 6 years
-
-
Shameerariff over 6 yearsHi @Dorian yours is doing good, but can you give me an option to prevent users on executing a script.
-
Shameerariff over 6 yearsI got your option, In-fact your explanation was so good. Is there is any way to prevent the user on executing any BASH scripts.
-
Kaz Wolfe over 6 years@Shameerariff This is a different question, and would best be asked as one. However, you will want to do this by denying execute to all shell scripts in that folder.
-
Shameerariff over 6 yearsYou are correct, can you give me solution on this comment, Thank you in advance
-
Delorean over 6 years@Shameerariff To set permissions on only files and not directories, try
find . -type f -exec chmod 644 {} \;
in the root folder where you want to set the permissions. DO NOT RUN THIS JUST ANWHERE! It should find all your files and set read-write permissions and ignore directories. -
Shameerariff over 6 yearsthanks for your kind help, But still I can create and execute a script. This folder is for the shared user, I do not want any user to create or execute any kind of script for the security reason. Kindly excuse me, I am a developer not a SysAdmin, So my approach in this case may be bit idiotic to professional sys admin.
-
Delorean over 6 years@Shameerariff No worries! And I apologise for my original answer. Please do it again but with
sudo chmod -R 776 /tmp/test
. This will set read-write-execute(77) for owner and group, and read-write(6) for "everyone else". Now I think the user can write a new file but not make it executable. I don't have a Linux machine to test it myself but that should work. -
Shameerariff over 6 yearsNow the permission for the regular user was gone . Now it looks like ls -l /tmp/test ls: cannot access '/tmp/test/db': Permission denied ls: cannot access '/tmp/test/test': Permission denied ls: cannot access '/tmp/test/sp': Permission denied ls: cannot access '/tmp/test/test.sh': Permission denied total 0 d????????? ? ? ? ? ? db d????????? ? ? ? ? ? sp d????????? ? ? ? ? ? test -????????? ? ? ? ? ? test.sh
-
Delorean over 6 years@Shameerariff But you were able to run
ls
when the folder permissions were 777? -
Shameerariff over 6 yearsYes I can do anything on 777 but on 776 I am getting the problem