How Can We Help?
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
su
orsudo
command to switch to the root user. For example:
sudo su
- Create a New User: Use the
useradd
command to create a new user. Replacenewuser
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.
- 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.
- 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.
- 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 withuseradd
:
useradd -m newuser
- Verify User Creation: You can verify that the user was created by listing the users on the system using the
getent
orcat
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.
- 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 typingexit
.
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.