Escolar Documentos
Profissional Documentos
Cultura Documentos
adduser in Linux. There are times when a Linux System Administrator asked
to create user accounts on Linux with some specific properties, limitations or
comments.
In Linux, a useradd command is a low-level utility that is used for
adding/creating user accounts in Linux and other Unix-like operating
systems. The adduser is much similar to useradd command, because it is
just a symbolic link to it.
In some other Linux distributions, useradd command may comes with lightly
difference version. I suggest you to read your documentation, before using our
instructions to create new user accounts in Linux.
When we run useradd command in Linux terminal, it performs following
major things:
useradd[options]username
In this article we will show you the most used 15 useradd commands with
their practical examples in Linux. We have divided the section into two parts
from Basic to Advance usage of command.
[root@tecmint~]#useraddtecmint
When we add a new user in Linux with useradd command it gets created in
locked state and to unlock that user account, we need to set a password for
that account with passwd command.
[root@tecmint~]#passwdtecmint
Changingpasswordforusertecmint.
NewUNIXpassword:
RetypenewUNIXpassword:
passwd:allauthenticationtokensupdatedsuccessfully.
Once a new user created, its entry automatically added to the /etc/passwd
file. The file is used to store users information and the entry should be.
tecmint:x:504:504:tecmint:/home/tecmint:/bin/bash
The above entry contains a set of seven colon-separated fields, each field has
its own meaning. Lets see what are these fields:
User Info: This field is optional and allow you to define extra
information about the user. For example, user full name. This
field is filled by finger command.
[root@tecmint~]#useraddd/data/projectsanusha
You can see the user home directory and other user related information like
user id, group id, shell and comments.
[root@tecmint~]#cat/etc/passwd|grepanusha
anusha:x:505:505::/data/projects:/bin/bash
[root@tecmint~]#useraddu999navin
Now, lets verify that the user created with a defined userid (999) using
following command.
[root@tecmint~]#cat/etc/passwd|greptecmint
navin:x:999:999::/home/navin:/bin/bash
NOTE: Make sure the value of a user ID must be unique from any other
already created users on the system.
[root@tecmint~]#useraddu1000g500tarunika
[root@tecmint~]#cat/etc/passwd|greptarunika
tarunika:x:1000:500::/home/tarunika:/bin/bash
The -G 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, we are adding a user tecmint into multiple groups
like admins, webadmin and developer.
[root@tecmint~]#useraddGadmins,webadmin,developerstecmint
Next, verify that the multiple groups assigned to the user with id command.
[root@tecmint~]#idtecmint
uid=1001(tecmint)gid=1001(tecmint)
groups=1001(tecmint),500(admins),501(webadmin),502(developers)
context=root:system_r:unconfined_t:SystemLowSystemHigh
[root@tecmint~]#useraddMshilpi
Now, lets verify that the user is created without home directory, using ls
command.
[root@tecmint~]#lsl/home/shilpi
ls:cannotaccess/home/shilpi:Nosuchfileordirectory
[root@tecmint~]#useradde20140327aparna
Next, verify the age of account and password with chage command for user
aparna after setting account expiry date.
[root@tecmint~]#chagelaparna
Lastpasswordchange
:Mar28,2014
Passwordexpires
:never
Passwordinactive
:never
Accountexpires
:Mar27,2014
Minimumnumberofdaysbetweenpasswordchange
:0
Maximumnumberofdaysbetweenpasswordchange
:99999
Numberofdaysofwarningbeforepasswordexpires
:7
[root@tecmint~]#useradde20140427f45tecmint
[root@tecmint~]#useraddc"ManisKhurana"mansi
[root@tecmint~]#tail1/etc/passwd
mansi:x:1006:1008:Manis Khurana:/home/mansi:/bin/sh
[root@tecmint~]#useradds/sbin/nologintecmint
[root@tecmint~]#tail1/etc/passwd
tecmint:x:1002:1002::/home/tecmint:/sbin/nologin
The following command will create a user ravi with home directory
/var/www/tecmint, default shell /bin/bashand adds extra information
about user.
[root@tecmint~]#useraddmd/var/www/ravis/bin/bashc"TecMintOwner"
Uravi
[root@tecmint~]#useraddmd/var/www/tarunikas/bin/zshc"TecMint
TechnicalWriter"u1000g1000tarunika
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~]#useraddmd/var/www/avisheks/usr/sbin/nologinc
"TecMintSr.TechnicalWriter"u1019avishek
[root@tecmint~]#useraddmd/var/www/navink/etc/custom.skells
/bin/tcshc"NoActiveMemberofTecMint"u1027navin
[root@tecmint~]#useraddMNrs/bin/falsec"DisabledTecMintMember"
clayton
For more information and options about useradd, run useradd command on
the terminal to see available options.