How to add and delete a user in linux ?

To add a user in linux:-

# useradd <user-name>

This command is used to add a user in linux. A root user is the superuser in the linux. So a root user only have the right to add another user. Another user can only add a user if the root user give access to do it so.


To give password to the added user is given by following command:-

# passwd <username>

After this it asks for the new password. Once the password is set to that user then only the users who know that password can access that user. The root user can access all the local users on that system without knowing their password



To delete a user in linux:-

# userdel <user-name>

This command will delete the user from the system but the user home directory and mail spool is not delete with this command.


If we want to delete the entire home directory as well as its mail spool then we have to write the following command :-

# userdel -r <user-name>

Please note that files located in other file systems will have to be searched for and deleted manually.