KEMBAR78
Linux User Creation Guide | PDF | Computer Architecture | Utility Software
0% found this document useful (0 votes)
130 views13 pages

Linux User Creation Guide

The document provides examples of using the useradd command in Linux to create users with specific configurations. It demonstrates how to add a user with a custom home directory, shell, comment and UID/GID. It also shows how to create a user without a home directory or shell, and with a custom comment and user ID. The final example creates a user without a home directory, shell or group, and with a custom comment.

Uploaded by

sandeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views13 pages

Linux User Creation Guide

The document provides examples of using the useradd command in Linux to create users with specific configurations. It demonstrates how to add a user with a custom home directory, shell, comment and UID/GID. It also shows how to create a user without a home directory or shell, and with a custom comment and user ID. The final example creates a user without a home directory, shell or group, and with a custom comment.

Uploaded by

sandeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Add a User with Specific Home Directory,

Default Shell and Custom Comment


The following command will create a user ‘ravi‘ with home directory
‘/var/www/tecmint‘, default shell /bin/bash and adds extra information about
user.

[root@tecmint ~]# useradd -m -d /var/www/ravi -s


/bin/bash -c "TecMint Owner" -U ravi

In the above command ‘-m -d‘ option creates a user with specified home
directory and the ‘-s‘ option set the user’s default shell i.e. /bin/bash. The ‘-c‘
option adds the extra information about user and ‘-U‘ argument create/adds a
group with the same name as the user.
12. Add a User with Home Directory,
Custom Shell, Custom Comment and
UID/GID
The command is very similar to above, but here we defining shell as ‘/bin/zsh‘
and custom UID and GID to a user ‘tarunika‘. Where ‘-u‘ defines new
user’s UID (i.e. 1000) and whereas ‘-g‘ defines GID (i.e. 1000).

[root@tecmint ~]# useradd -m -d /var/www/tarunika -s


/bin/zsh -c "TecMint Technical Writer" -u 1000 -g 1000
tarunika

13. Add a User with Home Directory, No


Shell, Custom Comment and User ID
The following command is very much similar to above two commands, the
only difference is here, that we disabling login shell to a user called ‘avishek‘
with custom User ID (i.e. 1019).
Here ‘-s‘ option adds the default shell /bin/bash, but in this case we set login
to ‘/usr/sbin/nologin‘. That means user ‘avishek‘ will not able to login into the
system.
[root@tecmint ~]# useradd -m -d /var/www/avishek -s
/usr/sbin/nologin -c "TecMint Sr. Technical Writer" -u
1019 avishek

14. Add a User with Home Directory,


Shell, Custom Skell/Comment and User ID
The only change in this command is, we used ‘-k‘ option to set custom
skeleton directory i.e. /etc/custom.skell, not the default one /etc/skel. We
also used ‘-s‘ option to define different shell i.e. /bin/tcsh to user ‘navin‘.

[root@tecmint ~]# useradd -m -d /var/www/navin -k


/etc/custom.skell -s /bin/tcsh -c "No Active Member of
TecMint" -u 1027 navin

15. Add a User without Home Directory,


No Shell, No Group and Custom
Comment
This following command is very different than the other commands explained
above. Here we used ‘-M‘ option to create user without user’s home directory
and ‘-N‘ argument is used that tells the system to only create username
(without group). The ‘-r‘ arguments is for creating a system user.

[root@tecmint ~]# useradd -M -N -r -s /bin/false -c


"Disabled TecMint Member" clayton

For more information and options about useradd, run ‘useradd‘ command on
the terminal to see available options.
Read Also: 15 usermod Command Examples
TagsAdduser, Linux Users, UseraddPost navigation
nSnake: A Clone of Old Classic Snake Game – Play in Linux Terminal
Fun in Linux Terminal – Play with Word and Character Counts
If you liked this article, then do subscribe to email alerts for Linux tutorials. If
you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You


Should Consider:

