[Intro Music]
We have just successfully created
new user using another command
called 'adduser'. And this command
is much more convenient for use as
'useradd' command, because it has
interactive prompts, and you're able
to set the Working Directory
password and other settings just in
one command. Great. Now let me
demonstrate you how to change
ownership for a specific file or
directory. And let me create a new
file in home directory for this
'bogdan' user, but under 'root' user
account. Let's go back to root
session, 'exit', and here now I'm
logged in as root user. And now
let's create a new file in the '/home/bogdan'.
Let's use the
touch command 'touch /home
/bogdan', and here will be
filename 2.txt. File was created.
Let's now list contents of the '/home
/bogdan' directory. Let's add here
'-la' options. And now I see new
file 2.txt. But username and
group are set to root because I
have just created this file as a
root user. Now let's change to
'bogdan' user. 'su -bogdan'. Let's
clear terminal. And let's list
contents of home directory here
under 'bogdan' user. And now I
still see here this 2.txt file
that we have just created as root
user. And in those columns, you'll
see this information root and root.
Now let's try to modify this file
2.txt under bogdan's
account. Let's use Nano editor, and
type 2.txt as argument. And
here you will see that file 2.txt
is unwriteable, and that is due
to ownership issue. Owner of this
file is 'root'. And of course, when
you have a look at those
permissions, you'll see that only
owner of this file is able to write
this file, here you see this 'w'. Other
users that are members of this
'root' group or other groups are not
able to write this file. That's why
we are not able to modify it. And
in order to solve this problem,
you're able to either change
permissions, or change ownership of
this file. This file is located in
the home directory for bogdan
user. And logically it's better to
change ownership of this file,
because again, this file is located
in the home directory for 'bogdan'
user. Let's do that. For that
you need to use command 'chown', this
one. Let's first have a look at
help options for this command.
Let's scroll a bit up to the beginning
of this output, and you'll see that
this command is used for change of
the owner and or group for a
specific file or files. And you'll
see that first you need to
specify options, if any.
Afterwards, you need to specify new
owner optionally, and new group
optionally, and afterwards comes
file or files. Let's try that in action.
Let's clear terminal, and type
chown. Next comes user name, we
want to change ownership of the
file to, it will be 'bogdan'; and
next comes file name, 2.txt. Let's
try to enter this command here
under bogdan's account, Enter. And
of course I see here error,
Operation not permitted. Could you
guess what is the reason for this
error? Why I am not able to change
ownership of this file under
Bogdan's account?
[Clock Ticking]
You are right, answer is very simple. We are not
able to modify this file under any
other accounts except only root
account. That's why I need to perform
this action on the root account, and
afterwards go back to bogdan's
account, and then I will be able to
modify this file as owner of this
file. All right, let's go back to
'root' account, exit, and let's type
the same command 'chown bogdan',
but now I need to enter a full path
to this 2.txt file because now
I'm the home directory for root
user. So I am typing here
'/home/bogdan/2.txt'.
And now let's verify whether
ownership was changed. 'ls -
la /home/bogdan'. And yes, I see that
now owner of this file 2.txt
is 'bogdan', but group remained
unchanged, it is still 'root', and
that's probably not what you have
expected. If you want to change
group as well, you need to slightly
modify this command. Let's go back
to this command 'chown bogdan',
and here after ':' you need to
specify group name. It will be
'bogdan'. Let's press Enter. And
now let's verify whether something
was changed here or not. And yes,
now I see User and Group equal to
'bogdan', my username.
Let's now go back to 'bogdan' user
'su -bogdan', and let's have
a look at contents of home
directory. And now I see correct
ownership of this file, 2.txt.
And of course, because now I'm
owner of this file, I am able to
write this file, modify it. Let's
try to modify it, 'nano 2.txt',
'Modified file'. Let's save
changes, 'Ctrl + x', Yes, Enter, and
now file was successfully changed.
Let's have a look at contents of
this file, 'cat 2.txt'; and yes,
I see here contents 'Modified file'.
That's how you're able to modify
ownership for a specific file. In
the same way, you're able to modify
ownership for a specific directory.
Let's quickly do that. And let's
create new directory here in
home folder for bogdan user,
and let's do that again as 'root'
user. Let's go back to root account
and here let's create a new folder
in '/home/bogdan'; and let's name
it 'tmp'. And now if I list the
contents of '/home/bogdan', I will
see this new folder here and the
owner is root and group is root as
well. And let's create a new file
in this 'tmp' folder. Let's actually
'cd' to this tmp folder. I'll copy
this folder name like so. And let's
'touch 3.txt', and 4.txt.
I'll create two new files here
in 'tmp' folder. Here they are. And
of course owner of those files is
root. Alright, let's now try to
modify ownership for entire folder,
'tmp' folder. Let's 'cd' to home
directory for root user, and let's
enter 'chown'; next comes 'bogdan
:bogdan'; and here
will be path to this 'tmp' folder,
'/home/bogdan', and
here will be 'tmp' like so. Let's
press Enter. And now let's list
contents of the '/home/bogdan';
and I'll see the owner of 'tmp'
folder was changed to 'bogdan'. But
if I have a look at contents of the
'tmp' folder, I'll still see owner
'root' for both files, 3.txt
and 4.txt; and that means
that I have just adjusted owner
only of the folder, directory 'tmp';
and ownership of any included files
or subdirectories wasn't changed.
If you want to change also owner of
the inner files, you need to use
additional options. Let's have a
look at the help for 'chown' command.
'chown --help', and scroll a bit
up, and you'll find here option
'-R', or '--recursive';
and with this option in
place, you'll be able to modify
ownership of all inner files and
directories. Let's try to use this
option. Let's clear terminal and
type 'chown'; next comes option this
'-R', capital 'R'; next we will type
username and the group name we
want to change ownership to. And
here will be path to folder we want
to change ownership. Here will be
'/home/bogdan/tmp', like so. Let's
press Enter. And now let's verify
whether file's ownership in this
'tmp' folder was changed or
not? Let me copy this path and 'ls
-la', and paste copied path. And
now I see the owner for those files
3.txt, and 4.txt was
correctly changed to 'bogdan'. And
of course, if I go back to bogdan's
account, 'su - bogdan', and
verify contents of home
directory, and list files and
folders in 'tmp' folder, I'll see
correct ownership everywhere. And
that means that now I'm able to
modify those files, 3.txt
or 4.txt. Let's try that
quickly. 'nano tmp/3.txt'.
Here I'm using relative path
without any slashes. Or I'm
actually able to use such
syntax tilde, '~'; and here will be
'/'; it means that I am accessing
specific file inside of the home
directory of this user. Let's press
Enter, and here add 'Hello', save
changes, Yes, Enter, and now let's
read the contents of this file 'tmp/
3.txt', and I see those
contents here. That's how we have
successfully changed the ownership
for entire directory and all
inner files and directories.
Great. That's all for this lecture.
And now you understand how to
change ownership for specific file,
files, or directories. Next, let's
talk about permissions. And I'll
explain you how to modify
permissions. And I'll actually
demonstrate to you first how to
create executable script in Linux.
And we will create a very basic
simple script that will simply
print 'Hello world' to the terminal
I'll see you in the next lecture,
guys. Bye-Bye.
[no audio]