FreeBSD : How to setup shared directories

Recently one of the new admin come across classic problem of “Sharing Directories Among Several User”. I explained him the commands and decided to write this. Although concept is almost same as Linux/UNIX; still people comes across problem. Here is scenario:

  • /home/project1 : Shared directory
  • usr1, usr2, … usrN : Would like to work and share files in /home/project1 directory
  • padmin : Main project administrator

(A) Create a shared directory /home/project1

# mkdir /home/project1

(B) Create the group project1

# pw group add project1

(C) Add user padmin and setup password:

# pw user add -n padmin -d /home/project1 -g project1 -m
# passwd padmin

(D) Add rest of users to group project1

# pw user add -n usr1 -d /home/project1 -g project1
# pw user add -n usr2 -d /home/project1 -g project1

….

# passwd usr1
# passwd usr2

(E) Setup permission on /home/project1 directory as follows:

a) Setup group ownership to project1 group:

# chown -R padmin.project1 /home/project1

b) Setup permission on directory i.e. setup full permission for group and owner on a directory:

# chmod -R 775 /home/project1

c) Setup sgid bit. So what is sgid bit? Normally when ever you creates file in a directory it belong to
default group of user. When a file is created in a directory with the sgid bit set it belogns to the same group as the directory. The result is all users of project1 group can create/alter files in /home/project1 directory:

# chmod -R 2775 /home/project1

OR

# chmod -R g+s /home/project1

Now each user can login over ssh and use the directory for project. Note if you wish to add an existing users to project1 group for sharing files then use pw command as follows:

# pw user mod -n username -G project1

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum