[Intro Music]
Let's guys now talk about
permissions. And I'll explain you
what is permission, and how to
modify permissions for a particular
file or directory. And for example,
here in this output for this file
'3.txt', you see that
owner of this file is 'bogdan',
and group is 'bogdan', and
here are permissions. First '-' means
that here you see file. Next, three
characters stand for permissions
for particular user, in this
case owner of the file, owner is
'bogdan'. Next three characters
stand for permissions for other
users in the same group, in this
case group is 'bogdan'. And
finally, three last characters
stand for permissions for all
remaining users that don't belong
to this particular group. That's
our permissions. Great. Let's now
quickly clean up this home
directory for this particular user
that we have created before, and
let me remove those two files,
1.txt, and 2.txt, and this
folder 'tmp'; and I'll do that under
'bogdan' account. And I will be
able to do so because now I'm owner
of those files, here you see 'bogdan'
everywhere. Great. Let's use
'rm' command. 'rm 1.txt',
'rm 2.txt', and 'rm -r',
recursive, 'tmp'. Actually, I was able
to use just a single 'rm' command
with multiple arguments. Type simply
'rm -r tmp 1.txt 2.txt'.
Alright, now
I don't have any unnecessary files
here in home directory for this
user, and I see only some hidden
files. Great. Now let's go back to
root account and create new
file in home directory for this
'bogdan' user. Let's go out of here and
here as the root user, let's 'touch',
new file in the '/home/bogdan'; and
let's name it 'new-file.txt',
like so. And of course owner of
this file will be now 'root' user. Let's
verify that. Yes, here it is, 'root'
is owner of this file, and here are
permissions for this file. Only
owner of this file is able to write
this file to modify it. Great. Now
let me demonstrate you how you are
able to modify permissions for this
particular 'new-file.txt'
And recap that if you will try to
write this file under other user, for
example 'bogdan', you will
definitely get an error, file is not
writeable. Because of those
permissions, it is not possible to
write or execute this file by any
other user that doesn't belong to
'root' group. Before modifying
permissions, let me explain you how
permissions are actually
represented. Again, there are three
different blocks. Here's first
block with three characters, here's
second block three characters, and
last block with three characters.
And actually, we're able to
represent every block with three
characters using binary format,
with zeros and ones. And for
example, if I want to represent
these three characters, I could
simply type 1, 1, and 0; read,
write, and not execute. I could
represent those three characters
using such combination 100. 1 stands
for allow read, 0 stands for deny
write, and this 0 stands for
deny execution. Three different
binary numbers 0 and 1. And
now let's try to convert those
three binary numbers into decimal
format. Do you know how to convert
a binary number to decimal number?
It is very simple. In this case, we
need to do add powers of two
multiplied by 0 or 1. Let me
show you. In this case formula will
be following 1 multiplied by 2
to power of 2, plus 0
multiplied by 2 to power of 1,
plus 0 multiplied by 2 to
power of 0 like so. And in this
case, we will get 4. 4 is
decimal representation of this
binary number 100. Actually, you
are able to use any online
converter that will convert the
binary to decimal for you. Let's
quickly find such kind of converter
binary to decimal. And here, let's
open up, for example, this link,
'Binary to Decimal Converter'.
Let's enter here 100, and press
Convert, and I get 4, decimal
number. Great. This is how you're
able to convert binary numbers to
decimal numbers. Now task for you,
please try to convert to decimal
number, this representation, read,
write and not execute. I wish you good luck.
[Clock Ticking]
All right, done. Let's
do that together. And let me
actually remove this formula, and
read, write and not execute is
actually represented like 110,
and it will be equal to
1 multiplied to 2 to power of
2, plus 1 multiplied by 2 to
power of 1, and plus 0
multiplied by 2 to power of 0,
like so. And the result will be
actually 4 plus 2, equal to
6. Great. And if there are all
ones, I mean, read, write and
execute, then result will be equal
to 7, Let me modify it here, 7;
here will be 1, and here will be
1. And it is actually read, write
and execute, 'rwx', like so. So you need
to convert this representation into
binary representation, and
afterwards to decimal. And actually
there are most popular combinations
like a read, 'r', '-', '-' read,
write, -, 'rw-'; and read write and
execute, 'rwx'. And corresponding decimal
numbers are 7, stands for read,
write and execute. Let me quickly
write it down here. I'll remove
this part. So read, write, and
execute, 'rwx' stands for 7, read,
write and not execute, 'rw-', stands
for 6. And read and
not write and not execute, 'r--', is
actually 4, like so. Those are
most popular numbers, decimal
numbers for permissions. And now
let me show you how using this
knowledge, we are able to modify
permissions for a specific file.
Let's remove this part. And here
for modification of permissions, we
will use command 'chmod', like
this; and next we could supply
number as a first argument; and
let's type here number, let's say
000; and here, let's type path to
the file we want to change
permissions, '/home/bogdan/new-file'
like this. Let's press Enter. And
now let's list contents of the '/home
/bogdan' user. And now I see
following permissions. Because 0
in decimal represents 000 in binary
format. That's why now there are
actually empty permissions. And we
are not able to read, write or
execute this new-file.txt. Let's
now modify permissions to following.
Change mode, 'chmod'; and here will be, let's
say 400. Press Enter. Let's verify
settings now. And now I see that it
is possible to read this file only
by owner of this file. Great. Let's
modify permissions again. And now
here I'll set permission 700. That
stands for read, write, and execute
for a particular user, but no other
permissions for other users. And now
let's verify it. And actually now
you see that permissions were
changed to read write and execute
and color of the file was changed
as well. And the reason for that is
that I have just made this file
executable; and all executable files
in bash shell will be marked with
green color like you see here.
Great. Now task for you. Please
modify permissions for this file,
and make it executable, writeable,
and readable for owner; and readable
and executable for remaining users
in group and for other users in
other groups. All right. Throws
let's try to write the permissions
we want to assign to this new-file.
in text format. So, permissions will
be following - read, write, execute by
owner; read, not write, and execute by
all other users in group; and read,
not write and execute by all
remaining users in other groups. And
we already know that this section
is represented by number 7 in
decimal format. We have just used
this number here, and we have not
yet calculated this section. And if
I represent this section in binary
format, I will get 101, where this
1 is four in decimal, and this
1 is 1 in decimal, 4 +
1, 4 + 1 is equal to
5. And that is the permission
for all other users in group, and
for all other users in other
groups. It means that final command
will be 755, like this. Let's
verify that. Let's list files
and folders here. And now I see
desired result. Now this new-file.txt
is writeable, readable
and executable by owner; and only
readable and executable by all
remaining users. And if you want to
set full permissions, you need to
type here 777 likes so. Great. This
is how you're able to modify
permissions using decimal
representation. Also, you're able
to add some permissions, and to
remove some permissions using the
following syntax. Let me show you.
Let's go back to this command; and
here instead of three 7s, I'll
write following, '-x'. Let's
press Enter. And now let's verify
what was changed for permissions.
And now I see that execution
permission was removed from all
three parts, here, here, and here. That's
what this '-x' does. It has
removed execution permissions for a
particular file. All right, let's
try to go back to this command; and
instead of '-x', let's use '+x',
like so. And let's have a look
again at the settings. And now I
see that 'x' was added again
everywhere. All right, you are also
able to remove or add some
permissions for particular groups.
For example, if you want to remove
execution permission only for
group, you could use following
command. Let's go back here. And
here will be 'g', then will be minus,
and x; 'g-x' for group remove
execution permission. Let's verify it.
And now I see that 'x' was removed
here in group part. All right,
let's now try to remove also read
access for group users. And here
will be 'g-r', let's try that.
List, and now I see that 'r' was
removed here as well for group
users. That's how you could very
quickly add or remove some
permissions if you want to. But I
personally usually use decimal
numbers like 777, or 700, or 755,
that are most commonly used.
Alright, that's all for
permissions. And that's how you're
able to modify permissions for
specific files. And actually, now
we see that this new-file.txt
is writeable and executable by
all users. And let's actually now
quickly verify that. Let's change
user to 'bogdan', list files here. I
see new-file.txt here in this list.
And now let's try to modify it, 'nano
new-file.txt. And yes, I'm able
to modify it. Because now
permissions are lowered. That's
what permissions do. And that's how
you're able to modify permissions.
And that's what actually will be
changed when you modify
permissions. But my personal
recommendation to you is to be very
careful with permissions. And don't
assign very broad permissions that
we'll make some files readable,
writable and executable by all the
users in the systems. Please assign
only necessary permissions that
you really need. Alright, that's
all for this lecture. And in the
next one, I'll tell you how to
create executable shell script
using Terminal. I'll see you in the
next lecture. Bye-Bye.
[no audio]