I have a user ftpadmin:
-bash-3.2$ id ftpadmin
uid=10001(ftpadmin) gid=2525(fsg) groups=2525(fsg),10005(git)
The important group to note is "git"
Then I have my git repository:
ls -al
drwxrwxr-x 7 git git 4096 Apr 20 14:17 fsg
So ftpadmin is a member of git, and git has given all permissions to people in the group. Why do I see this when I login as ftpadmin:
-bash-3.2$ ls -al /home/git/
ls: /home/git/fsg: Permission denied
...
Seems like I should have permission...
Update The permissions on /home/git are
drwxrw-rw- 6 git git 4096 Apr 26 09:20 git
still looks good...
Update New permissions on /home/git are:
drwxrwxrw- 6 git git 4096 Apr 26 09:20 git
Permissions on /home/git/fsg are:
drwxrwxr-x 7 git git 4096 Apr 20 14:17 fsg
However, I still get
ls: /home/git/fsg: Permission denied
ls: /home/git/fsg: Permission denied
Wanted to give mpez0 a +1 specifically, for his answer "You need the group "x" bit set in the directory to allow group searches. The "rw-" permissions allow opening a file given its name (r) or creating a file (w), but not listing or searching the files (x)."
Its so easy to forget, and his solution is buried in the middle. This is definitely a problem for new Linux users with respects to file / directory permissions for users and groups.
Everything Avery said was right on the money, again wish I could give you a +1 as well.
Figure another more detailed example might help new Linux users (not looking for any credit, just providing another example for clarity). On my own pc I wanted to create an additional user for a specific development project. Was testing some SSH, SFTP issues between my machine and a co-located server out on the web. Got the same "Permission denied" error after setting everything up...and yes it looked correct except for the searching issue based on the permissions for other that mpez0 pointed out.
Note: For new Linux users, permissions are user, group, other or rwx, rwx, rwx respectively and would look like this
For 'other' we are reminded its NOT enough to find/search for the directory, thus the error message.
Here is what I did, (encountered the error message in step 6)
1) created a user, hoiuser (to see user information, you can use the finger cmd, "finger hoiuser" or read the 'cat /etc/passwd' file)
2) created a group, hoidevs (added user "hoiuser" to group)
Remember you have to log off and log in again for the new “group” permissions to be associated with the Account ID.
3) chgrp hoidevs for directory /home/userz/data/Sites/hoi and created a place for the files
4) Opened a Terminal Window, user userz was active
5) su - hoiuser (switched to user hoiuser)
6) Attempted to cd /home/userz/data/Sites
7) Changed the permissions for Sites
And voila problem fixed....here is proof
Even us experienced Linux/Unix users need a reminder now and again.
As was pointed out, it is not enough to just give the correct permissions to the directory where the files are, you also need to make sure all the directories leading up to that directory have the correct permissions, especially the ability for "other" to "search" and look for the directory and the files. Hardly intuitive when x means execute, right.
My subdirectory structure was: /home/userz/data/Sites/hoi/html/
Starting from home
This was my directory structure BEFORE the chmod
This was my directory structure AFTER the chmod
Note the only change was the r-x permissions for 'other' for the directory 'Sites'. Hope this helps others, it was a good refresher for me.
You have to have permissions on the directory that contains the file to get to the file. What are the permissions on /home/git? (yes, Zoredache, I gave you a +1 for pointing that out)
Follow-up: You need the execute (x) bit set for the group in order for that group to enter the directory. Think of it as a rough analog to the windows "Traverse Directory" setting. Without it, access will be denied for the group. If you're desperate, you can do:
Try the following and post the message from each:
Each one of those should be accessable by
ftpadmin
. If any one of them isn't, then it will stop you from getting into/home/git/fsg
.Try logging in again, or running
su - ftpadmin
to login inside the current shell. Since groups are set when you log in, it might just be that you added so-and-so to a group but the old group settings are still being used.After changing groups of an user X via root access, you must log out and log in again with that user X, otherwise new groups won't be taken into account