hamwaves.com
;

Managing Users & Groups 
under GNU/Linux

Serge Y. Stroobandt

Copyright 2014–2019, licensed under Creative Commons BY-NC-SA

  1. Home
  2. IT
  3. Command Line
  4. Users & Groups

List all users

$ cat /etc/passwd

List all groups

$ cat /etc/group

Always use adduser or addgroup

The useradd, userdel and usermod commands are lowlevel utilities which are there for historical reasons, while adduser/deluser Do The Right Thing™.

adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd, groupadd and usermod programs, by default choosing Debian policy conformant UID and GID values, creating a home directory with skeletal configuration, running a custom script, and other features. adduser and addgroup can be run in one of five modes:

Manpage for useradd says:

useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead.

$ sudo adduser username
$ sudo adduser username --uid 1005
$ sudo addgroup groupname --gid 2000

Mnemonics

Naughty mnemonics are the ones that are best remembered, so here it goes:

The word “user” rhymes with “loser”, and “loser” comes last.
Thus, it is: adduser & deluser.

Create an SSH key pair

mkdir $HOME/.ssh
chmod 600 $HOME/.ssh
ssh-keygen -t rsa -b 4096 -f $HOME/.ssh/id_rsa
ssh-add $HOME/.ssh/id_rsa

Change a user’s finger information

$ man chfn

Delete an existing user

$ sudo deluser --remove-home username

List a user’s group membership

The id command offers much more information than the group names listed by groups. UID, primary GID and other group IDs are listed as well.

$ id username
$ groups username

Add an existing user to an existing group

$ sudo adduser username groupname

Log out and in again for this group affiliation to take effect.

Delete an existing user from an existing group

$ sudo deluser username groupname
5
Creative Commons Licence
This work is licensed under a Creative Commons Attribution‑NonCommercial‑ShareAlike 4.0 International License.
Other licensing available on request.
GNU GPL v3
Unless otherwise stated, all originally authored software on this site is licensed under the terms of GNU GPL version 3.
cookie
This static web site has no backend database.
Hence, no personal data is collected and GDPR compliance is met.
Moreover, this domain does not set any first party cookies.

All Google ads shown on this web site are, irrespective of your location,
restricted in data processing to meet compliance with the CCPA and GDPR.
However, Google AdSense may set third party cookies for traffic analysis and
use JavaScript to obtain a unique set of browser data.
Your browser can be configured to block third party cookies.
Furthermore, installing an ad blocker like EFF's Privacy Badger
will block the JavaScript of ads.
Google's ad policies can be found here.
This page employs a Python Bottle server‑side script.
This page includes an open-source client-side script, written in Python and
transcoded by Brython to make it run as secure JavaScript in the browser.
Static XHTML generated from Markdown by Pandoc and
the GNU/Linux make, sed and gpp commands.
LaTeXmath markup rendered with MathJax.
BibTeX references are best read with JabRef.
Unattended CSS typesetting with Prince.
This work is published at https://hamwaves.com/groups/en/.
profile for Serge Stroobandt on Stack Exchange, a network of free, community-driven Q&A sites
GnuPG
Use my OpenPGP public key to encrypt messages for:

echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d
Last update: Wednesday, September 1, 2021.