The following warnings occurred:
Warning [2] Use of undefined constant postnum - assumed 'postnum' (this will throw an Error in a future version of PHP) - Line: 253 - File: inc/plugins/my_activity.php PHP 7.2.14 (Linux)
File Line Function
/inc/plugins/my_activity.php 253 errorHandler->error
/inc/class_plugins.php 139 my_activity_postbit
/inc/functions_post.php 826 pluginSystem->run_hooks
/showthread.php 1070 build_postbit

Welcome to UltratechHost Forum, Guest. Please take the time to register if you haven't, or click

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

guide to “useradd” command in linux part 2

RedHat Guide to “useradd” Command in Linux [Part 2]

This post is about other option of useradd/adduser

Previous post:

Create a User with Specific Group ID
Similarly, every user has its own GID (Group Identification Number). We can create users with specific group ID’s as well with -g option or --gid option.

Here in this example, we will add a user ‘tarunika‘ with a specific UID and GID simultaneously with the help of ‘-u or --uid‘ and ‘-g or --gid‘ options.

# useradd -u 1000 -g 500 sumit

Now, see the assigned user id and group id in ‘/etc/passwd‘ file.

# cat /etc/passwd | grep sumit

Add a User to Multiple Groups
The ‘-G‘ option is used to add a user to additional groups. Each group name is separated by a comma, with no intervening spaces.

# useradd -G admins,webadmin,developers raju

Add a User without Home Directory
In some situations, where we don’t want to assign a home directories for a user’s, due to some security reasons. In such situation, when a user logs into a system that has just restarted, its home directory will be root. When such user uses su command, its login directory will be the previous user home directory.

To create user’s without their home directories, ‘-M‘ is used. For example, the following command will create a user ‘govi‘ without a home directory.

# useradd -M govi
# useradd --no-create-home govi

Now, let’s verify that the user is created without home directory, using ls command.

# ls -l /home/govi

Create a User with Account Expiry Date
By default, when we add user’s with ‘useradd‘ command user account never get expires i.e their expiry date is set to 0 (means never expired).

However, we can set the expiry date using ‘-e‘ option, that sets date in YYYY-MM-DD format. This is helpful for creating temporary accounts for a specific period of time.

Here in this example, we create a user ‘raja‘ with account expiry date i.e. 12th August 2014 in YYYY-MM-DD format.

# useradd -e 2014-08-12 raja
# useradd --expiredate 2014-08-12 raja

Next, verify the age of account and password with ‘chage‘ command for user ‘raja‘ after setting account expiry date.

# chage -l raja

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 account as soon as the password has expired. By default, the password expiry value set to -1 means never expire.

Here in this example, we will set a account password expiry date i.e. 45 days on a user ‘raja’ using ‘-e‘ and ‘-f‘ options.

# useradd -e 2014-08-12 -f 45 raja

Add a User with Custom Comments
The ‘-c‘ option allows you to add custom comments, such as user’s full name, phone number, etc to /etc/passwd file. The comment can be added as a single line without any spaces.

For example, the following command will add a user ‘dinesh‘ and would insert that user’s full name, Dinesh Mohanty, into the comment field.

# useradd -c "Dinesh Mohanty" dinesh


useradd --comment "Dinesh Mohanty" dinesh

You can see your comments in ‘/etc/passwd‘ file in comments section.

# tail -1 /etc/passwd

dinesh:x:1006:1008:Dinesh Mohanty:/home/dinesh:/bin/sh

Change User Login Shell
Sometimes, we add users which has nothing to do with login shell or sometimes we require to assign different shells to our users. We can assign different login shells to a each user with ‘-s‘ option.

Here in this example, will add a user ‘suraj‘ without login shell i.e. ‘/sbin/nologin‘ shell.

# useradd -s /sbin/nologin suraj
You can check assigned shell to the user in ‘/etc/passwd‘ file.

# tail -1 /etc/passwd


Dinesh Kumar Mohanty
Ultra Web Solutions®
Bhubaneswar, Odisha, India.

UltratechHost - Your One Stop Offshore & Onshore Hosting Provider
Server Locations : Netherlands, Germany, Russia, Singapore & USA
Service Offers: Shared hosting | Reseller hosting | Cloud server | Dedicated server | VPS Hosting

Forum Jump:

Users browsing this thread: 1 Guest(s)