Table of Contents

This article is Part 4 in a series of cheat-sheets on the command line shell, bash. (Previous Page | Next Page)

bash: Users and Permissions

User Management

See list of users:

$ cat /etc/passwd

Opens a new shell as user username:

$ su username

Opens a new shell as user username, using their environment:

$ su - username

useradd

Create new user username:

$ useradd username

Some options include:

More examples:

userdel

$ userdel username

Deletes user account.

passwd

$ passwd username

Changes user's password. Some options include:

usermod

$ usermod -flags username

Used for modifying accounts. Some options below:

Example, to change a user's shell:

$ usermod -s /sbin/nologin username

Group Management

See list of groups:

$ cat /etc/group

Create new group newgroupname:

$ groupadd newgroupname

Change name of group oldgroupname to newgroupname:

$ groupmod -n newgroupname oldgroupname

Remove user username from group oldgroupname:

$ gpasswd -d username oldgroupname

Change user's primary group:

$ usermod -g newgroupname username

Add user to a supplementary group:

$ usermod -aG newgroupname username

File Permissions

umask

Set default permissions to 600 on new files and 700 on new directories:

$ umask 0077

chmod

$ chmod 600 filename

Changes permissions of filename to 600. Further uses of chmod:

chown

Change owner of filename:

$ chown user filename

Change owner and group of filename:

$ chown user:group filename

chgrp

Change group of filename:

$ chgrp group filename

File Permissions Notes

Octal Values

Sticky Bits



This article is part of a series on Command Line
Linux, MacOS & BSD
Shells: Bash (Getting Started - Shortcuts & Piping - Managing Processes - Users & Permissions - Files & Archives - Customization) - zsh
Emulators/Multiplexers: tmux
Windows
PowerShell