1

I have granted full access to a folder as follows:

sudo chmod 777 -R /media/sharedfolder

However when a new subfolder is created by User A, that subfolder is not accessible by other users. How can I automatically grant full access to any new folders/files/subfolder that are created in this folder?

I'm running Ubuntu 20.04.6 LTS

4
  • never use 777. "others" have nothing to do on your external disk. Nor does "group" generally need execute permissions. Better to use 750. And you need to check your mount options. It probably is lacking mask , userid and or groupid settings,
    – Rinzwind
    Commented Dec 3, 2023 at 18:06
  • I have no idea how to use masks - is this what is required to achieve what I want to do? This is the mount command: UUID=bd4f641a-f011-49c6-ae4f-7ae9db49a3c1 /media/sharedfolder ext4 defaults,nofail 0 0
    – Ian M
    Commented Dec 3, 2023 at 18:25
  • Please edit your question to add whatever information you get. Do not use Add Comment.
    – waltinator
    Commented Dec 3, 2023 at 20:43
  • @Rinzwind, if you want users within the group, to be able to list the files in the directory, to be able to create subdirectories, or create new files within the directory, then they need execute permissions. It is very common to have x permission for group. As for never use 777, that is also incorrect, there are often times a tmp directory needs open permissions, you might have a upload directory on a webserver, allowing 777 on one directory, that is used for one specific reason is common. With that said, it is not recomended to use 777 often. Commented Dec 4, 2023 at 3:29

2 Answers 2

1

You can set the default ACLs(file access control lists) specific to this particular directory like so:

for i in u g o
  do
    setfacl --default --modify "$i"::7 /media/sharedfolder
    done

... where u g o are user, group and other, the skipped empty field in :: means any user/group, the 7 is a bit-wise combination of read (4), write (2), and execute (1) which, in this case, is equivalent to rwx which can alternatively be used instead and /media/sharedfolder is the desired target directory.

The target directory and any sub-directories/files to be created under it from now on will be set to those permissions by default.

However, on files, the execution bit is not set by default (not even with umask 0000) ... It'll need to be set manually after the files have been created if/when it's required ... Read and write bits, however, can be set by the default permissions.

1
  • Many thanks for this. I have run the script as suggested and it seems to have done the job perfectly!
    – Ian M
    Commented Dec 5, 2023 at 12:13
1

The mask of any file/directories created by a user is defined by the users umask. The umask is generally set in the users .bashrc or via /etc/login.def system wide.

The standard umask in Ubuntu is 022 - this results in new files 644 and directories as 755.

***NOTE Only use 777 if you are sure you want everyone to have permission to view, and run files within this directory, using 777 in the wrong place, is a major secuirty risk.

If you really really want User A to create directories with a 777, then modify User A umask in .bashrc in the Users home directory.

Alternatively, you could create a little script eg:

file: /usr/bin/mkmediadir

#!/bin/bash
mkdir $1
chmod 777 $1 

set the script permissions to allow executable.

chmod +x /usr/bin/mkmediadir

now all User A needs to do when you want to create a new directory in /media/sharedfolder is run mkmediadir and the permissions will be set. This would remove the risk that User A creates a sensative directory with open permissions in error.

1
  • The default umask on Ubuntu is 0002 ... 0022 is under the root/sudo user ... Please compare umask && sudo bash -c 'umask' ... I hope I recalled correctly :)
    – Raffa
    Commented Dec 4, 2023 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .