Check out a free preview of the full Complete Intro to Linux and the Command-Line course

The "Permission Shortcuts" Lesson is part of the full, Complete Intro to Linux and the Command-Line course featured in this preview video. Here's what you'd learn in this lesson:

Brian gives an overview of a few numbers used to change permissions such as read, write, or execute through the terminal.


Transcript from the "Permission Shortcuts" Lesson

>> So let's touch another file here, file.txt. Something you'll see people do is they'll say sudo chmod, and then you'll see 777, which is super random, I understand that but let's talk about 777. I'm not encouraging you to do it this way. I'm just going to tell you that you're going to find a lot of stack overflow answers that have people that tell you that yeah, just to put 777 there.

It's a very shorthand way of doing what I showed you before, which is u equals rgw or was it, rwx, g equals rwx, o equals rwx. These two lines are totally equivalent. So what this number represents, each number represents, the first one represents the users, the second one represents the groups and the last one represents the o the other people and they use math.

So let me just check here, I have to look at the math every single time. You add four to the number if you want read permissions, you add two to the number for write permissions and one to the number for execute permissions. So if I went in here and did 66, I'm not gonna do 667, some people have a problem with that number, what would this be?

This would be the user can read and write, the group can read and write, and everyone else can read, write and execute which basically means everyone else, right? Or if I did 700, that's one that you'll actually will see. It means that just the user can read, write and execute and no one else has any permission.

So let's let's just do that and see what that looks like. So notice file.txt here can be read, written or executed by Ubuntu and no one else can do anything to the file, not even people in the group, right? Or if I did 600, that would be just the user can read and write, cuz a text file is not executable.

So they have read write or 640, that's another one you'll see as well. The group can read but can't write it, or 664, I think you're getting the point, though, right? That you use that kind of like math to to set the permissions. Now, why did they do that?

It's because computer scientists are lazy and I guess have good memories and wanted to do a little bit more math, right? Because I guess it's too burdensome to write out u equals rg or whatever. I guess that's the point is I can't even remember and I was just talking about it.

So that's why you see 777. That's basically saying anyone can do anything to this file whenever they want to. So it's not usually the best idea to say 777 on a file because that's a very insecure practice, but that's why you'll see it. It's because it's the easy thing to do, even if it's not the right thing to do.

And then the last one that you'll see sometimes is let's say we had a, I'm gonna touch a file called my-new-program. Let's say I wanna make that file executable. What you can do is sudo chmod +x, my-new-program, like that. And it's just going to go ahead and add the executable ability to all permissions, right?

So now if I go in here, you'll see that my new program here has an x permission for each one of those so it makes it so anyone can execute it. By the same token, I can come in here and say -x and it'll take away that x for everybody.

And same diff with like you could do maybe like +w for everybody and now everybody can write. Where did I go? I guess that just adds it for the user in the group, but there you go. So mostly you'll see a pro plus x, right, to add executable permissions to something or take it away.

For the most part, I just do the the one that I was showing you before sudo chmod, our user equals blah blah blah because I can remember that and I don't have to go look up the math for it every single time. But I wanted to show you the other ways because you will definitely see them in Stack Overflow answers.

Questions? Permissions makes sense? Cool. It's something like that knowledge I showed you, if I was able to teach it to you in I don't know 30 minutes or something like that. That's probably taken me like seven years to really understand everything that I taught you which is just positively shameful to admit but I just never went and researched it.

I just kind of like osmosed it over seven years. So you're already way ahead of where I was about, I don't know last week. No, I'm just kidding. Maybe like I said, like seven years in my career. The question is, is when you cat out this Etsy password, what are all the various different values?

So let's talk about you have your Ubuntu here. I think one of these this 1000 and this 1001 I think these are user IDs, right, because you can refer to a user by their ID or by the name, by the same token, I think the 1000 and the 1001 I think those are group IDs.

I don't know what this Ubuntu is honestly. You can see there that Brian doesn't have one. I don't know what the x is. This one is their home directory /home/ubuntu and the /bin/bash is the login shell. So like whenever you say, hey log me in as Ubuntu, run this.

So for example, you'll notice that Brian's login shell is a different shell it's I think this is called ash. I wonder if I can, man sh, it's dash, see I don't even know what that is. So it's a different shell still. So for example, you'll notice that your tab completions we're not working as Brian.

That's because you're actually running a different shell. It's very, very similar but it's stripped down and less powerful than bash. So that's why some of these have like false and no login is won't allow you to log in as these users, they're not interactive users. For that x and for the Ubuntu here, you'd have to go look up that cuz I don't actually know what those are.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now