The main command for creating users is useradd.
If you're on Ubuntu, it's important to use userad m because on Ubuntu users do not get
a home directory by default. And really you want your users to have a home directory.
So don't forget the m option on Ubuntu.
You will also find that alternative commands are available instead of useradd. There's also add user.
But I would advise you focus on one command. Why would you want to learn about different commands to do the exact same thing?
When users are created default settings from the file etc login.devs are applied and if login.devs
file is an important file, you should consider changing settings in it before creating the users.
And that is because once you have changed settings, they won't be applied for existing users.
You can also use userad D to get an overview of currently effective default settings.
Let me show you how to use all of this.
Let's start with the sudo useradd d where we can see some of the default settings.
So what are these default settings? So that is actually funny. Group is 100.
That is not true Shell has been bashed. That is true. Skel is etc skelled that is also true.
This etc skel is a sk directory and the contents of
the skeleton directory will be copied into the user home directory.
Much more important than the output of user AT
D is the contents of this file etclogin devs.
There you will find login definitions.
Notice that many items in the file show as not supported.
That is because behind user configuration there's a more advanced system with the name pam. As spam
is taking care of things, then the functionality is taken out of the etc login devs.
So as you can see there's a lot of not supported. But if you scroll
down a little bit right here we do see some parameters that are important.
Pass max days. That is definitely a value that you want to change.
Because if a user password is set, then the user password according to this value
is valid for 99,999 days. For your information, that is that's about 272 years.
I think that's too much.
So change that to 99 to make it a little bit more secure.
There are other parameters as well, like the userid max and the gid max
and min which is identifying where user IDs and group IDs should be starting.
Let's not do that right now. Let's just keep it as it is.
And add a user. User add Anna and oh boy, does that make sense. Of course
that makes sense, because we want to add a user and that requires super user privileges.
Now this creates user Anna and if any relevant values were changed in the etc login.dev they will be applied as well.
Honestly, I didn't change any relevant values, but I can show you sudo
passwd anna and then I'm going to enter the new password twice.
And now I'm going to use sudo till minus 55 on
etc shadow. That's the file where user passwords are stored.
Now what do we see? We see for lynda there is
a value of 99,999. For Anna there's a value of 99.
This is the maximum password validity that I just changed in etc login.devs.