How Can We Help?
< All Topics
Print

How to Create a New User in CentOS

To create a new user in CentOS, you can use the useradd command. Here are the steps to create a new user:

  1. Open a Terminal: Log in to your CentOS system and open a terminal. You can use a physical console or an SSH connection if you are working on a remote server.
  2. Switch to the Root User (Optional): Depending on your system’s configuration, you may need superuser privileges to create a new user. You can use the su or sudo command to switch to the root user. For example:
   sudo su
  1. Create a New User: Use the useradd command to create a new user. Replace newuser with the username you want to create:
   useradd newuser

By default, this will create a user with a home directory in the /home/newuser directory.

  1. Set a Password: You should set a password for the new user using the passwd command:
   passwd newuser

You will be prompted to enter and confirm the new password for the user.

  1. Optional: Add User to Groups: You can add the new user to additional groups if needed. For example, to add the user to the sudo group for administrative privileges:
   usermod -aG sudo newuser

Replace sudo with the name of the group you want to add the user to.

  1. Optional: Create the User’s Home Directory: If you want to create the user’s home directory and copy files from the /etc/skel directory, you can use the -m option with useradd:
   useradd -m newuser
  1. Verify User Creation: You can verify that the user was created by listing the users on the system using the getent or cat command:
   getent passwd newuser
   # or
   cat /etc/passwd | grep newuser

This will display user information, including the username, UID (user ID), GID (group ID), home directory, and shell.

  1. Exit Root or Superuser Mode (if used): If you used sudo su or a similar command to gain superuser privileges, you can exit this mode by typing exit.

That’s it! You have successfully created a new user in CentOS. The user can now log in using their username and password. Make sure to grant the appropriate permissions and configure any additional settings for the new user as needed.

Please suggest edits or add your comments.

Your email address will not be published. Required fields are marked *

Scroll to Top