User Management

Password

sudo passwd <username>

you may want to remove your keyring lock file as it doesn’t always update:

rm ~/.local/share/keyrings/login.keyring 

Users, groups

From:

  1. Create a new group

    sudo addgroup groupname
    
  2. Create a new user

    sudo adduser username
    
  3. create a new group by gid

    groupadd -g <group-id> <groupname>
    
  4. create a new user and group by groupid

    MYUSER=ubuntu
    MYGID=1000
    MYUID=1000
    
    groupadd -g ${MYGID} ${MYUSER}
    useradd -u ${MYUID} -g ${MYGID} -p $(perl -e 'print crypt($ARGV[0], "password")' 'password') -G adm,sudo ${MYUSER} && mkdir /home/${MYUSER} && chown ${MYUSER}:${MYUSER} /home/${MYUSER}
    

    another variant:

    useradd -m my_new_username -p $(openssl passwd my_custom_password) && usermod -s /bin/bash my_new_username &&  usermod -aG sudo,other_groups,another_group my_new_username
    
  5. Find groups associated with current user:

    groups $USER
    
  6. Add new user to new groups

    sudo usermod -aG adm username
    sudo usermod -aG sudo username
    #...
    
  7. modify list of groups user belongs to

    unlike the last command(-aG), -G redefines rather than appends

    sudo usermod -G usergroup,othergroup username
    

Change password

passwd [username]

Remove User

  1. remove user from group

    sudo deluser username groupname
    
  2. remove user completely

    sudo deluser --remove-home username
    

    more tips here

delete group

groupdel <groupname>

Force new password

passwd --expire <username_here>

Expire / unexpire

from here

Expire Account

Let the account expire to disallowing a user from logging in from any source including ssh:

# disallow peter from logging in
sudo usermod --expiredate 1 peter

This is how you can reenable that account:

# set expiration date of peter to Never
sudo usermod --expiredate "" peter

List all users / groups

users:

cut -d: -f1 /etc/passwd
getent passwd

groups:

cut -d: -f1 /etc/group
getent group

find out who is logged on

users
who
whoami

List login times including boots

list login dates / times, users, etc

last