Creating a shared folder in your home directory - acarril/unix-servers GitHub Wiki

While we usually want that the files and directories in our home directory remain private, sometimes it is useful to have a folder that other people can access. Here we'll go through the basics of creating a shared folder in our home directory that other users can read (and possibly write to), while maintaining the privacy of our home directory.

Here we'll go through a short, step-by-step guide on how to achieve our immediate goal. However, I strongly recommend you also read this small primer on Unix file and directory permissions to better understand what we are doing.

tl;dr

Group and Others permissions should be set to execute for all parent directories in order to grant read and/or write access to shared subdirectory. Then the shared directory itself should be recursively set to the proper permissions (i.e. read and/or write), as well as execute.

Step by step

  1. First we need to check our own home directory's permissions. We can list all users' home directories, along with other useful information, with
$ ls -l ~/..
total 356
drwx------.  4   102611         20125   178 Jul 21  2014 aagan
drwx--x--x. 28 acarril  acarril        4096 Jul  7 15:50 acarril
drwx---rwx. 13 agaldin  agaldin       36864 Feb 28 16:35 agaldin
drwx-----. 16 alangan  alangan        8192 Jul  1  2019 alangan
drwx---r-x. 44 amas     amas           4096 Apr  8  2016 amas
...

The first column summarizes permissions for a given folder (or file). What we care about here are the permissions that Others (i.e. anyone) on our home directory, which are given by the last three digits of the string in the first column. For example, agaldin's home directory has allowed read, write, and execute permissions for Others, while acarril (my username) has only execute permissions for Others.

We need to set our home directory so that Group and Others only have execute permissions, as is the case with my home directory (acarril). This can be done in a number of ways; for example,

chmod go=x ~

Here chmod is the program to change permissions, and go=x indicates that both group and others permissions are set to execute. You can double-check that this worked by using ls -l ~/.. again.

  1. Now we need to create a Public subdirectory in our home directory with
mkdir ~/Public

Remember that ~ is a shorthand for our home directory (it usually stands for /home/<user> in Linux and for /Users/<user> in macOS). Of course, we could've named this directory with any other name.

  1. Finally, we need to set the right permissions for this newly created Public subdirectory.
chmod -R go=rx ~/Public

Now we use the chmod command with go=r to grant read (and execute) permissions to Group and Others. The -R flag makes this recursive, so that it affects all subdirectories. This is not strictly necessary in this case, since we know ~/Public is empty. However, it might be useful in case we want to modify the permissions of an existing and already populated directory.

Acknowledgements

Thanks to Karl Schulze for helping me test these commands in the Princeton servers.

⚠️ **GitHub.com Fallback** ⚠️