Javascript required
Skip to content Skip to sidebar Skip to footer

Login in as a New User in Linux Updated FREE

Login in as a New User in Linux

Nosotros all are enlightened of the most popular command called 'useradd' or 'adduser' in Linux. There are times when a Linux System Ambassador is asked to create user accounts on Linux with some specific backdrop, limitations, or comments.

[ You might also like: How to Create a Shared Directory for All Users in Linux ]

In Linux, a 'useradd' command is a low-level utility that is used for calculation/creating user accounts in Linux and other Unix-like operating systems. The 'adduser' is much like to the useradd control because it is just a symbolic link to information technology.

add users in linux
useradd control examples

In another Linux distributions, the useradd command may come with a slightly different version. I suggest you read your documentation, earlier using our instructions to create new user accounts in Linux.

When nosotros run the 'useradd' command in the Linux terminal, information technology performs the following major things:

  • Information technology edits /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the newly created user accounts.
  • Creates and populates a home directory for the new user.
  • Sets permissions and ownerships to the dwelling house directory.

Useradd Control Syntax

The Basic syntax of the useradd command is:

# useradd [options] username        

In this commodity, nosotros will show y'all the most used 15 useradd commands with their practical examples in Linux. Nosotros take divided the section into 2 parts from Bones to Advance usage of the command.

  • Part I: Basic Useradd Commands with x examples
  • Role II: Accelerate Useradd Commands with v examples

Part I – 10 Basic Usage of useradd Commands

ane. How to Add together a New User in Linux

To add/create a new user, you've to follow the command 'useradd' or 'adduser' with 'username'. The 'username' is a user login name, that is used by a user to login into the organisation.

But ane user tin can exist added and that username must be unique (different from other usernames already exists on the system).

For example, to add together a new user chosen 'tecmint', utilize the following command.

[[email protected] ~]# useradd tecmint

When nosotros add together a new user in Linux with the 'useradd' command it gets created in a locked state and to unlock that user business relationship, nosotros need to set a password for that account with the 'passwd' command.

[[e-mail protected] ~]# passwd tecmint Irresolute password for user tecmint. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
Create User in Linux
Create User in Linux

Once a new user is created, its entry is automatically added to the '/etc/passwd' file. The file is used to store the user'due south data and the entry should be.

tecmint:x:g:1000:tecmint:/dwelling/tecmint:/bin/fustigate
View User Info in Linux
View User Info in Linux

The above entry contains a set up of vii colon-separated fields, each field has its own significant. Allow's see what are these fields:

  • Username: User login proper noun used to login into the organization. It should be between 1 to 32 characters long.
  • Countersign: User password (or x character) stored in /etc/shadow file in encrypted format.
  • User ID (UID): Every user must have a User ID (UID) User Identification Number. By default, UID 0 is reserved for the root user and UID'southward ranging from i-99 are reserved for other predefined accounts. Farther UID's ranging from 100-999 are reserved for system accounts and groups.
  • Group ID (GID): The primary Group ID (GID) Group Identification Number stored in the /etc/group file.
  • User Info: This field is optional and allows you lot to define extra information most the user. For instance, user full name. This field is filled past the 'finger' command.
  • Home Directory: The absolute location of the user'southward domicile directory.
  • Shell: The absolute location of a user's shell i.e. /bin/bash.

2. Create a User with Different Home Directory

Past default 'useradd' command creates a user'southward home directory under /home directory with a username. Thus, for example, we've seen above the default home directory for the user 'tecmint' is '/dwelling house/tecmint'.

Even so, this action tin exist inverse by using the '-d' option along with the location of the new home directory (i.e. /data/projects). For example, the following command will create a user 'anusha' with a home directory '/data/projects'.

[[email protected] ~]# useradd -d /data/projects anusha [[electronic mail protected] ~]# passwd anusha        

You can run into the user domicile directory and other user-related data like user id, group id, shell, and comments.

[[email protected] ~]# true cat /etc/passwd | grep anusha          anusha:x:1001:1001::/data/projects:/bin/bash
Create User with Home Directory in Linux
Create User with Home Directory in Linux

3. Create a User with a Specific User ID

In Linux, every user has its ain UID (Unique Identification Number). By default, whenever we create a new user account in Linux, it assigns userid 500, 501, 502, and and then on…

Simply, nosotros can create users with custom userid with the '-u' option. For instance, the following control will create a user 'navin' with custom userid '1002'.

[[email protected] ~]# useradd -u 1002 navin

Now, let's verify that the user created with a divers userid (1002) using the following command.

