Linux Basics: How to Add and Delete Shell Users on CentOS

Tutorial Topic:

  • 1.1 Overview
  • 1.2 Addition and Deletion of Shell Users on CentOS - An Introduction
  • 1.3 How To Add a Shell User on CentOS
  • 1.4 How To Delete a Shell User on CentOS


CentOS Linux is a popular community-supported distribution primarily derived from sources that are freely available to the public by Red Hat (for Red Hat Enterprise Linux-RHEL). Given the lineage, CentOS Linux essentially aims to be functionally compatible with RHEL. A revised CentOS version is generally released roughly every 2 years, in addition to each CentOS version being periodically updated nearly every 6 months to support updated hardware. This invariably offers users a highly secure, low-maintenance, dependable and fairly familiar and reproducible Linux environment.

1.2 Addition and Deletion of Shell Users on CentOS - An Introduction

The process of adding and deleting shell users on a new server is a basic task every Linux user or system administrator ought to know. In fact, when a user creates a fresh server, they begin with a default root account, thus enjoying absolute authority and flexibility, though the uninhibited access is somewhat susceptible to misuse. Therefore, in order to check probable manipulation, it is always prudent to add a supplementary unprivileged user for completion of common tasks. Also, system administrators must warrant the creation of supplementary accounts for system users so as to plot a unique account to each user.

This tutorial offers a comprehensive guide on the process of creating and deleting shell user accounts on CentOS:

1.3 How To Add a Shell User on CentOS

To add a new shell user on CentOS, one needs to use the following command, and replacing the word "newuser" with the preferred username.

adduser newuser

The adduser command creates a new home directory for the user under /home. In our example, the directory name will be /home/newuser. This command without additional options will be sufficient for most cases.

Advanced Options

If you like to set a different home directory, use the --home option. e.g.:

adduser --home /home/otherdirectory newuser

The new shell user will use the centos default shell. To specify a different shell like /bin/sh, use the option --shell followd by the path to the shell binary. combined with our different home path from above, the command will look like this:

adduser --shell /bin/sh --home /home/otherdirectory newuser

A list of all options is available in the manpage of the command. The manpage can be shown with this command:

man adduser

To quit the manpage, press "q".

The adduser command is the first step in the process of adding a new user on CentOS. This needs to be followed up by assigning a new password to the user, and typing and confirming the new password upon receiving the system prompt. Administrators need to use the following command for that:

passwd newuser

You just added a new user, and mapped a password to their account! Successively, you need to log out of the root user by keying in "exit", and then log back in with the new username and password. You may take the process forward from this point if you wish to assign access to administrative functionality to the new user.

1.4 How to Delete a Shell User on CentOS

Deleting shell user accounts is required when the specific user(s) are no longer required on the virtual private server. This can be achieved by using the following command:

userdel newuser

Administrators must note here that they have the option to add the flag "-r" to the aforementioned command (as given below) if they wish to also remove the user`s files and home directory in the process.

userdel -r newuser

The above command shall certainly ensure a goofproof deletion of the user account, plus all the sudo privileges linked to the said account.

A list of all options is available in the manpage of the command. The manpage can be shown with this command:

man userdel

To quit the manpage, press "q".

Share this page:

0 Comment(s)

Add comment


From: howtoforge