3.6. Exercises and Summary

3.6.1. Questions

  1. Which file contains information about password policies such as expiry date, modification date, etc?

  2. Which tool will change password policies?

  3. The content of which directory is copied across to the home directory of a newly created user?

  4. In which file are default values such as the MAX_UID or PASS_MAX_AGE set?

  5. Which tool will create a shadow file if it doesn't exist yet?

3.6.2. Files

FileDescription
/etc/groupcontains the names of all the groups on the system
/etc/gshadowcontains (optionally) passwords associated to a group
/etc/login.defscontains predefined values needed when adding a new user such as the minimum and maximum UID and GID, the minimum password length, etc
/etc/passwdpasswd(5). a text file that contains a list of the systems accounts, giving for each account some useful information like user ID, group ID, home directory, shell, etc. Often, it also contains the encrypted passwords for each account. It should have general read permission (many utilities, like ls(1) use it to map user IDs to user names), but write access only for the superuser
/etc/shadowshadow(5) contains the encrypted password information for user's accounts and optional the password aging information
/etc/skel/directory containing files and directories to be copied into the home directory of every newly created user

3.6.3. Commands

CommandsDescription
chagechanges a user's password expiry information
gpasswdadminister the /etc/group file
groupaddadd a new group to the system
groupmodmodify an exiting group
groups print out all the groups a user belongs to
id print out the UID as well as the GIDs of all the groups a user belongs to
passwdchange the password for an account
useraddadd a new user to the system
usermodmodify an existing user account

3.6.4. Exercises

  1. Creating users

    Create a group called devel with GID 550

    groupadd -g 550 devel
    

    Use adduser to create a user called tux with user ID 600 and additional group ID 550

    useradd -u 600 -G 550 -m tux
    
    [Note]Note

    the -G flag adds tux to the group with GID 550 as an additional group (other than users or tux)

    Use usermod to change this user's home directory.

    usermod -d /home/newtux/ -m  tux
    

    Does the new directory need to be created? (Hint: check the effect of the -m flag)

    Is the content of /etc/skel copied to the new directory?

    Use usermod to change tux to the group wheel.

    usermod -G devel,wheel tux
    
    [Note]Note

    If a comma separated list of groups is not given, the user will be assigned to a single extra group. The gpasswd tool will add users to additional groups (see Working with groups below)

  2. Working with groups

    Create a group called sales using groupadd.

    groupadd sales
    

    Add tux to this group using gpasswd.

    gpasswd -a tux sales
    

    Login as tux. Use groups to list the groups you belong to. Join the group sales using newgrp and list the groups you belong to (once again).

  3. Conifiguration files

    Add a user to the system by editing /etc/passwd, /etc/group and /etc/shadow. Create a group called share and add the user tux to this group by manually editing /etc/group

  4. Modifying an Account

    Change the expiry date for user tux's account using usermod.

    Lock the user's account. (Use tools or edit /etc/shadow)

    Prevent the user from logging in by changing the user's default shell to /bin/false

    Change the PASS_MAX_DAYS for user tux to 1 in /etc/shadow

  5. Changing default settings

    Use useradd -D to change the system's default settings such that every new user will be assigned /bin/sh instead of /bin/bash. (Notice that this will change the file in /etc/defaults/)

    Edit /etc/login.defs and change the default PASS_MAX_DAYS so that new users need to change their password every 5 days