[[email protected] ~]# cat /etc/passwd | grep navin  navin:x:1002:1002::/domicile/navin:/bin/bash
Create User with User ID in Linux
Create User with the User ID in Linux

Notation: Make sure the value of a user ID must exist unique from any other already created users on the arrangement.

4. Create a User with a Specific Grouping ID

Similarly, every user has their ain GID (Grouping Identifier). We can create users with specific group IDs equally well with the -g choice.

Here in this example, we will add a user 'tarunika' with a specific UID and GID simultaneously with the assistance of '-u' and '-grand' options.

[[email protected] ~]# useradd -u 1005 -thousand tecmint tarunika

At present, see the assigned user id and group id in '/etc/passwd' file.

[[electronic mail protected] ~]# cat /etc/passwd | grep tarunika          tarunika:x:1005:1000::/home/tarunika:/bin/bash        

To verify the user'southward GID, apply the id command:

[[electronic mail protected] ~]# id -gn tarunika        
Create User with Group ID in Linux
Create User with Group ID in Linux

5. Add a User to Multiple Groups

The '-K' option is used to add a user to additional groups. Each group name is separated by a comma, with no intervening spaces.

Here in this example, nosotros are calculation a user 'tecmint' into multiple groups like admins, webadmin, and developer.

[[email protected]:~]# groupadd admins [[email protected]:~]# groupadd webadmin [[electronic mail protected]mint:~]# groupadd developers [[email protected]:~]# usermod -a -One thousand admins,webadmin,developers tecmint [[e-mail protected]:~]# useradd -G admins,webadmin,developers paddy        

Next, verify that the multiple groups are assigned to the user with the id control.

[[email protected] ~]# id tecmint  uid=1000(tecmint) gid=1000(tecmint) groups=1000(tecmint),1007(admins),1008(webadmin),1009(developers) context=root:system_r:unconfined_t:SystemLow-SystemHigh
Add User to Group in Linux
Add User to Group in Linux

[ You might also like: How to Add together or Remove a User from a Grouping in Linux ]

6. Add a User without Home Directory

In some situations, where nosotros don't want to assign home directories for a user, due to some security reasons. In such a situation, when a user logs into a organization that has just restarted, its home directory volition be root. When such a user uses the su command, its login directory will be the previous user'southward home directory.

To create users without their dwelling directories, '-Yard' is used. For case, the following control will create a user 'shilpi' without a home directory.

[[email protected] ~]# useradd -M shilpi

Now, let's verify that the user is created without a dwelling house directory, using the ls control.

[[email protected] ~]# ls -l /habitation/shilpi  ls: cannot access          /home/shilpi: No such file or directory
Create User Without Home Directory in Linux
Create User Without Dwelling house Directory in Linux

7. Create a User with Account Expiry Engagement

Past default, when nosotros add together user'due south with the 'useradd' control user account never go expires i.east their expiry appointment is set to 0 (means never expired).

However, we tin set the death appointment using the '-due east' option, which sets the engagement in YYYY-MM-DD format. This is helpful for creating temporary accounts for a specific period of time.

[ You lot might also like: How to Manage User Password Expiration and Aging in Linux ]

Here in this example, we create a user 'aparna' with business relationship death date i.e. 27th August 2021 in YYYY-MM-DD format.

[[email protected] ~]# useradd -e 2021-08-27 aparna

Next, verify the age of the account and password with the 'chage' command for user 'aparna' after setting the account decease appointment.

[[electronic mail protected] ~]# chage -l aparna  Last password alter					: Jun 25, 2021 Countersign expires					: never Password inactive					: never Account expires						: Aug 27, 2021 Minimum number of days between countersign change		: 0 Maximum number of days between password alter		: 99999 Number of days of warning before countersign expires	: 7        
Create User With Account Expiry Date
Create User With Account Death Appointment

8. Create a User with Password Expiry Date

The '-f' argument is used to define the number of days after a password expires. A value of 0 inactive the user business relationship as soon equally the countersign has expired. By default, the countersign death value set to -one ways never elapse.

Here in this instance, we will set an account password death date i.eastward. 45 days on a user 'mansi' using '-e' and '-f' options.

[[email protected] ~]# useradd -east 2014-04-27 -f 45 mansi
Create User With Password Expiry Date
Create User With Password Decease Date

9. Add together a User with Custom Comments

The '-c' pick allows you to add custom comments, such every bit the user's full name, phone number, etc to /etc/passwd file. The annotate tin be added every bit a single line without any spaces.

