How To Add New User Account To Linux

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/add-new-user-account-linux/
PINTEREST
PINTEREST
INSTAGRAM

Linux all operations are done with users. In Linux environment to create a file,  start a service, open a network port we need a user with required privileges. Linux users are stored in plain test database at /etc/passwd . As old times user passwords also stored in this file but on modern time for security reasons user passwords are hold in /etc/shadow . There is also user groups to manage permission better. User groups are stored in plain text database /etc/group . In this tutorial we will look how to add new user to the Linux.

Getting Help About Useradd Command

Useradd command is very useful command for system administrators. Knowing its parameters and options are very crucial for daily operations. To get quick help about useradd command issue following command.

useradd command help
useradd command help

List Current Users in A Linux System

Before adding a linux user we will list existing users to provide non colliding username.

List current Users
List current Users

Create New User

We will create new user with name test. This user will be added to the /etc/passwd file with the default shell and other related parameters.

We can list newly created user with the following command.

Create A User With Different Home Directory

By default useradd command will create a home directory in /home path with the same name as username.  For example if the username is test the home directory of the user will be /home/test 

This command will create test user with a home directory like /home/mytest 

LEARN MORE  Best Linux Laptops

Create A User With Specific User ID

Linux operating system gives users User ID in order to separate them. User ID’s starts from 500 and increments upon new user addition. But we can change this default behaviour by setting specific UID without getting default one. -u will be provided to the useradd command to specify new users UID.

Create A User With Specific User ID
Create A User With Specific User ID

After user creation we check new users UID with grep command by providing user name. As we can see user nick is created with UID 567

Create A User With Specific Group ID

While creating user in Linux operating system new group is created too. This group is dedicated to the new user and the new user is automatically assigned to this user group. The new user group ID is assigned by default and starts from 1000. This value can be changed with -g option.

Create A User With Specific Group ID
Create A User With Specific Group ID

As we can see newly created user group assigned to the 0 which is root group.

Add A User To Multiple Groups

In previous example we have added new user with the specified group ID. We have just provided only single group ID. We may also need to add user to the multiple groups by providing multiple group ID’s in a single command. This can be done with -G options like below.

Add A User To Multiple Groups
Add A User To Multiple Groups

While creating new user nick we added nick to the groups named root,vboxusers,kvm with this example.

Add A User Without Home Directory

Linux users are great way to login and use Linux systems. Being a Linux system user means having a home directory. But this is not always true. Should it be? Should all Linux users have a home directory? No. For example services users those used for Linux daemons and services do not needs home directories. Also there may be some situations we do not need home directories. Another example is using Linux users just for authentication and providing VPN service. With -M options new user will be created without a home directory.

LEARN MORE  chage Command Tutorial With Examples To Manage User Accounts In Linux

Create A User With Account Expire Date

In a busy system creating a lot of user without any restrction and future notificatin will create security problems. Some added users will be permanent for the Linux system but some others will be temrorary and should be removed or at least locked after some time. While adding new users we can set account expire date for the new user. Just issue -e option to the useradd command like below. In this example we set 28 February 2017 as account expire time for user nick. The date format is YYYY-MM-DD .

After adding user with a account expire date we can check this date with chage command like below.

Create A User With Password Expire Date

Another way to secure newly created user is specifying password expire  date. Specifying password expire date will force the user to change his/her password at the specified date. This will make the user credentials more secure by changing the passwords regularly. To set password expire date use -f option with number of days . If we provide value -1 the password will never expire. We need to provide also a start day for this operation

Create A User With Password Expire Date
Create A User With Password Expire Date

Add User With Custom Comments

While adding user we may need to add some extra informal informaion. This informal information can be the full name, phone number etc. The comment can be added with -c option like below. We will add the phone number of the new user named nick in this example.

LEARN MORE  How To Get Docker Container Ip and Mac Address

Add User With Custom Comments
Add User With Custom Comments

Change User Login Shell

Linux users use shell to issue commands from command line interface. There are alternative command line interfaces. Default and most popular command line interface or shell is bash . The newly create user will have bash as default shell. The default shell can be changed while creating user with -s option like below. In this example we will set sh as default shell.

Change User Login Shell
Change User Login Shell

Disable Login Shell

In previous example we have set shell preferences for the newly created user. There is also an option where user will have no shell. This will prevent user to login to the Linux system. This can be used also a security step for the system. We will set the created users default shell /bin/nologin which is not a shell.

Disable Login Shell
Disable Login Shell
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/add-new-user-account-linux/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.