Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

Create Users with useradd Command on Linux – Complete Guide

by Cloudbooklet
4 years ago
in Google Cloud, AWS
Create Users With Useradd Command On Linux - Complete Guide
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Create Users and Manage with useradd Command – Linux Complete Guide. In Linux and other Unix operating systems you can create multiple users and assign them to a group or multiple groups and provide necessary privileges to the new users. By default root user has the highest privilege on the system. In this guide you […]

ADVERTISEMENT

Create Users and Manage with useradd Command – Linux Complete Guide. In Linux and other Unix operating systems you can create multiple users and assign them to a group or multiple groups and provide necessary privileges to the new users. By default root user has the highest privilege on the system.

In this guide you are going to learn how to create users with useradd command and also explore the options that can be used with this command.

You can also use this guide on any Linux OS bases systems or servers or on Cloud or VPS or any dedicated servers also.

ADVERTISEMENT

Prerequisites

Logged in to the server or system SSH as root or the user with sudo privileges.

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago

useradd Command Syntax

The general syntax for the useradd command is as follows.

useradd username

When you run this command your will be prompted with several questions to create the user.

ADVERTISEMENT

The useradd command also allow several options to be added with the following syntax.

useradd options username

Create a New User in Linux

To create a new user account type useradd followed by the username.

ADVERTISEMENT
sudo useradd username

In its simplest form when used without any option, useradd will create a new user account with the default settings specified in the /etc/default/useradd file.

To log in as the newly created user, you need to set the user password using the passwd command as shown below.

ADVERTISEMENT
sudo passwd username

You will be prompted to enter and confirm the password. Make sure you use a strong password.

Changing password for user username.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Create New User with Home Directory

You can use the -m (--create-home) option to create the user with home directory as /home/username

ADVERTISEMENT
sudo useradd -m username

This command creates the new home directory with the username as directory name.

Create User with Different Home Directory

If you want to create the user’s home directory in other location than the default /home directory you can use the d (--home) option as shown below.

sudo useradd -m -d /new/path username

Create User with Specific User ID

By default when a new user is created the system assigns the next available UID from the range of user IDs specified in the login.defs file.

You can use the -u (--uid) option to create a user with a specific UID.

sudo useradd -u 1500 username

You can verify the user’s UID, using the id command:

id -u username
Output
1500

Create User with Specific Group ID

When creating a new user the default behavior of the useradd command is to create a group with the same name as the username, and same GID as UID.

You can use the -g (--gid) option to create a user with a specific initial login group. You can specify either the group name or the GID number.

The group name or GID should exist.

sudo useradd -g users username

To verify the user’s GID, use the id command:

id -gn username
Output
users

Create User and Assign Multiple Groups

There are two types of groups in Linux operating systems Primary group and Secondary or supplementary group. Each user can belong to exactly one primary group and zero or more secondary groups.

The -G (--groups) option allows you to specify a list of supplementary groups which the user will be a member of.

sudo useradd -g users -G wheel,docker username

Create User with Specific Login Shell

By default, the new user’s login shell is set to the one specified in the /etc/default/useradd file. In some Linux distributions such as Ubuntu 18.04 the default shell is set to /bin/sh while in others it is set to /bin/bash.

The -s (--shell) option allows you to specify the new user’s login shell.

To create a new user named username with /bin/sh as a login shell type you can use the following command.

sudo useradd -s /bin/sh username

Create User with a Comment

The -c (--comment) option allows you to add a short description for the new user. Typically the user’s full name or the contact information are added as a comment.

In the following example we are creating a new user named username with text string New User Account as a comment:

sudo useradd -c "New User Account" username

The comment field is also known as GECOS.

Create User with an Expiry Date

The -e (--expiredate) option allows you to define a time at which the new user accounts will expire. This option is useful for creating temporary accounts.

To create a new user account named username with expiry time set to December 31 2025 you can follow the below example. The date must be specified using the YYYY-MM-DD format.

sudo useradd -e 2025-25-31 username

You can use the chage command to verify the user account expiry date:

sudo chage -l username

Create a System User

There is no real technical difference between the system and regular (normal) users. Typically system users are created when installing the OS and new packages.

In some situations, you may need to create a system user that will be used by some application.

Use the -r (--system) option to create a system user account. For example, to create a new system user named username you would run:

sudo useradd -r username

System users are created with no expiry date. Their UIDs are chosen from the range of system user IDs specified in the login.defs file which is different than the range used for normal users.

Change the Default useradd Values

The default useradd options can be viewed and changed using the -D, --defaults option or by manually editing the values in the /etc/default/useradd file.

To view the current default options type:

useradd -D

The output will look something like this:

GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no

Let’s say you want to change the default login shell from /bin/sh to /bin/bash. To do that specify the new shell as shown below:

sudo useradd -D -s /bin/bash

You can verify that the default shell value is changed by running the following command:

sudo useradd -D | grep -i shell
SHELL=/bin/bash

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

Conclusion

Now you have learned how to create user with useradd command and also explored all options related to this command.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: AWSCentOSDebianGoogle Cloud PlatformUbuntu 18.04
Share8Tweet5SendShare
Cloudbooklet

Cloudbooklet

Leave a Reply Cancel reply

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

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Validator Ai

Validator AI: The AI Powered Business Idea Validator

September 20, 2023

How to Delete Netflix Account Permanently

HeyGen AI: Free AI Video Generator to Create Amazing Videos

10 Best AI Song Generator in 2023 (Free and Paid)

Google Bard Extensions: How to Link Your Gmail, Docs, Maps, and More to an AI Chatbot

How to Create and Customize Stunning Contact Poster on iPhone

Popular Articles

Ai Script Generator

Free AI Script Generators Online to Create High Quality Scripts

August 28, 2023

How to Find Songs on YouTube by Humming the Tune

How to Use Midjourney for Pixel Graphics – Tips and Tricks

How to Clear Gmail Inbox with AI: Tips and Tricks

10 Best AI Prompts for Writers to Improve Website SEO

6 Best AI Cover Song Generators for Free Online

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.