We are all aware of the most popular commands called ‘useradd‘ or ‘adduser‘ in Linux. There are times when a Linux System Administrator is asked to create user accounts on Linux with specific properties, limitations, or comments.
In Linux, the ‘useradd‘ command is a low-level utility used for adding or creating user accounts in Linux and other Unix-like operating systems. The ‘adduser‘ command is very similar to the ‘useradd‘ command, as it is just a symbolic link to it.
In some Linux distributions, the ‘useradd‘ command may have a slightly different version. I suggest reading your documentation before using our instructions to create new user accounts in Linux.
When we run the ‘useradd‘ command in the Linux terminal, it performs the following major tasks:
- It edits /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow files for the newly created user accounts.
- Creates and populates a home directory for the new user.
- Sets permissions and ownerships to the home directory.
Useradd Command Syntax
The basic syntax of the ‘useradd‘ command is:
useradd [options] username
In this article, we will demonstrate the 15 most commonly used ‘useradd‘ commands with practical examples in Linux.
1. How to Add a New User in Linux
To add or create a new user, you have to use the ‘useradd‘ or ‘adduser‘ command followed by the ‘username‘. The ‘username‘ is the login name a user uses to log into the system.
Only one user can be added, and the username must be unique, and not already exist on the system.
For example, to add a new user named ‘tecmint‘ use the following command:
useradd tecmint
When we add a new user in Linux with the ‘useradd‘ command, it gets created in a locked state. To unlock that user account, we need to set a password for that account using the ‘passwd‘ command.
passwd tecmint Changing password for user tecmint. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
Once a new user is created, its entry is automatically added to the ‘/etc/passwd‘ file. This file is used to store the user’s information, and the entry should be.
tecmint:x:1000:1000:tecmint:/home/tecmint:/bin/bash
The above entry contains a set of seven colon-separated fields, each field having its own meaning.
Let’s see what these fields are:
- Username – The user login name is used to log into the system. It should be between 1 and 32 characters long.
- Password – The user password (or
'x'
character) is stored in the ‘/etc/shadow‘ file in an encrypted format. - User ID (UID) – Every user must have a User ID (UID), which stands for User Identification Number. By default, UID 0 is reserved for the root user, and UIDs ranging from 1 to 99 are reserved for other predefined accounts. Additionally, UIDs ranging from 100 to 999 are reserved for system accounts and groups.
- Group ID (GID) – The primary Group ID (GID), which stands for Group Identification Number, is stored in the ‘/etc/group‘ file.
- User Info – This field is optional and allows you to define extra information about the user, such as the user’s full name. This information can be filled in using the finger command.
- Home Directory – The absolute location of the user’s home directory.
- Shell – The absolute location of a user’s shell i.e. /bin/bash.
2. How to Create a User with a Different Home Directory
By default, the ‘useradd‘ command creates a user’s home directory under the ‘/home‘ directory with the username. For example, as seen above, the default home directory for the user ‘tecmint‘ is ‘/home/tecmint‘.
However, this behavior can be changed by using the '-d'
option along with the location of the new home directory (e.g., ‘/data/projects‘). For instance, the following command will create a user ‘anusha‘ with a home directory set to ‘/data/projects‘.
# useradd -d /data/projects anusha # passwd anusha
You can view the user’s home directory and other user-related information, such as user ID, group ID, shell, and comments using the following cat command.
cat /etc/passwd | grep anusha anusha:x:1001:1001::/data/projects:/bin/bash
3. How to Create a User with a Specific User ID
In Linux, every user has their own UID (Unique Identification Number). By default, when we create a new user account in Linux, it assigns user IDs 500, 501, 502, and so on.
However, we can create users with custom user IDs using the '-u'
option. For example, the following command will create a user ‘navin‘ with a custom user ID ‘1002‘.
useradd -u 1002 navin
Now, let’s verify that the user created with a defined userid (1002) using the following command.
cat /etc/passwd | grep navin navin:x:1002:1002::/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.
4. How to Create a User with a Specific Group ID
Similarly, every user has their own GID (Group Identifier). We can create users with specific group IDs as well using the '-g'
option.
In this example, we will add a user ‘tarunika‘ with a specific UID and GID simultaneously with the help of the '-u'
and '-g'
options.
useradd -u 1005 -g tecmint tarunika
Now, check the assigned user ID and group ID in the ‘/etc/passwd‘ file.
cat /etc/passwd | grep tarunika tarunika:x:1005:1000::/home/tarunika:/bin/bash
To verify the user’s GID, use the id command:
id -gn tarunika
5. How to 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.
In this example, we are adding a user ‘tecmint‘ to multiple groups, such as admins, webadmin, and developers.
groupadd admins groupadd webadmin groupadd developers usermod -a -G admins,webadmin,developers tecmint useradd -G admins,webadmin,developers paddy
Next, verify that the multiple groups are assigned to the user with the id command.
id tecmint uid=1000(tecmint) gid=1000(tecmint) groups=1000(tecmint),1007(admins),1008(webadmin),1009(developers) context=root:system_r:unconfined_t:SystemLow-SystemHigh
6. How to Add a User Without Home Directory
In certain situations, where we don’t want to assign home directories for a user due to security reasons, the user’s home directory will be root when they log into a system that has just restarted. When such a user uses the ‘su‘ command, their login directory will be the previous user’s home directory.
To create users without their home directories, the '-M'
option is used. For example, the following command will create a user ‘shilpi‘ without a home directory.
useradd -M shilpi
Now, let’s verify that the user is created without a home directory using the ls command.
ls -l /home/shilpi ls: cannot access /home/shilpi: No such file or directory
7. How to Create a User With an Expiry Date in Linux
By default, when we add users with the ‘useradd‘ command, the user account never expires, meaning their expiry date is set to 0 (which means never expired).
However, we can set the expiry date using the '-e'
option, which should be in the YYYY-MM-DD format. This is helpful for creating temporary accounts for a specific period of time.
In this example, we create a user ‘aparna‘ with an account expiry date, which is 27th August 2021, in the YYYY-MM-DD format.
useradd -e 2021-08-27 aparna
Next, verify the account and password aging information using the ‘chage‘ command for the user ‘aparna‘ after setting the account expiry date.
chage -l aparna Last password change : Jun 25, 2021 Password expires : never Password inactive : never Account expires : Aug 27, 2021 Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7
8. How to 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 inactivates the user account as soon as the password has expired. By default, the password expiry value is set to -1
, which means it never expires.
In this example, we will set an account password expiry date, which is 45 days, for a user ‘mansi‘ using the '-e'
and '-f'
options.
useradd -e 2014-04-27 -f 45 mansi
9. How to Add a User with Comments in Linux
The '-c'
option allows you to add custom comments, such as the user’s full name, phone number, etc., to the ‘/etc/passwd‘ file. The comment can be added as a single line without any spaces.
For example, the following command will add a user ‘mansi‘ and insert that user’s full name, Manis Khurana, into the comment field.
useradd -c "Manis Khurana" mansi
You can view the inserted comment in the ‘/etc/passwd‘ file in the comments section using the tail command.
tail -1 /etc/passwd mansi:x:1010:1013:Manis Khurana:/home/mansi:/bin/sh
10. How to Create a User Login Shell in Linux
Sometimes, we add users who have nothing to do with the login shell or sometimes we are required to assign different shells to our users. We can assign different login shells to each user with the ‘-s‘ option.
Here in this example, will add a user ‘tecmint‘ without a login shell i.e. ‘/sbin/nologin‘ shell.
useradd -s /sbin/nologin tecmint
You can check the assigned shell to the user in the ‘/etc/passwd‘ file.
tail -1 /etc/passwd tecmint:x:1011:1014::/home/tecmint:/sbin/nologin
11. How to Create a User with Specified Home, Shell, and Comment
The following command will create a user ‘ravi‘ with a home directory ‘/var/www/tecmint‘, a default shell of /bin/bash, and additional information about the user.
useradd -m -d /var/www/ravi -s /bin/bash -c "TecMint Owner" -U ravi
In the above command, the options '-m'
and '-d'
creates a user with a specified home directory, and the '-s'
option sets the user’s default shell to /bin/bash. The '-c'
option adds extra information about the user and the '-U'
argument creates/adds a group with the same name as the user.
12. How to Create a User with a Defined Home, Shell, Comment, UID/GID
The command is very similar to the one above, but here we define the shell as ‘/bin/zsh‘ and set custom UID and GID for a user ‘tarunika‘. The '-u'
option defines the new user’s UID (i.e., 100), and the '-g'
option defines the GID (i.e., 1000).
useradd -m -d /var/www/tarunika -s /bin/zsh -c "TecMint Technical Writer" -u 1000 -g 100 tarunika
13. How to Create a User with Home, No Shell, Comment, and UID
The following command is very similar to the above two commands. The only difference is that here, we disabled the login shell for a user called ‘avishek‘ with a custom User ID (i.e., 1019).
The '-s'
option sets the default shell to /bin/bash, but in this case, we set the login shell to ‘/usr/sbin/nologin‘. That means the user ‘avishek‘ will not be able to log into the system.
useradd -m -d /var/www/avishek -s /usr/sbin/nologin -c "TecMint Sr. Technical Writer" -u 1019 avishek
14. How to Create a User with a Specified Home, Shell, Skeleton, and UID
The only change in this command is that we used the '-k'
option to set the custom skeleton directory to /etc/custom.skell instead of the default one, /etc/skel. We also used the '-s'
option to define a different shell, /bin/tcsh, for the user ‘navin‘.
useradd -m -d /var/www/navin -k /etc/custom.skell -s /bin/tcsh -c "No Active Member of TecMint" -u 1027 navin
15. How to Create a User without Home, Shell, or Group, with Comment
The following command is very different from the other commands explained above. Here, we used the '-M'
option to create a user without the user’s home directory, and the '-N'
option is used to instruct the system to only create a username (without a group). The '-r'
option is for creating a system user.
useradd -M -N -r -s /bin/false -c "Disabled TecMint Member" clayton
For more information and options about ‘useradd‘, run the ‘useradd‘ command in the terminal to see the available options
useradd
If you want to modify user account attributes such as modifying the username, user ID (UID), home directory, shell, and more, use the usermod command.
Section 3. Create a User with Specific User ID – >
With reference to this statement – “By default, whenever we create a new user accounts in Linux, it assigns userid 500, 501, 502 and so on…”
Doesn’t Linux create a new user and assign UID to new users by default from – 1001, 1002, 1003 … onwards, instead of 500 ?
“Doesn’t Linux create a new user and assign UID to new users by default from – 1001, 1002, 1003 … onwards, instead of 500 ?”
Depends on the distro. Some start at 500. It is also possible to change the starting number to almost anything you please, as long as the user numbers do not conflict with preset root/system numbers.
Thanks, nice tips
Hi,
Can you please tell us to how to create a user with password in single command line on Debian
Thank you.
Yogesh
@Yogesh,
I hope this following command will help you to add user and password with one single command.
I cannot get the ‘adduser‘ or ‘useradd‘ commands to work. Whenever I try I get the prompt “bash: useradd: command not found”
@Ray,
First, locate the useradd location using:
Then, try adding /usr/sbin to your path.
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
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?
@Harry,
To find out correct user creation date in Linux, you need to check the stats of
.bash_logout
file in your home directory.Sample Output
In the output above highlighted, shows the correct user creation date..
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.
Is there anything I am missing?
Thanks
@Harry,
You just installed auditd, so it will not track existing users. Try to create a new user and see..
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
@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.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?
@Harry,
If you have auditd installed on the system, you can find out the user creation date and time.
Alternatively, you can find the user creation in /var/log/secure file..
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.
Example 5)
if the user is already exit command should be:
If you are adding the new user to additional groups then command:
is correct…
Example no 3)
But, we can create user’s with custom userid with
‘-u‘
option. For example, the following command will create a user ‘navin‘ with custom userid ‘999‘.Now, let’s verify that the user created with a defined userid (999) using following command.
You created user navin with uid 999. in verification command you are checking for tecmint user and output user login name is correct that is navin and home dir is /home/tecmint … how?
@Madhav,
Sorry for confusion, yes its “navin” username. I’ve corrected in the article.
-f
switch is incorrectly explained above.-e
for expiry date of account.-f
,--inactive
INACTIVE: The number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired, and a value of -1 disables the feature.If not specified, useradd will use the default inactivity period specified by the INACTIVE variable in /etc/default/useradd, or
-1
by default.NOTE-chage uses: -E and
-M
(max days) for password expiry days after setting a new password.and chage uses
-I
switch which works like the-f
switch here.In Example #1 you did not specify either the UID or the GID but:
Please explain why, if UIDs 100-999 are reserved for system accounts and groups, why does ‘tecmint’ have UID of 504 and a GID of 504? Is ‘tecmint’ a system account? Based on the commands you used to set up user ‘tecmint’ the default UID and GID should be 1000. You did not specify
I know that in Linux one can permanently change the default starting UID and GID number. But in this case you have not done so.
Hi, I want to create a user who will have permission to read only files in his home directory. This user should not be able to read files in the etc and dev kind of folders. So how can I create this user.
Tried setfacl but there is no support for it in my board.
@Santhos,
Check this article: https://www.tecmint.com/give-read-write-access-to-directory-in-linux/
Unfortunately, this article had me extremely pissed off at Debian 9.
is all that’s required to set up a user + home directory in Debian 9 and CentOS I believe.
This article had me wondering why the “superior” useradd was not creating my home directory.
@Senor,
To create a Sudo User on Debian, first you need log in to your system as the root user and run the following command to create a sudo user.
Next, add the user to the sudo group.
Verify the sudo access.
When I am creating user with another director I am getting this error:
@Madhav,
The easiest solution here, is to create the parent directory structure before calling useradd:
Hii Sir,
After creating an user and setting a password to it, there are so many created users are visible on the terminal. So,how can I get only the one user which I hav been created on the terminal.
@Revathi,
While creating user, you must have specified username on the terminal, for example.
So don’t you remember the user you created?
Hi Ravi. Your suggestion to go directly to the source documentation to understand the requirements and details is an exceedingly excellent one. You have obviously done so, and translated the English it is written in, into whatever your native language is. A link to your interpretation, in your native language would be more helpful than the confusing broken English found here.
Hi Ravi,
I have one problem, from client side I have a request to add a new user with username having space, I mean username of two words.
For example,
@Anuj,
That’s not possible, add underscore or dash, like ravi_gen or ravi-gen.
Hi Ravi, I have a question, If use: su “user” type the password and the system say: su: System Error, why is this message?
Hi Sir,
I have a one question..
How to create a user with custom primary group and then add this user to secondary group in one command, this question asked in interview .
ex: username – techmint
primary group name – linux
secondary group name – admin
@Pramod,
Use following command add a new user to primary group (-g option) and secondary group (-G option).
Thank you. Why you used ‘-m -d‘? Can we use ‘-d’ instead of ‘-m -d‘?
@Saidur,
Yes, you can use only –
d
instead of using-m
-d
options with useradd command.Thank you for your feedback. What is the difference between ‘-d’ and ‘-m -d’option?
Both options
-m
and-d
are same and used for creating a new user’s home directory if it does not exist.Hi, I am new for learning Linux from basic to advanced level I think your blog is best to everyone to learn thanks for providing such a great tutorial and articles.
How to Prevent reuse of UID/GID in SUSE Linux?
The result does not match search criteria right?
[root@tecmint ~]# cat /etc/passwd | grep tecmint
navin:x:999:999::/home/navin:/bin/bash
@Andrea,
Yes, search criteria for user ‘tecmint’ was wrong, but thanks for pointing out, we’ve corrected in the writeup..
I am adding a user “sudo useradd test” in RHEL. I am getting “configuration error – unknown item ‘TMOUT=600;’ (notify administrator)”. But user is getting created. However when I try to login I am unable to login ad test. Any idea why so?
I tried using ‘useradd,’ and no home folder was created, also, when trying to switch from ‘root’ to the new user created, I got the message “No directory, logging in with HOME=/.”
It worked fine until I used ‘adduser’ instead of ‘useradd’. This way the /home/user1 folder was created, and I was able to switch from ‘root’ to ‘user1’ using ‘su – user1’ command.
After all, ‘useradd’ and ‘adduser’ are not as similar as one would think.
Excellent suggestion. I had the exact same issue. This article needs to be modified to reflect this issue. The commands are not the same and they perform different functions.
Very helping article sir please continuous to upload some information about permission on file
@Faiqkhan,
Thanks for finding this article useful, regarding permission management, you should read this article https://www.tecmint.com/file-and-directory-management-in-linux/
Is it possible to have an account that has no shell, not a root account and it has sftp access by using winscp? I’m setting up a linux box with Litespeed so I would like to have a locked down account that only used for uploading and running the server service.
@Daniel,
Try this article, might be helpful to based on your requirements https://www.tecmint.com/restrict-sftp-user-home-directories-using-chroot/
@Ravi Saive: I suggest you add the command to remove user
@James,
Here is the guide on ‘userdel’ command, hope this is what you looking for..
https://www.tecmint.com/delete-remove-a-user-account-with-home-directory-in-linux/
how to create multiple users with same home directory .
like we have 5 user test1, test2,test3,test4,test5 and share with same home directory like /home/job .
condition :- user should have not have own directory they will access only /home/job.
please guide how can we create ???
@Anshoo,
First create a shared directory, for example /home/shared and give appropriate permissions to this folder so that all users can able to edit or write to this directory. Next add new users to this directory with the help of following command.
Maybe I overlooked something but in what cases do you create a user with no shell?
@Gabe,
There are many reasons to disable shell access to a user, for example FTP uploads, samba share users, nfs share users, etc.
how to create bulk user in linux ?
We can create Linux user without password, using following command.
the above command is not working for login without password.
On my system (Ubuntu 14.04) I need to specify the command line switch “-m” in order to get the useradd command to automatically create the required home directory. Otherwise the useradd command creates the user, with the required home directory listed in their user properties, but doesn’t actually create the physical directory entry. Same with use of “-d” switch for a non-standard home directory.
Thought you might like to add this to your tutorial. Ta.
@Sarlacii,
Thanks for the tip, let me check it if it works that way will surely add it to the article as suggested…
useradd -d /data/projetcs anusha ……………….. when i am trying to add a user with different home directory…this command is working for me…
its show an error “cannot create directory /data/projects” .. please help me out asap ..
sorry not working for mr.. i am using rhel 7.0
@Tarun,
Could you please tell us clearly what not working for you?
@Tarun,
I just tried the same command in my CentOS 7 box and the command worked for me without any error, I hope you’re running the command as root..
Is it possible to specify/limit the size of particular user’s home directory.
for example : create a user “abc”, then /home/abc should be allowed to store only 5GB(not more than that).
@Rajesh,
Yes it’s possible in Linux, here you should use quota system..
Hi
How do I add multiple users at once, not necessarily in a group?
@Angie,
Not possible, you have to create one by one..
Hi Ravi,
I had similar query as Angie, I tried to add 4 users one by one in a group.
however, when tried to see output of below it still show user added at first.
cat /etc/group | grep xyz
out I am expecting is
xyz:: 111: user1, user2,user3,user4
however, result I am getting as below
xyz:111: user1
kindly suggest
1 – create a file where all users are in there. Something like a list
2 – cat it, then use xargs. Something like
~]# cat user.lst | xargs -i useradd {}
With the same concept you can set password as well.
Cheers
Is there a useradd -e command that makes the user change their password after they have logged in for the first time?
Hi Bill,
You can also try this. First change user’s password then run chage -d 0 username. Here -d will set days left for password expire to 0. So as soon as user enter his or her password it will prompt to change the password.
Hello,
I created a new user and I want to set for it just some commands to run ( eg. create to db, add a column, etc.) . How I do that? Thanks a lot!
how can i find particular user full name in linux?? i mean which username assigned to which user in the company .?
Without using usermod, how can you add a user, leaving the default group, but also add an additional group:
useradd -m -g username -G additonalgroup username
…this doesn’t work, and complains that username group doesn’t exit yet
useradd -m -G additionalgroup username
…this doesn’t work, as it doesn’t add them to their default username group
Can’t seem to find the proper syntax.
Huge help! Well presented, thanks for making this process understandable!
Great article!! Very helpful!!
Hello Sir,
When we simply add any user by useradd it automatically create directory under /home, or we also can define it by giving path to particular folder for that users home directory.
But when i add new user i want to change users home directory permanently to other location by default .
so is there any configuration file where it is define about users default path for create home directory.
example i’ve added user “test” then it create directory by default under “/home/test” coz somewhere it is defined that.
but i want that configuration file so i can change default path for home directory.
also when i add domain user in Active Directory it also goes under /home/
i also want to change that home directory location.
so please if u have any idea plz reply asap. Thnx .. :))
@Mori,
Just use the -d (defines home directory for user) option along with useradd command to create a new user with specified directory path. I’ve already showed about that -d option in the article, just read carefully…all options of useradd command in the article.
Proper Explanation by executing each command.
@Ruchi,
Thanks for such kind words….we will continue to write and such great articles for our readers like you..keep connected…:)
hello people and what is all the command beginning with –
what is the best linux operating system
@Rufus,
For newbies, I suggest Fedora, Ubuntu, Zorin OS or Linux Mint, for experts CentOS, RHEL, Debian, Arch or Gentoo..Now its upto you what to choose..
were do you find all of the letters with hiphens
@Rufus,
Go through the man pages of useradd command you will know…
How do I create a user which can work on his home directory only? The user is should be restricted to change directory or access other files accept his home directory.
@Supal Choudhary,
The following command will help you to achieve your goal.
“However, this action can be changed by using ‘-d‘ option along with the location of new home directory (i.e. /data/projects). For example, the following command will create a user ‘anusha‘ with a home directory ‘/data/projects‘.”
“However, this behavior can be overriden by using the -d option followed by the full path for the desired new home directory (which need not be in /home). For example, the following would create a new user named jim with a home directory /home/james:”
Come on, this post is just a copy of http://www.linfo.org/useradd.html (a copyrighted source), paraphrased just enough that it’s difficult to google the similarities. If this is a paid piece, I believe there’s some attribution missing, and that’s being /very/ kind.
@Fidning,
Yes, you’re absolutely right, we’ve taken few examples from that site..
Awesome Article dear…
Captured all possible options. You just saved my time in search of other articles on this.
Hi,
I want to create a 3 different type of user with below privilege in Sun Solaris and Linux platform.
1) read only
2) read and write only
3) admin
Can you help on this. How I do the same.
@Naveen,
You can’t create users in your own way..in Linux every user created with default permissions, you need to play with these permissions to achieve your goals.
Great post. Thanks.
Can you please let me know how to land on # prompt instead of $ prompt when logged in as non-root user.
Just use ‘su -‘ command to become root user.
very nicely described…Ravi
ple let me know the command for set all user(who store in one group ) password at one time .
Awesome article!
Thanks for sharing!
Keep writing buddy :)
The beginning of the guide is wrong. I’ve never used a linux system where useradd and adduser were the same. They are different programs!
In fact that is always something annoying I have to check, since I cant remember which one I want when I finally want to add a user. (maybe 1-2 times a year)
Systems and
networks
Q1:
Create a shell script named
scriptadduser.sh
which will take
a name or names of
users on command line along with script itself, and add a user and a home directory for
the use
how to solve this quation pls fast
Dear Pooja,
Your question is not clear to me, can you explain more clearly..
Dear ,
Could you please explain me why it is needed to create a system account and why the need to change the login shell to usr/sbin/nologin.
Please reply.
very nicely described .. i am a Java developer .. need to work with some RPM stuff and know about Linux user management . This article helped me to understand the concept very clearly. Thanks a ton ..friend .. keep doing the good work ..cheers .
WARNING: useradd -G [group1,group2,group3…] will replace ALL existing groups the user is a member of, with the groups specified
What you probably want to use is:
useradd -a -G [group1, group2, group3…]
-a or –append does exactly that. Without it, the default behaviour is to replace all group membership.
It’s amazing that so few sites documenting how to add users to a group mention this fact… I just had to boot in to recovery mode to fix my login, as I accidentally removed my account from the ‘sudo’ group (along with all other groups). I hope this saves just one user from yelling at their computer ;)
The article is very clear and precise and good article to freshers and hope in comming days more posts to see from you ..:)
Siva, thanks for such words, yes we are in process of providing such useful articles to our fellow readers like you. Stay tuned for such more awesome articles.
Hi Ravi,
Really very useful introduction with nice helpful examples.
Hope to see more from you soon.
Thank you for sharing your knowledge with us and giving us chance to learn from your experience.
Best regards
Hi Ravi,
Very nice article.
Hi,
Kindly explain me if we create a user by useradd ,, will it create a group automatically in the name of the user itself ??
example :
#useradd -d /ebiz/raja raja — now there will be a directory created under /ebiz mount point as raja
#passed raja – creates password thats it,,
now explain me the above mentioned user has its own GROUP as the username ???
I wanted to create a group and wanted to add some users into that with their own folder ,, how to do that,,
Some one explain me
Yes, when creating a user with useradd command the group also created with the same username. You can use -G or -g option to add uses to groups.
HI Ravi,
Your article is very good. I have a question on user’s
Q) How to check when the user was created? ( Date and time)
Thanks in advance.
Awesome article thank you very much for this post.
I really liked your articles and it’s easy to understand . Please post many :)
Seems to me that articles like this are what scare people away from Linux. I know commands are useful, and use many myself. Yet I have yet to use a Linux OS that would not let me add a user through the GUI. Maybe that should be explained first, then on to commands. I know the terminal and command line kept me from using Linux for years. Once I found out how easy things now are, exclusive Linux user for 2 years.
Here is a wonderful tutorial on VI. Starters will love it. Commands practically illustrated.
https://www.udemy.com/vi-editor-increase-your-productivity-on-linux-and-unix/?instructorPreviewMode=guest
Nice article but one nit. The password is not stored in encrypted form in the /etc/shadow file. That implies the password could be recovered if one knew the key. Instead, a hash is made of the password and it is the hash that is stored. It is all but impossible to recover the password from the hash value and highly improbable that one could find an alternate password that would have the same hash.
Even if one did not have access, let alone root access, getting any password, even root is simple. An easy exploitation, whether it be physical starting with nmap, or social, starting with looking for users on the website if the company has one can have one running…
# cat /etc/shadow
… in no time. From there it is a simple matter of copying the hashed line for the specific user, realizing that root starts at 0, and running john the ripper or hydra on it. Most high school kids could do this these days I would guess.