Create user in Linux using useradd command in linux with flags | Examples
![]() |
Create user in Linux |
Hello, guys welcome to the next session on Linux command line tutorial. In this session, you will learn how to use "useradd command" create users in Linux.
To create a "user" we can use a command called "useradd" and with this command, you can use some flags and the user name to create a user.
create user [sudo useradd]
![]() |
useradd command |
$sudo useradd [user Name]
You just need to type "sudo useradd name of the user". The name of the user can be anything.
Creating a password
![]() |
Create a password using the "passwd" command |
$sudo passwd [user Name]
You haven't provided any "password" to this user. So whenever this user wants to log in.
He/She will login with the "username" and the "password". But we haven't provided any passwords here.
When you give this command as it is then it will allow you to change the "password" for the root user.
When you use this command with the userName then this will allow me to change the password of that specific user.
And then you need to use "sudo" command because you may have to give the root access in order to change the password of the user.
Important flags in useradd command
[-m] flag
![]() |
(-m) flag with useradd |
- What this flag is going to do is it's going to create a "default home directory" for this user.
[-s] flag
![]() |
(-s) flag with useradd |
- "-s" is the flag for the "default shell"
- So this "-s" flag is used for allowing the "user" to use the shell. Whatever you provide after this flag.
[-g] flag
![]() |
(-g) flag with useradd |
- "-g" this flag is the "default user" flag.
- After this flag whatever user you type the user will be assigned that group.
- So the default group is "users" and I would recommend that you always use the "-g" flag.
[-c] flag
![]() |
(-c) flag with useradd |
- "-c" flag is for providing the "comments".
- You can provide any comments here for this user.
Conclusion
HAVE A NICE DAY💕