All right, Now let me demonstrate you how you could create a new user, and I will do that as root
user in Ubuntu Docker container.
Please notice that if you want to create new users, you need to have root access to the system and
if you are root user you are good to go and you are able to create any other users.
If you are logged in as a regular user, you need to prepend commands that we will use here in this
lecture and next lectures with sudo.
And when you enter any command with sudo prefix you will be asked for root password.
And if you don't have access to root password, of course you will not be able to perform such actions
as creation of new users.
All right.
You are able to create new users using two different commands either user add or add user.
And first, let's have a quick look at help for those both commands.
User add Dash Dash help.
And here you see different options that could be used along with this command.
And you see that the this command is used for creation of the new user.
And here in place of login, you need to enter new username for the user you want to add.
Let's have a look at Add user command, clear terminal, add user dash dash help and here is a help
page for Add user command and for example, with such option as dash dash home, you are able to set
custom home directory for specific new user and here as user you should enter any username that will
be used for creation of the new user.
All right, I'll show you both commands in action.
And let me start with user add command.
Let me clear a terminal and enter user add.
And next let me enter my name as username user add mock done.
And you see that actually nothing happened.
I saw no prompts and it seems that new user was created.
Let me now try to login as Bogdan user and you are able to log in as other user if you are already logged
in as for example, root user.
And for that you could use command as u this one and next you could type simply username you want to
log in with as you Bogdan and notice that I was logged into other shell and actually now you see Shell
as root user.
I was logged in into the bash shell and from that bash shell I was logged into shell for Bogdan user
And if I enter here, who am I?
I see.
Bogdan And that means that now I'm logged in as Bogdan User.
But let's have a look at the contents of the folder.
I'm currently in LHS, and here I see error permission denied.
If I enter W, I see that I'm still in the root folder, but you could remember that this folder is
actually home directory for root user and this folder has read, write and execute permissions only
for root user.
And if I enter LHS and here type slash, you'll see this information here on this line root folder can
be accessed only by root user.
That's why if I try to access it here as Bogdan user, I'll get permission error and that's fully correct.
All right.
That's how I was able to log into the shell using different user.
But let's try to list contents of the home directory.
I have told you that each user should have home directory.
Let's enter LHS slash home and here I see actually no other subfolders.
And that means that no home directory was created for this new user.
Bogdan And if you want to create new home directory, you need to perform additional action.
Also, this user does not have any password set and if you will try to access this computer remotely
and login as Bogdan user, you will not be able to do so because there was no password for this user.
Now let's go back to root user and if you want to exit from current session for Bogdan user, you need
to enter simply exit.
And now I'm back to bash shell for root user.
All right next command that you need to use if you want to set up a password for specific user is pass
WD and next comes username Bogdan and here I could set new password for specific user.
Let me set something random.
One, two, three.
Here, I'll retype one two, three and password was updated successfully and now I will be able to log
in as regular Bogdan user using this password that I have just configured.
Let's now again try to log in as Bogdan user by typing as you Bogdan and you see that I was not asked
for any password and the reason for that is that I'm already logged into the system as root user and
that's why there is no need to ask for password for other user.
All right.
That's how we were able to set password for a specific new user.
But there is still no home directory for this user.
Let me show you how you could create new user with Home directory.
And first, let's simply remove this user that we have just created and for that use following command
user del.
And next comes username.
User was removed and now let's create the same user back again, but with another option that will automatically
create a new home directory for this user.
Let's type user, add dash, dash help and let's look for option that will create home directory.
And actually I'm able to filter this output using pipe operator and here will be grab command.
We have already discussed this command before and here type home like so.
And you see that with dash D option you are able to set specific home directory or you are able to use
dash m option that will create home directory automatically in the slash home directory.
Let's use dash m option.
Let's clear terminal user add dash m and next comes username back down again.
And now let's list contents of the home folder.
And now you see new sub folder that was created here automatically and name matches user name for this
user that we have just created.
Let's list contents of this bag down folder and let's add here options Dash LA in order to see hidden
files and see results in table format.
And now I see that there are three hidden files.
Bash log out, bash, RC and profile.
And those files were created automatically for this particular user.
But now question how Linux system decides which shell specific user should use by default.
Let me show you how E-t-c default user add.
There is such file located in default directory.
Let's have a look actually at this file using cut command and you'll see set of default options that
are used for creation of the new user.
When you enter user add command and if you scroll up a bit, you'll see such variable that is set to
bin.
And that actually indicates the default shell that will be used for new users that you create using
user add command and you are able actually adjust this default configuration file, you are able to
uncomment some sections, you are able to add additional parameters, you are able to modify existing
parameters and so on.
And let's actually try to modify this file and adjust shell to bin bash and afterwards let's try to
create new user.
But first let's log in as Bogdan user and ensure that we will be logged in into the shell Let's clear
terminal and enter as log Bogdan And you see here that I'm logged in into the shell as Bogdan user and
we are able to verify which shell we are currently using by entering a command echo dollar sign zero
And here I see.
All right.
Let's now try to create new user under this session.
Let's try to enter user ID and for example, let's create new user called test.
And here I see error permission denied.
And the reason for that is that I'm trying to create new user from regular user session.
And I have told you before that if you want to create new users, you need to have root privileges.
And if you try to do so as regular user, you will get definitely an error.
All right, let's exit from this session.
And now let's modify configuration file for user add command.
Let's use Nano Editor Nano here type path to this configuration file.
It is located in EDC.
I'll use absolute path next default and here will be user add like this.
And let's modify this line.
Shell will be bin bash like so let's save changes.
Control X yes.
Enter and let's read the contents of this file in order to verify that changes were saved.
And let's scroll up here.
And yes, here is this change.
Shell is set to bin bash.
All right.
Let's now create one more user.
And again, I'll use option M that will automatically create new home directory for this new user.
And afterwards we will try to log in as new user.
Let's enter user Add.
Next comes option and afterwards let's enter username test.
We will create new user with username test.
Let's press enter and now let's use as test.
And now you see that I'm inside of the bash shell.
Let's type echo dollar sign zero and you see bash.
And notice that if you use as command without any other options, then current working directory will
remain unchanged.
Notice that here I was inside of the home directory for root user, it is slash root and when I have
changed user I still remain in this folder slash root.
And if you don't want such behavior you need to use additional option with as command.
Let me show you that.
Let's exit from here and type dash, dash, help.
And here you will see this option on this line.
You could either use simply dash or dash l or dash dash login.
And with this option you will be logged into new session completely from scratch as new user.
Let me show you that as dash and here type username test and you'll see that I have changed user to
test and now I'm inside of the home directory for this test user and if I enter PWD you'll see path
to home directory for test user.
It is slash home slash test.
Same applies to other users.
For example, let's exit from here and as you dash and here type Bogdan username and now I'm actually
in the shell.
But if I enter PWD you'll see same picture.
I'm inside of the home directory for this particular user.
That's what this option dash or dash L does.
All right.
That's how you could create new users using user add command.
And with such option as you are able to automatically create new home directory for specific user.
Great.
Let's exit from here and let's use user command in order to remove Bogdan user and let's verify whether
home directory for this user is still in place or not.
Let's list files in Home directory and yes, I still see here Bogdan Subfolder and that means that user
Del Command without any additional options does not remove home directory for specific user.
Let's have a look at the help options for user del Command User del Dash.
Dash Help.
And here in list of those options, you'll see option dash R that will automatically remove home directory
for a specific user.
Let's use this option in order to remove test user.
Let's enter user Dell dash r test.
You see warning that the test mail spool wasn't found.
Just ignore it.
Let's list the contents of the home directory now and don't see test sub folder here in this home folder.
Let's also remove manually this sub folder.
Let's use rm dash r slash home slash Bogdan enter.
Let's list contents of the home directory.
And now it is empty.
All right.
That's how you could create a new users using user add command with another command pass WD you are
able to set password or modify it if it is already set for a particular user and using user del command
you are able to remove created user.
Let's now proceed and next let me show you another command add user.
It is slightly different from user add command, but just with single command you are able to set home
directory password and other options if you want to do so.
Let's talk about it in the next lecture.
Bye bye.