> For the complete documentation index, see [llms.txt](https://olb.gitbook.io/linux-essentials-certification/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olb.gitbook.io/linux-essentials-certification/5.security-and-file-permissions/5.2-creating-users-and-groups.md).

# 5.2 Creating users and groups

**Weight 2**\
Key knowledge areas

* User and group commands
* User IDs

Partial list of the used files, terms and utilities

* /etc/passwd, /etc/shadow, /etc/group, /etc/skel/
* useradd, groupadd
* passwd

***

## Adding and Deleting User Accounts

* `sudo useradd $USER` : add user
* `sudo userdel $USER` : delete user add -r to delete home directory
* `sudo passwd $USER` : create password
* `userdbctl` : user database
* `-c` Create a new user account with custom comments (for example full name).
* `-d` Create a new user account with a custom home directory.
* `-e` Create\` a new user account by setting a specific date on which it will be disabled.
* `-f` Create a new user account by setting the number of days after the password expires during which the user should update the password.
* `-g` Create a new user account with a specific GID
* `-G` Create a new user account by adding it to multiple secondary groups.
* `-m` Create a new user account with its home directory.
* `-M` Create a new user account without its home directory.
* `-s` Create a new user account with a specific login shell.
* `-u` Create a new user account with a specific UID.

-`id $USER` : show UID,GID -`groups $USER` : show Groups

## The Skeleton Directory

* `/etc/skel` : When you add a new user account, the newly created home directory is populated with files and folders that are copied from the skeleton directory

## Adding and Deleting Groups

* `groupadd -g 1090 developer` The -g option of this command creates a group with a specific GID.
* `groupdel developer`

## The passwd Command

* `passwd -options $USER`
* `-d` Delete the password of a user account (thus setting an empty password, making it a passwordless account).
* `-e` Force the user account to change the password.
* `-l` Lock the user account (the encrypted password is prefixed with an exclamation mark).
* `-u` Unlock the user account (it removes the exclamation mark).
* `-S` Output information about the password status for a specific account.

`useradd -u 1035 -g 1020 -G web_admin,db_admin carol`\
`id carol`\
`uid=1035(carol) gid=1020(sys_admin) groups=1020(sys_admin),1021(web_admin),1022(db_admin)`
