sudo passwd <username>
you may want to remove your keyring lock file as it doesn’t always update:
rm ~/.local/share/keyrings/login.keyring
From:
sudo adduser username
This runs an interactive q&a to create a new user, which is fine if you are interacting with bash. If you want to script, you can use useradd
, a lower-level command with more command-line options that permits you to enter a password in the command options, add the user to groups right away, and create the home directory.
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
you can create a new user and group by specifying groupid and uid, too, if you need to be specific.
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}
note the two ways to generate a valid password are to substitute
-p $(perl -e 'print crypt($ARGV[0], "password")' 'password')
with
-p $(openssl passwd my_custom_password)
if you have openssl installed. Also note the different approach to encrypting the password (lower-level) and creating directories.
Create a new group with
sudo addgroup groupname
You can also create a new group by gid
groupadd -g <group-id> <groupname>
Find groups associated with current user:
groups $USER
Add new user to new groups
sudo usermod -aG adm username
sudo usermod -aG sudo username
#...
modify list of groups user belongs to. Unlike the last command(-aG
), -G
redefines rather than appends
sudo usermod -G usergroup,othergroup username
You can change the password with:
passwd [username]
delete root password
sudo passwd -l root
remove user from group
sudo deluser username groupname
remove user completely
sudo deluser --remove-home username
more tips here: https://www.howtogeek.com/656549/how-to-delete-a-user-on-linux-and-remove-every-trace/
groupdel <groupname>
passwd --expire <username_here>
from here: https://askubuntu.com/questions/282806/how-to-enable-or-disable-a-user
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
users:
cut -d: -f1 /etc/passwd
getent passwd
groups:
cut -d: -f1 /etc/group
getent group
users
who
whoami
list login dates / times, users, etc
last