A quick topic describing how to create and manage linux users and groups from the command line. This topic only describes what linux users and groups are and how to manage them. It does not explain security and permissions for those users. Please see Linux Permissions for help on that topic.

Remember to use --help (example usermod --help to see a help list for that command

Brief Explination[-][--][++]

Linux is a multi-user operating system. The linux user system uses users and groups to define a users role on the system. A user will always have one primary group, but can also have multiple secondary groups. The user and the group are used to assign roles or permissions throughout the system. For example, a system administrator could set permissions on every file in /etc so that any user in the 'public' group can read the files, but any user in the 'admin' group can edit the files. Or when you install alsa, the linux sound architecture, users must be in the 'audio' group to be able to play sound. Since the sound card is represented as a file, those sound files have read permission to the 'audio' group only.

User Management[-][--][++]

Commands used to manage users and groups in linux are

  • useradd to create new users
  • usermod to edit existing users
  • userdel to delete existing users
  • groupadd to create new groups
  • groupmod to edit existing groups
  • groupdel to delete existing groups
  • id to list current users groups and user/group IDs
  • groups to list the current users (or specified users) groups
  • who or users shows you who is logged in to the system
  • All user and group information is stored in the /etc/passwd, /etc/shadow, /etc/group files
Since adding and editing users is an administrator thing, you must be root (or use sudo) to execute the add/mod/del commands above
Other commands I will not cover are newgrp, gpasswd

Managing Groups[-][--][++]

Most groups on your system were created when you installed the OS. These groups are used by other applications for manage internal permissions. Like the 'audio' example for ALSA above. the /etc/group file contains all groups on your linux system.

  1. List all groups on your system with cat /etc/group

#

  1. Add group
# groupadd developers

Add new or existing user to a group, if group dne, then this will create it too
-g is primary group
-G is secondary group
-m is create home dir
-N is don't create a group with the same name
-s is the shell

useradd -g wheel -G users -m -N -s /bin/bash newusername

Add new user (able to login to computer) called 'mreschke' and add to developers group

# useradd -G developers mreschke

or add user 'mreschke' and set to multiple groups
# useradd -G admins,ftp,www,developers mreschke

This ones better[-][--][++]

groupadd lfs
useradd -s /bin/bash -g lfs -m lfs

The meaning of the command line options:
-s /bin/bash
    This makes bash the default shell for user lfs.
-g lfs
    This option adds user lfs to group lfs.
-m
    This creates a home directory for lfs.
lfs
    This is the actual name for the created group and user.

Change user

Change existing user 'mreschke' primary group to www

usermod -g www mreschke

Add existing user 'mreschke' to secondary group ftp

usermod -a -G ftp mreschke

# or easier still  just run
adduser mreschke ftp

Rename a User[-][--][++]

This will rename a user, and move his home folder. Note, because there could be some files that directly call \
/home/olduser, I decided to do a symbolic link, 'ln -l newuser olduser'

# usermod -l newuser olduser
# groupmod -n newgroup oldgroup
# mv -f /home/olduser /home/newuser
# Now edit /etc/passwd and change the olduser home directory to /home/newuser

Manager nwq[-][--][++]

To deny all chmod o-rwx file
To allow

Resources[-][--][++]