If you're going to have a modern operating system today you're going to have to have a file and folder
permissions.
And certainly Linux is no exception to that rule.
So in this episode what I want to do is go through linux file and folder permissions and then show you
how we can edit those.
So the best way to get started with this is to die than go into a particular folder and just type LS
minus L.
So if you take a look here on the far left hand side we see all these letters and dashes and that's
really where all the file permission magic takes place.
As you look at this on the far left hand side you're going to see one that has the letter D.
That means it's a directory so that very first value.
I just want you to just ignore it for this episode that's just used to separate files from directories
from links and other stuff like that.
What's important are the next nine values.
So if you take a look here you're going to see individual files have ours and W's and X's and dashes
in different places depending on what's happening here.
Those are the file and folder permissions.
Now to get started on this I want to explain to you how they're organized.
And I'm going to have to wait just a minute then I'm going to tell you what our you x means so bear
with me.
You have three groups of these R.W. exes.
So if we zero in for example down in this bottom five right here called Run me you'll see I have r w
x R W x R W x.
What you're looking at here are three different permissions depending on the entity that you want to
apply permissions to.
The first three values are the permissions that are applied to the creator owner whoever created that
file whoever created that directory usually has very powerful permissions on it.
And that's what the creator owner can do.
The second set in the middle there is for the group every file and folder in a Linux system belongs
to a group and other users can be in that group.
And you can define the permissions for everybody in that group for that particular file or folder simply
by editing those three letters right there.
Now if you're not the creator owner and if you're not in the group well then what permissions do you
get.
And that's what that third set is for.
The third set defines permissions for everybody else.
The rest of the world the universe whatever you might want to look at that as.
So we break it up into these three very distinct groups.
OK now let's go back in.
Except this time I want to take a moment and talk about what exactly are and W and X mean it's going
to vary depending on whether these permissions are applied to a file or to a directory.
R stands for read a readable permission allows the contents of a file to be viewed in other words you
can open a file read permission on a directory allows you to list the contents of that directory right.
Permission allows you to modify the contents of a file but the right permission for a directory allows
you to edit the contents of that directory which is a nice way of saying you can add or delete files
from that particular directory.
Executes a little bit strange for a file it makes sense.
The executable permission allows you to run the file and execute a program or a script for a directory
though the execute permission allows you to change to a different directory and make it your current
working directory.
So if you want to get out of a particular directory and go someplace else make sure it's executable
for your particular user owner group or other.
The tool we use in Linux to change file and folder permissions is called chmod.
Now chmod is an interesting command and there's a couple of different ways to run it.
And since I don't know how come t is going to tell you how to do it.
We're going to try it both ways.
So first of all what we're going to do is we're going to use chmod to change some permissions on one
particular file a little executable program called Run me.
Now run me is a very dangerous program so I want to be very specific about who can actually run this
particular program.
So I've got my Ls minus l running and you can see right now anybody can execute this program and see
all three x's.
So the creator owner the group and the others can all run this.
So the first thing I am going to do tomorrow is I want to give the other people no rights to do anything
on this thing so to do that I'm going to type in chmod and now I'm going to start typing in some switches.
The switches here are either are going to be a letter followed by an equal sign and then the permissions
I want.
So in this particular case I'm going to say over other equals and I'm going to leave it blank which
means turn off all permissions for the other people.
And then obviously I'm going to type in the name of the file.
So I run this and now you can see if you take a close look you'll see that the other group has absolutely
no rights to this is somebody who isn't the creator owner or member of the group tries to execute this
program.
It's not going to happen.
They don't have permissions.
Now the other thing I want to do is I want to take a look and we can see the group has read right next.
Q permissions since it's really just an executable file.
There's really no reason to write to it.
So what I'm going to do in this case is I'm going to turn off right permissions for the group.
So again I type in chmod and now this time I type G for group and here all I want them to have is read
and execute permissions.
And then once again typing in the name of the file so I typed LS minus ELP and you can see that I've
got rid of the right permissions so you can do a lot of cool stuff with this.
Now there's one more chmod type command I want to show you in this version to run.
And that means when you want to do it to everybody let's just say I'm feeling crazy and I want to give
everybody rights to do everything they want to do.
So in that case I'm going to run chmod and I'm going to use a.
That means everybody creator owner group and other and easy I'm typing in a equals R W X so that means
give everybody all the permissions run make
me type.
LS might well and you can see that I've put back all of the missions for that particular one.
So that's one way to run Tramon.
Now there is a whole other way to run it which is a little bit more old school and guys like me like
to use.
So I want to run Chimay one more time but this time what we're going to do is we're going to use numbers
instead of letters to change things.
Now in order for you to understand these numbers keep in mind that we have three values read write and
execute.
So in a binary world the read is in a four position.
The right is in a two position and the execute is in a one position.
So to explain that a little bit better let me put a little graphic up so that you can correlate the
positions of those three values to binary values.
Take a look at this.
So we know that every linux file has read write and execute permissions for the creator owner the group
and then the rest of the world.
Now we've seen chmod used one way but let me show you this other way.
So first thing I want to do is let's just pick on any one of these three so we'll just pick this one
that's as good as anting.
Now we understand that setting a permission basically turns it on or off.
So there is kind of a binary thing to this if you think about this for a minute like for example we
could turn off the read permission we could turn off the right permission and just turn on the execute
permission.
Equally we could turn on the read and the right permission and turn on the exit turn off the execute
permission or we could turn on all of these permissions so really what you've got is three binary digits
that we can convert to decimal Let's go ahead and go through all this real quick so all zeros and binary
equals zero in decimal 0 0 1 equals 1 in decimal 0 1 0 equals 2 in decimal 0 1 1 equals 3.
Here I'll just keep going through the rest of these.
I think you can figure this out.
So basically three binary values can have 1 2 3 4 5 6 7 8 different combinations going from zero to
7 in decimal.
And understanding that we can actually do something really cool with Jamaah to make our lives a lot
easier.
So for example on this particular one if we just want to set this particular one to read only all we
have to do is type in 1 0 0 which is going to equal 4.
So in essence we just say for if we want to set it to just write permission we would say to and if we
want to say execute permission we say one.
So really what it boils down to when you look at read write execute read gets the value of for right
gets the value of two and execute gets the value of one.
And we can use this combination which Hamada do cool things for example.
So if I wanted to set the read permission I would just say four and that would turn off right and execute
if I want to just the right permission.
I would say to if I want to just execute permission I would say 1 but it also works for combinations
if I want the read and right combination it will be a 6.
And if I want everything it's going to be a 7 and we can use that to work with chmod.
So let's go through one quick example of this.
Now keep in mind we have three read write and executes to deal with not just one.
So if I wanted to for example set everybody to read write and execute I would type chmod 7 7 7 and that
would give everybody read right next cue permissions.
But then again if I wanted to give the creator owner complete permission and then I wanted to give the
group just read and write permission.
And then if I wanted to give everybody else no permission at all that would be 7 6 0 OK.
Now that you have a least rough idea of how this works what we're going to do is we're going to use
Tamada again except this time we're just going to use numbers now.
The downside of using Shimada like this is that you've got to be really really comfortable with binary
and well luckily I am but you may not be so.
If there's one thing you might want to rehearse a little bit are using these number of days for Chameides
as opposed to what I think is the well now easier way of just using the letters.
Anyway let's go through an example.
If you take a look up on the screen you'll see that I have this run me right now.
So I'm going to type chmod and I'm going to type in the number 7.
Now think about this for a minute four plus two plus one equals seven.
So if I give a value of seven that means I want read and write and execute the order that I put these
numbers in depends on whether it's for the creator owner the group or other.
So the first value seven means makes your creator owner has read write and execute.
Now it's often common to do the same thing.
So I'm going to type in a second seven so that the group has read write and execute permissions that
the third one I'm going to do is I'm going to put in the number five.
Now with the number five in there now I'm really speculate for a minute.
What permission am I turning off by doing that.
I'll give you a clue.
Seven minus two equals five.
So let's go ahead and run this.
They can see I type chmod and a number and then the actual file that I want to change I hit enter.
Now if I type LS minus L right now if I've done it right there it is.
The w is not in for other.
So what I did by typing a five in that third position as I said turn off right.
Permission for that particular file.
So which my you can have a lot of fun.
In fact you'll see people with Jamaah they'll say chmod 777.
And what they're saying is just turn everything on.
OK.
Now that's Tramon.
So Juds pretty cool.
And I like it.
But what I want to do now is go from dealing with who has what type of file and folder permissions to
who owns a particular file.
And to do that we're going to use tcha own.
OK.
So CHONE simply allows us to change ownership.
Let me show you how that works.
If you take a look at my Ls minus L here you'll see that right now the file run me has student as the
owner.
And what we're going to do right now is we're going to change that to route.
So Joe needs sudo in order to work.
So we're going to type sudo shown and we're going to type in truly want to change ownership to and then
we type in the name of the file.
Now look very carefully here you can see that the owner is now root.
And that's what CHONE is all about.
It's a quick way for you to be able to change the owner of a particular file or folder.
All right.
So we've messed with our file and folder permissions we have changed the ownership.
Now the last thing I want to talk about is changing a password and to do that we use the S S W D command.
Now again this one needs sudo so I'm going to type in pseudo SSW D.
Now right now if I just hit enter it's going to change the password for the account I'm logged in on
currently which is student.
So I'm going to do that.
So I'm going to enter a new Unix password
and I have now changed the password successfully.
So if you need to change a password make sure you know how to use p s s w d.
On the plus objectives they do something very strange here.
They actually in the objectives they put ph s s w d which is change passwords right with the command
P W D which means for just show me the current working directory.
I'm not quite sure why Campania does that but it might be a clue on something you're going to see on
the exam on
in
an.