In Linux, you share files and directories by using groups.
When you create a file or directory, you are set as the owner of that file or directory.
If you are a member of a group and that group owns a directory, then you can interact with the files in that directory as if you were the owner.
Changing File and Directory Ownership
You can view and update file ownership information in the Files application.
Navigate to the file or directory, right-click the item and click Properties from the context menu.
In the following example, the mynotes.txt file is owned by the logged-in operator1 user, so the Owner label displays Me.
The drop-down list for the Group field displays operator1 as the group owner.
On the command line, you use the ls command with -l option to view file ownership information.
In the following example, the operator1 user is a member of the finance group.
The listed files are owned by the operator1 user, but the Artifacts directory is owned by the finance group.
This configuration allows the operator1 user to create files in the Artifacts directory, even if the /Projects/Artifacts/ directory is not the home directory for the operator1 user.
[user@host ~]$ ls -l /projects/
total 46824
drwxr-xr-x. 2 operator1 finance 6 Oct 31 02:17 Artifacts
-rw-r--r--. 1 operator1 operator1 5371104 Oct 31 02:06 FirstQuarter.xlsx
-rw-r--r--. 1 operator1 operator1 42188800 Oct 31 02:11 LinuxCommands.pdf
-rw-r--r--. 1 operator1 operator1 383800 Oct 31 02:04 standup-notes.txt
You update file ownership by using the chown command.
The chown command requires two arguments: the new owner (either a user or a group) and the target file or directory.
You provide the user or group in the user:group format.
You must use a colon (:) to separate the user from the group, or to define only the group.
In the following example, two users interact with a directory.
Note the username in the command prompt to identify which user is running which command.
The developer1 and developer2 users are members of the java-devs group.
The developer1 user and the dev1 group own the /Projects/Java-code directory.
The directory has the required permissions for group members to create files.
[developer1@host ~]$ ls -ld /Projects/Java-code/
drwxrwxr-x. 2 developer1 dev1 6 Oct 31 12:37 /Projects/Java-code/
The following command fails because the developer2 user is not a member of the dev1 group.
[developer2@host ~]$ touch /Projects/Java-code/README.md
touch: cannot touch '/Projects/Java-code/README.md': Permission denied
In the following command, the developer1 user changes the group owner of the Java-code directory to the java-devs group.
The developer1:java-devs argument sets the user owner as developer1 (no changes) and the group owner as java-devs.
This action grants access to the developer2 user through the java-devs group.
The developer1 user is still the user owner of the directory.
[developer1@host ~]$ chown developer1:java-devs /Projects/Java-code/
[developer1@host ~]$ ls -ld /Projects/Java-code/
drwxrwxr-x. 2 developer1 java-devs 6 Oct 31 12:37 /Projects/Java-code/
Because the developer2 user is a member of the java-devs group, the developer2 user can create a file in the Java-code directory.
[developer2@host ~]$ touch /Projects/Java-code/README.md
[developer2@host ~]$ ls -l /Projects/Java-code/
total 0
-rw-r--r--. 1 developer2 dev2 0 Oct 31 15:46 README.md