Tutorial 08 · FreeBSD

Users, groups and permissions

Manage accounts with adduser and pw, and control access with ownership, modes and umask.

Last updated

FreeBSD keeps accounts in /etc/master.passwd (with the public view in /etc/passwd) and groups in /etc/group. Don't edit these by hand; use the tools below.

1Adding users

adduser                                    # interactive
pw useradd -n bob -m -s /bin/sh -c "Bob"   # scripted, -m creates the home directory
passwd bob

2Changing and removing users

pw usermod bob -s /usr/local/bin/bash
pw lock bob        # disable login
pw unlock bob
rmuser bob         # interactive removal
pw userdel bob -r  # remove including home directory

3Groups

pw groupadd staff
pw groupmod staff -m alice,bob   # add members
pw groupshow staff
id alice
pw groupdel staff

Members of wheel can use su to become root. Group changes take effect at the user's next login.

4Ownership and modes

Each file has an owner, a group and permission bits for user, group and others: read (4), write (2) and execute (1).

ls -l report.txt
chown alice:staff report.txt
chmod 640 report.txt        # rw for owner, r for group, none for others
chmod g+w,o-rwx report.txt  # symbolic form
chmod -R u+rwX,go-rwx ~/private   # X: execute only on directories

5Shared directories

On FreeBSD, new files inherit the group of their directory by default, so a shared folder only needs the right group and mode.

mkdir /home/shared
chown root:staff /home/shared
chmod 2770 /home/shared

6umask

The umask removes permission bits from newly created files. 022 gives 644 files and 755 directories; 027 keeps files private from others. Set it in your shell profile, or system-wide in /etc/login.conf (then run cap_mkdb /etc/login.conf).

umask          # show current
umask 027
echo 'umask 027' >> ~/.profile

← All FreeBSD tutorials