Creating a user in Linux Terminal
The useradd command will create the user and usermod can modify user properties such as groups the user is part of.
useradd [options] username
Example:
sudo useradd dragos
Using default options to create username dragos.
Also created the user home directory: /home/dragos
A group is also created for the user with the same name. This can be changed if needed by specifying the -g option.
sudo useradd -g dragosgroupname dragos
After the user is created use the passwd command to create a password for that user.
The passwd command adds entries in the file:
/etc/passwd
sudo passwd dragos
type password twice when prompted and it’s done. User is ready to logon.
If the user should be able to run suo commands – run commands with elevated privileges – ROOT.
You should be careful with this. Only give this to yourself or only users you trust.
They can rm / -rf (Don’t try this – delete everythong) your server so there’s that.
To allow a user to sudo it needs to be added to the wheel group. Add an entry in the file: /etc/group
sudo usermod -aG wheel temptest
Now this user is able to run sudo commands.
The user can be added to any custom group you might have.
sudo usermod -aG devs,users,bloggers temptest
The user can change the password by logging in and typring in Terminal or SSH session.
passwd dragos
They can only change their own password.
the useradd -D or defaults shows you the default values used when creating a new user in Linux.
useradd -D
You can customize each one by looking at the options allowed,
useradd -h
Leave a Reply