Creating a new User:
There are two commands that can add a user.
useradd:
useradd
is a low level utility. This command is written assudo useradd [options] [user-name]
.-
adduser:
adduser
is a high level utility. This command is written assudo adduser [options] [user-name]
.
Deleting a User:
There are two commands to delete a user.
userdel:
userdel
is a low level utility. This command is written assudo deluser [options] [user-name]
.By using this command the directory of the user will not be deleted.
-
Delete the user and also its directory:
To delete the user and its directory in one command
sudo userdel --remove [user-name]
is used. -
deluser:
deluser
is a high level utility. This command is written assudo deluser [options] [user-name]
.
Set a password for a user:
To set a password for a user sudo passwd [user-name]
is used.
Create a Service Account:
To create a service account sudo useradd --system [service-name]
is used.
Change the username of a user:
To change the username of a user account sudo usermod --login [new-name] [old-name]
is used.
Change the shell for a user:
To change the shell for a user sudo usermod --shell /bin/bash [user-name]
is used. When you make a user account sh
shell is set by default for the user.
Switch User:
To switch the user sudo su [user-name-to-be-switched]
is used. By entering exit
command you can exit from the new user and move back to the main user.
Lock/Disable User:
usermod:
To lock or disable a user account using usermod
sudo usermod -L [user-name]
is used.-
passwd:
To lock or disable a user account using passwd
sudo passwd -l [user-name]
is used.
Unlock/Enable User:
usermod:
To unlock or enable a user account using usermod
sudo usermod -U [user-name]
is used.-
passwd:
To unlock or enable a user account using passwd
sudo passwd -u [user-name]
is used.