How to Create a New User in Linux

In Linux, a user account is a unique username, the user’s profile, and the associated password that allows a person to access the system and perform certain actions based on their level of permissions. Each user account has its own home directory where the user can store their files and settings.

To create a new user account in Linux or Unix systems, you can use either the adduser or useradd command line tools as explained below.

Using adduser Command Line Tool

Start by opening a terminal window on your Linux desktop. If you wish to create a user on a server, connect to the server via ssh. Then type the following command and press Enter to start the process. Use the sudo command to invoke root privileges where necessary and enter your password when prompted.

#adduser fossman
OR
$sudo adduser fossman

Remember to replace “username” with the desired username for the new user. You will be requested to define the password for the new user. Set the new password, retype the new password and press Enter to proceed.

You will then be asked to enter some additional information about the user, such as their full name, room number, work and home phone number, and other information. Note that this step is optional, but recommended for better user management. The new user account will be created once you have completed the steps.

By default, the adduser command will configure the new user’s account based on configurations in the /etc/adduser.conf file. This file contains variables that define the new user’s shell and directory where the user’s home directory will be created.

It also contains a SKEL variable that specifies the directory containing “skeletal” user files. The default SKEL directory on Ubuntu is /etc/skel/. These files are used to initiate the home directory when a user is first created.

To specify a different home directory for a user, use the --home option. Replace /opt/home/fossman with the directory on your system:

$sudo mkdir -p /opt/home/fossman
$sudo adduser  --home  /opt/home/fossman fossman

To specify a different shell for the new user, use the --shell option:

$sudo adduser --shell /bin/sh fossman
Using useradd Command Line Tool

To create a new user using the useradd command line tool, type the following command and press Enter to start the process. By default, the useradd command does not create a home directory or set a password for the new user.

Add the -m or --create-home option to create the user’s home directory if it does not exist. Also, add the -s or --shell option to specify the user’s default shell. Also, replace “username” with the desired username for the new user.

# useradd  -m -s /bin/bash fossman
OR
$sudo useradd -m -s /bin/bash fossman

Then create a new password for the new user using the passwd command. You will be prompted to set a password for the new user. Follow the prompts to set a strong password and press Enter to proceed.

$sudo passwd fossman

Once you have successfully created a new user account, the user can now log into the system. For more information about adduser or useradd commands, view their man pages:

$man adduser
OR
$man useradd
Conclusion

In this post, I showed how to use the adduser and useradd command line tools to create a new user account in a Linux operating system. You can use the feedback form below to ask any questions about this guide.

You may also like...

Leave a Reply

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

Page Contents