Creating Local User Accounts in Linux/RHEL

Creating and managing user accounts is an essential part of system administration. But you have to have good understanding of what a user account is and how we can effectively create a new one. User account is method used by operating system to identify individual and to know which user has access to which file and services.
LinuxRHEL1

 

In this post I will cover only user creation part of user account handling. In next two post, we will learn user account modification and deletion. I am using Red Hat Enterprise Linux 6.3 (RHEL 6) though all command works with all other Linux flavors.
There are two type of users in Linux:
1. Normal users: Normal users have full access to their individual home folders and can perform tasks designated for them. They are restricted from viewing or altering other users’ files and folders.
2. Admin users: Admin users are just like any other normal user but can use or borrow (using ‘sudo’ command) rights of root user. They can perform any task by possessing powers of the root user.
Creating User Account
useradd command is used to create a new user account. To create an account for username ‘tony’ with default settings, use useradd command as follows:
1
# useradd tony
This will create the tony user account in the system with default user account settings. However useradd with no options/switch is not much useful.
Default ‘user account’ settings can be found in /etc/default/useradd file.
To create user account for username ‘tony’ with a display name ‘Tony Stark’:
1
# useradd -c 'Tony Stark' tony
Sometime you may need a user account but you don’t want that user to have shell access (Example: when creating user account for FTP/SMTP services, though these are created automatically) then you can use the command as follows:
1
# useradd -s /sbin/nologin -c 'Tony Stark' tony
Some important switches you should remember:
-g groupID/groupName  
To specify primary group name/id for the user. When specifying groupID, don’t use 0-500 as groupID because these are reserved to be used by the system. Whenever a new user account is created system also create a group with same name as username and makes the user its member. This group is called primary group of the user.
In following example we are giving user tony’s primary group’s groupid=1303
1
# useradd -g 1303 -c 'Tony Stark' tony

-G groupName1,groupName2,groupName3

To make user member of supplementary groups. All other groups other than primary group are called supplementary groups of the user.
In following example, we are making user tony member of three supplementary groups: personal, work and avengers
1
# useradd -G personal,research,avengers -c 'Tony Stark' tony

-u userID

To manully specify userid for the user (not recommended, let the system choose appropriate userid). Don’t use 0-500 as userid.
Following command will create user tony with userid 675.
1
# useradd -u 675 -c 'Tony Stark' tony

-M

To tell the system, not to create user’s home directory. below example command will create user account for tony but won’t create home directory for the user.
1
# useradd -M -c 'Tony Stark' tony

-b /new/path/for/home/dir

To specify home directory path for the user. In general, new user’s home directory is /home/username. By using below command you can specify different home directory (/newhome/tony) for the user.
1
# useradd -b /newhome -c 'Tony Stark' tony

-e dd/MM/YYYY

To set expiry date for the user account. By default a user account never expires. With following command, tony’s account will expire on 23-Jan-2015.
1
# useradd -e 23/01/2015 -c 'Tony Stark' tony

–help

You can use ‘help’ switch to view all available option which can be used with useradd command.

1
# useradd --help

Read More Post

STAY CONNECTED

Most Popular

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know
17 Dec

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know

If you’re heading to Singapore for a few weeks or many months, maybe for work or study or just to

Manifesting Your Dream Career: Finding Your Passion And Purpose
01 Aug

Manifesting Your Dream Career: Finding Your Passion And Purpose

Are you passionate about finding your dream career? Manifesting can help you align your career with your passions and purpose.

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service
27 Feb

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service

Finding a reliable auto service provider is paramount in the bustling world of vehicle maintenance and repair. That's where Carolina

Floratam: The Robust Grass Solution From Council Growers SOD
25 Jan

Floratam: The Robust Grass Solution From Council Growers SOD

Floratam grass, a popular St. Augustine variety, has become a go-to choice for homeowners and landscapers seeking a lush, durable

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair
25 Jan

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair

For vehicle owners, the braking system is among the most critical components for safety and performance. Carolina Mobile Autoservice, a

Safeguarding Your Property: Expert Water Damage Services By MBC Capital
24 Jan

Safeguarding Your Property: Expert Water Damage Services By MBC Capital

Water damage can significantly impact homes and businesses, often leaving a trail of destruction and disruption in its wake. Understanding