Add/Remove Linux users

To add a Linux user to your server you will use the adduser command:

# adduser <new_username>
# passwd <username_password>

Here we will add user ‘ph1’ to the server:

root@web [/]# adduser ph1
root@web [/]# passwd ph1
Changing password for user ph1.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
root@web [/]#
centos login user 1
CentOS Login Screen

Notice that the home directory of the user will usually be /home/username/. To specify a home directory when creating the user, use:

# adduser -d <desire_user_directory>

The users’ home directories are stored in /etc/passwd file. To view the home directory for a user:

root@web [/]# cat /etc/passwd | grep ph1
ph1:x:32012:32015::/home/ph1:/bin/bash
root@web [/]#


To remove a Linux user from your server:

# userdel <username>
root@web [/]# userdel ph1
root@web [/]#

To delete the user’s account, the user’s directory and the user’s mail spool, use:

# userdel -r <username>
root@web [/]# userdel -r ph1
root@web [/]#

Notice that the commands adduse and userdel will not display any confirmations on success.

Resources:
adduser man page
userdel man page

Leave a Reply