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:
- 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.
- 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
sudocommand to switch to the root user. For example:
- Create a New User: Use the
useraddcommand to create a new user. Replace
newuserwith the username you want to create:
By default, this will create a user with a home directory in the
- Set a Password: You should set a password for the new user using the
You will be prompted to enter and confirm the new password for the user.
- Optional: Add User to Groups: You can add the new user to additional groups if needed. For example, to add the user to the
sudogroup for administrative privileges:
usermod -aG sudo newuser
sudo with the name of the group you want to add the user to.
- Optional: Create the User’s Home Directory: If you want to create the user’s home directory and copy files from the
/etc/skeldirectory, you can use the
useradd -m newuser
- Verify User Creation: You can verify that the user was created by listing the users on the system using the
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.
- Exit Root or Superuser Mode (if used): If you used
sudo suor a similar command to gain superuser privileges, you can exit this mode by typing
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.