[Intro Music]
Alright, now let me demonstrate to you
how you could create a new user;
and I will do that as a 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 a 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 the 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 won't 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 'useradd' or 'adduser'.
And first, let's have a quick
look at help for those both
commands. 'useradd --help'.
And here you see different options
that could be used along with this
command. And you see that this
command is used for creation of the
new user. And here in place of
LOGIN, you need to enter new user
name for the user you want to add.
Let's have a look at 'adduser'
command. Clear terminal. 'adduser
--help'. And here is a help page
for 'adduser' command. And for
example, with such option as '--home',
you are able to set
custom home directory for a
specific new user. And here as
USER, you should enter any user
name that will be used for creation
of the new user. Alright, I'll show
you both commands in action. And
let me start with 'useradd' command.
Let me clear terminal; and enter
'useradd'; and next, let me enter my
name as username; 'useradd
bogdan'. 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 'su', this one. And next
you could type simply username
you want to log in with. 'su bogdan'.
And notice that I was logged
into other shell. And actually
now you see 'sh' shell. As a root
user, I was logged in into the bash
shell. And from that bash shell, I
was logged into 'sh' shell for 'bogdan'
user. And if I enter here, 'whoami',
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 'ls'; and here I see
error, 'Permission denied'. If I enter
'pwd', 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 'ls
-la', and here type '/',
you'll see this information here on
this line. A root folder can be
accessed only by root user. That's
why if I try to access it here as
'bogdan' user, I will get permission
error. And that's fully correct.
All right. That's how I was able to
log into the 'sh' shell using
different user. But let's try to
list the contents of the home
directory. I have told you that
each user should have home
directory, let's enter 'ls /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 a new home
directory, you need to perform
additional action. Also, this user
doesn't 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 am back
to bash shell for root user.
Alright, next command that you need
to use if you want to set up a
password for specific user is 'passwd',
and next comes username 'bogdan'.
and here I could set a new
password for a specific user.
Let me set something random '123'.
Here I'll retype '123'; and password
was updated second 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 'su
bogdan'. And you see that I wasn't
asked for any password. And the
reason for that is that I'm already
logged into the system as a
root user, and that's why there was
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
was still no home directory for
this user. Let me show you how you
could create a new user with home
directory. And first, let's simply
remove this user that we have just
created. And for that use following
command, 'userdel', 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 new
home directory for this user. Let's
type 'useradd --help'; and
let's look for options that will
create the home directory. And
actually, I'm able to filter this
output using pipe operator, '|', and here
will be 'grep' command, we have
already discussed this command
before. And here type 'home' like so.
And you see that with '-d'
option, you are able to set
specific home directory, or you are
able to use '-m' option that will
create a home directory
automatically in the '/home'
directory. Let's use '-m' option.
Let's clear terminal, 'useradd
-m'; and next comes username,
'bogdan' again. And now let's
list contents of the '/home' folder.
And now you see new subfolder
that was created here
automatically; and name matches
username for this user that we
have just created. Let's list
contents of this 'bogdan' folder;
and let's add here options '-la'
in order to see hidden files and
see results in table format. And
now I see that there are three
hidden files, '.bash_logout', '.bashrc',
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 'ls /etc/
default/useradd', there is such
file located in '/etc/default'
directory, let's have a look
actually at this file using 'cat'
command, and you'll see a set of
default options that are used for
creation of the new user when you
enter 'useradd' command. And if you
scroll up a bit, you'll see such
variable that is set to '/bin/sh'.
And that actually indicates default
shell that will be used for new
users that you create using 'useradd'
command. And you are able
actually adjust this default
configuration file, you're able to
uncomment some sections, you're
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 be '/bin/bash'; and
afterwards, let's try to create a
new user. But first, let's log in
as 'bogdan' user, and ensure that we
will be logged in into the 'sh' shell.
Let's clear terminal, and enter 'su
bogdan'; and you'll see here that
I'm logged in into the 'sh' shell as
'bogdan' user; and we are able to
verify which shell we are currently
using by entering command 'echo
$0'; and here I see 'sh'.
Alright, let's now try to create a
new user under this session. Let's
try to enter 'useradd'; and for
example, let's create a new user
called 'test'. And here I see error
'Permission denied'. And the reason
for that is that I am trying to
create a new user from a 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 a regular user, you'll get
definitely an error. All right,
let's exit from the session. And
now let's modify configuration file
for 'useradd' command. Let's use
Nano Editor. 'nano', here type a path
to this configuration file. It is
located in '/etc', I'll use absolute
path, next 'default', and here will be
'useradd' like this. And let's
modify this line. 'SHELL' will be
'/bin/bash' like so. Let's save
changes, Ctrl + X, Yes, Enter, and let's
read the contents of this file in
order to verify that the changes were
saved, and let's scroll up here.
And yes, here's this change, 'SHELL'
is set to '/bin/bash'. Alright, let's
now create one more user. And
again, I'll use option '-m', that
will automatically create a new
home directory for this new user.
And afterwards, we will try to log
in as a new user. Let's enter
'useradd'; next comes '-m'
option; and afterwards, let's enter
username, 'test'. We will create a
new user with username 'test'. Let's
press Enter. And now let's use 'su
test'; and now you'll see that I'm
inside of the 'bash' shell. Let's
type 'echo $0', and you
see 'bash'. And notice that if you
use 'su' 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 '/root'; and the when I
have changed user, I still remain
in this folder, '/root'. And if
you don't want such behavior, you
need to use additional option with
'su' command. Let me show you that.
Let's exit from here, and type 'su
--help'; and here you'll see
this option on this line. You
could either use '-', or
'-l', or '--login'; and
with this option, you will be
logged into new session completely
from scratch as a new user. Let me
show you that. 'su -', 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 '/home/test'. Same
applies to other users. For
example, let's exit from here and
'su -', and here type 'bogdan'
username; and now I'm actually in
the 'sh' shell, but if I enter 'pwd'
you'll see the same picture. I'm
inside of the home directory for
this particular user. That's what
this option '-' or '-l' does.
Alright, that's how you could
create new users using 'useradd'
command. And with such option
as '-m', you're able to
automatically create a new home
directory for a specific user.
Great. Let's exit from here; and
let's use a 'userdel' 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' sub folder.
And that means that 'userdel'
command without any additional
options does not remove home
directory for a specific user.
Let's have a look at the help
options for 'userdel' command.
'userdel --help'; and here in
list of those options you see
option '-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 'userdel
-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 I don't see 'test'
subfolder here in this home folder.
Let's also remove manually this sub-
folder. Let's use 'rm -r /home
/bogdan'; Enter; let's
list contents of the '/home' directory;
and now it is empty. Alright, that's
how you would create the new
users using 'useradd' command. With
another command 'passwd' you are
able to set password or modify it
if it is already set for a
particular user. And using 'userdel'
command you are able to remove
created user. Let's now proceed, and
next let me show you another
command 'adduser'. It is slightly
different from 'useradd' command,
but just with single command you're
able to set the home directory,
passwords, and other options if you
want to do so. Let's talk about it
in the next lecture. Bye-Be.
[no audio]