For example, the following control will add a user 'mansi' and would insert that user'south full proper noun, Manis Khurana, into the comment field.

[[email protected] ~]# useradd -c "Manis Khurana" mansi

You tin can encounter your comments in the '/etc/passwd' file in the comments section.

[[e-mail protected] ~]# tail -1 /etc/passwd          mansi:x:1010:1013:Manis Khurana:/abode/mansi:/bin/sh
Create User with Full Name
Create User with Full Name

ten. Create User Login Beat out in Linux

Sometimes, we add users who have nothing to do with the login beat or sometimes nosotros require to assign different shells to our users. We tin assign dissimilar login shells to each user with the '-s' selection.

Hither in this example, will add a user 'tecmint' without login shell i.e. '/sbin/nologin' shell.

[[electronic mail protected] ~]# useradd -southward /sbin/nologin tecmint

You lot tin check the assigned shell to the user in the '/etc/passwd' file.

[[email protected] ~]# tail -1 /etc/passwd          tecmint:ten:1011:1014::/home/tecmint:/sbin/nologin                  
Create User with Login Shell
Create User with Login Shell

Part Ii – v Accelerate Usage of useradd Commands

11. Add a User with Specific Domicile Directory, Default Beat out, and Custom Comment

The post-obit command will create a user 'ravi' with dwelling directory '/var/world wide web/tecmint', default vanquish /bin/fustigate and adds extra information about the user.

[[e-mail protected] ~]# useradd -thou -d /var/www/ravi -s /bin/bash -c "TecMint Possessor" -U ravi
Create User with Home Directory and Login Shell
Create User with Home Directory and Login Vanquish

In the above control '-g -d' option creates a user with a specified home directory and the '-s' option sets the user's default beat i.e. /bin/fustigate. The '-c' option adds the extra data nearly the user and the '-U' argument creates/adds a group with the same proper noun every bit the user.

12. Add a User with Home Directory, Custom Beat out, Custom Annotate, and UID/GID

The command is very like to above, but here we defining beat out as '/bin/zsh' and custom UID and GID to a user 'tarunika'. Where '-u' defines the new user's UID (i.eastward. 100) and whereas '-g' defines GID (i.e. 1000).

[[email protected] ~]# useradd -m -d /var/www/tarunika -due south /bin/zsh -c "TecMint Technical Writer" -u 1000 -thousand 100 tarunika
Create User with UID and GID
Create User with UID and GID

13. Add a User with Domicile Directory, No Vanquish, Custom Annotate, and User ID

The following control is very much similar to the to a higher place two commands, the simply difference is hither, that we disabling the login shell to a user chosen 'avishek' with a custom User ID (i.e. 1019).

Hither '-s' option adds the default shell /bin/bash, but in this example we ready login to '/usr/sbin/nologin'. That means user 'avishek' volition non able to login into the organisation.

[[email protected] ~]# useradd -grand -d /var/www/avishek -s /usr/sbin/nologin -c "TecMint Sr. Technical Writer" -u 1019 avishek
Create User with UID and Nologin
Create User with UID and Nologin

14. Add a User with Home Directory, Shell, Custom Skell/Annotate, and User ID

The only modify in this control is, nosotros used '-k' option to prepare the custom skeleton directory i.e. /etc/custom.skell, not the default i /etc/skel. We likewise used '-s' selection to define different trounce i.e. /bin/tcsh to user 'navin'.

[[email protected] ~]# useradd -grand -d /var/www/navin -k /etc/custom.skell -southward /bin/tcsh -c "No Active Member of TecMint" -u 1027 navin
Create User with Shell and UID
Create User with Shell and UID

15. Add a User without Abode Directory, No Shell, No Group, and Custom Annotate

The following command is very dissimilar than the other commands explained above. Here we used the '-Yard' option to create a user without the user's home directory and the '-N' argument is used that tells the system to only create a username (without grouping). The '-r' argument is for creating a arrangement user.

[[email protected] ~]# useradd -M -N -r -s /bin/false -c "Disabled TecMint Member" clayton
Create User with NoLogin and Group
Create User with NoLogin and Group

For more information and options nigh useradd, run the 'useradd' control on the terminal to come across available options.

# useradd        

[ You lot might also like: 15 Useful Usermod Command Examples in Linux ]

Login in as a New User in Linux

DOWNLOAD HERE

Source: https://www.tecmint.com/add-users-in-linux/#:~:text=To%20add%2Fcreate%20a%20new,already%20exists%20on%20the%20system).

Posted by: simonsonfulther.blogspot.com