0

I have created a folder called /home/projects, to do this I had to use sudo mkdir /home/projects because it's inside the home folder.

Initially the folder had these permissions:

drwxr-xr-x  4 root     root       4096 Dec 29 16:53 projects

I then added two users user1 and user2 to the group developers.

I then changed the owner of the folder to user1 because I read that sometimes if you're not the owner of the folder changes might not work. I did this with:

sudo chown -R user1 /home/projects

I then changed the group with ownership of the folder (while logged in as user1) to developers like this:

sudo chgrp -R developers /home/projects

The output of ls -la is:

drwxr-xr-x  4 user1  developers 4096 Dec 29 16:45 projects

Both users are part of the group, I checked with:

groups {username}

Despite all of this, user2 still cannot create folders or files inside /home/projects. The user can enter the folder and view everything inside of it, but nothing else.

The strangest thing about this is that user2 was able to create/upload and delete files and folders inside /home/projects for about a week, before Ubuntu suddenly started giving him permission denied errors.

If I set user2 as direct owner of the folder, the user is able to do everything, but of course then the other one can't.

What is going on here?

EDIT: User Zeta suggested I give the group w access, so now the folder is like this:

drwxrwxr-x  4 user1 developers 4096 Dec 29 16:45 projects

Instead of a permission denied I get this error:

mkdir /home/projects/New directory: received failure with description 'Failure'

Operating system is Gnu/Linux (Ubuntu 18.10)

  • Should I do chmod for the group or for the user directly? – Eight Dec 29 '18 at 17:09
  • Tried it, a new error appeared – Eight Dec 29 '18 at 17:18
  • You do not need sudo to create a directory in your home , set the sticky bit, the shared group needs to be primary, consider acl – Panther Dec 29 '18 at 17:19
  • Without using sudo I cannot create a folder inside /home, it tells me "Permission denied". I am not logged in as root, but as a user with sudo privileges – Eight Dec 29 '18 at 17:21
1

As long as you are convinced that a shared directory is the best way to go (version control, like github, is vastly superior for many use cases), you'll want to do the following:

  • as user1, chmod g+ws /home/projects

This gives write permission to the directory and sets the setgid bit, so that any files and directories created inside the directory will automatically go to the correct group.

  • as both users, add umask g+rwx to the shell startup file. This way, the files created by one user will, by default, be accessible (and writable) by all members of the group.
  • Could you go into more detail about adding umask g+rwx to the shell startup file? Thank you – Eight Dec 29 '18 at 17:28
  • umask sets the default permissions for any files created by the user. This is very useful, since you are going to forget to chmod your new files more often than not. Most systems have a default umask that blocks group access, so you'll want to change that for the users that need to co-operate on the project. – Bass Dec 29 '18 at 17:32
  • I'm really sorry to bother but what I mean is that I'm not entirely sure of how to do what you told me to do. How do I add umask g+rw to the shell startup file as both users? – Eight Dec 29 '18 at 17:36
  • That depends on a lot of things. I'm going to guess the users are using Bash (it's the default on Ubuntu at least; you can use echo $SHELL to confirm), in which case you can add the line to a file called .bash_profile in each user's home directory. – Bass Dec 29 '18 at 17:46
  • I can see a ".profile" I'm going to suppose it's that. – Eight Dec 29 '18 at 17:52
0

You don't have group write, so the group can't write.

Also see file access control lists (setfact/getfacl). Set up a default group, so that all new files/directories are added to the group developers.

Installing aclutils

If using Debian, or derivatives such as Ubuntu, then install with apt-get install acl. You may also need to activate for your file-system (But maybe not: I am using ext4, I don't seem to have configured it in my mount options, and it is working)

  • Could you link me to, or explain how setfact and getfacl work? Can't find a lot about them. Also can I set these for files created in this specific folder, or is this a global thing? – Eight Dec 29 '18 at 18:51
  • it is per file man setfacl. But what OS are you on? – ctrl-alt-delor Dec 29 '18 at 23:17
  • So acl was already installed, what do I do with it now? – Eight Dec 31 '18 at 17:34
  • Read the manual: You can add groups/users to the access control list (that is give them any of rwx permissions). You can also add default permissions, so that new files get these new permissions. Something like setfacl -R -m d:g:developer:rwx g:developers:rwx (Note you will be much better of with a revision control system, it will solve your current problem, avoid the down sides of shared directories, aid backup, and give you revision control. Mercurial, with bitbucket.org are easy to learn). – ctrl-alt-delor Dec 31 '18 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.