TecMint is the fastest growing and most trusted community site for
any kind of Linux Articles, Guides and Books on the web. Millions of
people visit TecMint! to search or browse the thousands of
published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee
( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Related Posts
Install Linux from USB Device or Boot into Live Mode Using Unetbootin
and dd Command

6 Best CLI Tools to Search Plain-Text Data Using Regular Expressions

How to Install tar in CentOS, RHEL, and Fedora


Diskonaut – A Terminal Disk Space Navigator for Linux

CDIR – A Faster Way to Navigate Folders and Files on Linux


How to Install Zip and Unzip in Linux

117 thoughts on “The Complete Guide to


“useradd” Command in Linux – 15
Practical Examples”
Comment navigation
← Older Comments

1.
Binh Thanh Nguyen
September 1, 2020 at 4:28 am
Thanks, nice tips

Reply

2.
Yogesh Tiwari
August 26, 2020 at 7:20 pm
Hi,

Can you please tell us to how to create a user with password in single
command line on Debian
Thank you.

Yogesh

Reply


Ravi Saive
August 27, 2020 at 9:32 am
@Yogesh,

I hope this following command will help you to add user and password with
one single command.

$ sudo useradd username; echo password | passwd username --stdin

Reply

3.
Ray
April 21, 2020 at 4:57 am
I cannot get the ‘adduser‘ or ‘useradd‘ commands to work. Whenever I try I
get the prompt “bash: useradd: command not found”
Reply


Ravi Saive
April 21, 2020 at 10:42 am
@Ray,

First, locate the useradd location using:

# whereis useradd

Then, try adding /usr/sbin to your path.


Reply

4.
Harry
January 31, 2020 at 7:14 am
Thanks again for your response.
Quick question- If the user joins signs in/out the following day, it will be the
closet possible date of creation – correct?

e.g. I created user john on Jan 30 and the sign joins organization on Jan 31
and signs in/out, this is when .bash_logout will be created -correct?
Thanks

Reply

5.
Harry
January 29, 2020 at 8:36 pm
I created a new user and it came up with some results, not so relevant to the
user creation date. However, it seems like showing me authentication success
or failure for the user.

Any further ideas?

Reply


Ravi Saive
January 30, 2020 at 11:50 am
@Harry,

To find out correct user creation date in Linux, you need to check the stats
of .bash_logout file in your home directory.
$ stat /home/tecmint/.bash_logout

Sample Output
File: /home/tecmint/.bash_logout

Size: 220 Blocks: 8 IO Block: 4096 regular file

Device: 803h/2051d Inode: 6162417 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 1000/ tecmint) Gid: ( 1000/ tecmint)

Access: 2020-01-02 12:16:13.475201521 +0530

Modify: 2019-02-15 17:23:35.675059936 +0530

Change: 2019-02-15 17:23:35.675059936 +0530


Birth: -
In the output above highlighted, shows the correct user creation date..

Reply

6.
Harry
January 28, 2020 at 8:18 pm
I installed and run without any luck. It returned no results. I double-
checked /etc/passwd to confirm if the user I am testing with existed.
I checked the status and restarted the service auditd.
# systemctl status auditd

# systemctl restart auditd

Is there anything I am missing?

Thanks

Reply


Ravi Saive
January 29, 2020 at 10:38 am
@Harry,

You just installed auditd, so it will not track existing users. Try to create a
new user and see..
Reply

7.
harry
January 27, 2020 at 5:03 am
Hey,

How can I create a user which shows the date of creation (date stamp) so that
IS security can audit it, down the road. It would be great if it is for RHEL or
Ubuntu distros.

Thanks

Reply

Ravi Saive
January 27, 2020 at 2:03 pm
@Harry,

To Find Out When a User is Created in Linux, you can check the stat
of .bash_logout file, as this file is created upon the user’s first logout.
# stat /home/username/.bash_logout

Reply


Harry
January 27, 2020 at 8:05 pm
Thank you for your quick response.

At work, I have a scenario where we generally create a user a day in


advance of his joining date. If I follow, what you said I can get
approximation and not exact date as a user will log in and logout the
following day. However, our IS security team wants to know the time
stamp of user creation or their audit. Do you recommend any other way
to know the creation date?

Reply


Ravi Saive
January 28, 2020 at 11:16 am
@Harry,

If you have auditd installed on the system, you can find out the user
creation date and time.
# aureport --auth | grep username

Alternatively, you can find the user creation in /var/log/secure file..


Reply

8.
SAURABH RAJPUT
January 15, 2020 at 10:03 am
I am not able to set a password for a new user, it shows heading New
password but it does not type anything neither any alphabetical letter nor a
number.
Please help me.

Reply

9.
madhav
June 6, 2019 at 2:12 pm
Example 5)

if the user is already exit command should be:

# usermod -G admins,webadmin,developers tecmint

If you are adding the new user to additional groups then command:

# useradd -G

is correct…

Reply
Comment navigation
← Older Comments
Got something to say? Join the
discussion.
Have a question or suggestion? Please leave a comment to start the
discussion. Please keep in mind that all comments are moderated and your
email address will NOT be published.

Comment

Name EmailWebsite

 Save my name, email, and website in this browser for the next time I
comment.
 Notify me of followup comments via e-mail. You can
also subscribe without commenting.
Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is
processed.
Over 3,500,000+ Readers

         
A Beginners Guide To Learn Linux for Free [with Examples]
Red Hat RHCSA/RHCE 8 Certification Study Guide [eBooks]
Linux Foundation LFCS and LFCE Certification Study Guide [eBooks]
Learn Linux Commands and Tools
How to Enable, Disable and Install Yum Plug-ins
fswatch – Monitors Files and Directory Changes or Modifications in
Linux
How to Run Multiple Commands on Multiple Linux Servers
procinfo – Shows System Statistics from /proc Filesystem
How to Enable Syntax Highlighting in Vi/Vim Editor
Switching From Windows to Nix or a Newbie to Linux – 20 Useful
Commands for Linux Newbies
If You Appreciate What We Do Here On TecMint, You Should Consider:

You might also like