---
title: "How to Make Directory Sharable in Linux"
description: "Here's an easy way to make file or directory sharable in Linux"
url: https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/
date: 2022-12-31
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2022/12/pexels-photo-12317177.jpeg?fit=1625%2C1300&ssl=1
categories: ["Linux"]
tags: ["Share a File in Linux"]
type: post
lang: en
---

# How to Make Directory Sharable in Linux

When you create a new file, Linux assigns the file permissions of the newly created file using your default UID and GID. To allow others access to the file, you need to either change the security permissions for the `everyone` security group or assign the file a different default group that contains other users.

Related[Linux ‘su’ these are popular real life examples](https://srinimf.com/2017/10/24/linux-su-these-are-popular-real-life-examples/)

*Sharing-Folder-Linux *

Related[Differences Between Find and Locate in Linux](https://srinimf.com/2020/08/22/linux-find-vs-locate-quick-differences/)

**ON THIS PAGE**

1. [What’s file sharing](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/#what-s-file-sharing)
2. [How Linux stores information about a file](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/#how-linux-stores-information-about-a-file)
3. [Easy ways to share a file or a directory](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/#easy-ways-to-share-a-file-or-a-directory)
4. [Steps to make a file or a directory sharable](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/#steps-to-make-a-file-or-a-directory-sharable)

Related[5 Linux Directory Commands Useful for Beginners](https://srinimf.com/2022/01/09/5-linux-directory-commands-useful-for-beginners/)

## What’s file sharing

It means giving access to others so that they have permission on it.

## How Linux stores information about a file

Linux stores three additional bits of information for each file and directory:

- **Set user ID (SUID):** When a file is executed by a user, the program runs under the permissions file owner’s permissions.
-  **Set group ID (SGID):** For a file, the program runs under the permissions of the file’s group. For a directory, new files created in the directory use the directory group as the default group.
-  **The sticky bit:** When applied to a directory, only file owners can delete or rename the files in the directory.

## Easy ways to share a file or a directory

The SGID bit is important for sharing files. By enabling the **SGID bit**, you can force all new files created in a shared directory to be owned by the directory’s group and now the individual user’s group. [Here’s a helpful book on Linux](https://www.amazon.in/Linux-Command-Shell-Scripting-Bible/dp/1119700914?tag=srinimf-21)

The SGID is set using the `**chmod**` command. It’s added to the beginning of the standard three-digit octal value (making a four-digit octal value), or you can use the symbol **`s` **in symbolic mode.

| Binary | Octal | Description |
| --- | --- | --- |
| 000 | 0 | All bits are cleared. |
| 001 | 1 | The sticky bit is set. |
| 010 | 2 | The SGID bit is set. |
| 011 | 3 | The SGID and sticky bits are set. |
| 100 | 4 | The SUID bit is set. |
| 101 | 5 | The SUID and sticky bits are set. |
| 110 | 6 | The SUID and SGID bits are set. |
| 111 | 7 | All bits are set. |

*Linux OCTAL values*

## Steps to make a file or a directory sharable

The first step is [to create](https://srinimf.com/2020/03/24/linux-how-to-create-your-own-command/) a directory that you want to share using the `mkdir` command. Next, use the **`chgrp` command **to change the default group for the directory to a group that contains the members who need to share files. Finally, the SGID bit is set for the directory to ensure that any files created in the directory use the shared group name as the default group.

To work properly, all the group members need to have the **umask** values set, so that group can have writable access. Below, you’ll find the **`umask` is changed to `002`** so that the files are writable by the group.

After all, any member of the group can go to the shared directory and create a new file. As expected, the new file uses the default group of the directory, not [the use](https://srinimf.com/2022/04/15/the-use-of-df-disk-free-command-in-linux/)r account’s default group. Now any user in the shared group can access this file.

```
$ mkdir testdir
 $ ls -l
 drwxrwxr-x    2 rich     rich         4096 Sep 20 23:12 testdir/
 $ chgrp shared testdir
 $ chmod g+s testdir
 $ ls -l
 drwxrwsr-x    2 rich     shared       4096 Sep 20 23:12 testdir/
 $ umask 002
 $ cd testdir
 $ touch testfile
 $ ls -l
 total 0
 -rw-rw-r--    1 rich     shared          0 Sep 20 23:13 testfile
 $
```

Related

- [How to Set File Permissions in Linux [+Example]](https://srinimf.com/2022/04/18/how-to-set-file-permissions-in-linux/)DateApril 18, 2022
- [Linux: The Hierarchy of System Directories](https://srinimf.com/2018/08/30/linux-directories-for-new-programmers-really-useful/)DateAugust 30, 2018
- [Your Absolute Guide to Hard link Vs Soft link in Linux](https://srinimf.com/2022/10/17/what-is-hard-and-symbolic-link-in-linux-and-how-to-use/)DateOctober 17, 2022

References

- What’s umask and [how to](https://srinimf.com/2022/04/18/how-to-set-file-permissions-in-linux/) use it
- What’s chgrp g+s and how to use it

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2022%2F12%2F31%2Feasy-ways-to-share-a-file-in-linux%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2022%2F12%2Fpexels-photo-12317177.jpeg%3Ffit%3D1200%252C960%26ssl%3D1&description=How%20to%20Make%20Directory%20Sharable%20in%20Linux)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2022/12/31/easy-ways-to-share-a-file-in-linux/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Make%20Directory%20Sharable%20in%20Linux&body=https%3A%2F%2Fsrinimf.com%2F2022%2F12%2F31%2Feasy-ways-to-share-a-file-in-linux%2F&share=email)
-

### Like this:

Like Loading…
