Code Snipcademy on April 17th, 2015
Last post we taught you how to use the command line to cook the perfect steak. Now we'll teach you how to manipulate Linux permissions to grant access rights to buy and open Pokémon booster packs!
If you're unfamiliar with Pokémon cards, they're collectible shreds of paper with a Japanese monster drawn on them. You can use them to trade for other cards, make friends, and achieve social status among your fellow prepubescent friends. The more they shine and sparkle, the more they're worth. To sum it up, it's pretty much a big deal, especially when you're a 12-year-old kid.
There's only one problem - your parents hate them. They don't understand the need to having a 1st Edition Charizard. Or how great of an investment these cards are - with returns ranking close to TY beanie babies! They'd rather have you read useless books (also pieces of paper but with words instead of monsters on them). We can, however, get around your strict parents through our cunning knowledge of the all-glorious command line interface.
The first thing we have to do is check our piggy bank to see if we have enough for a booster pack.
Now let's check our wallet to see how our funds stand.
$ ls piggy.bnk -rwx------ 1 LittleJohn root 4.23USD Apr 21 15:38 piggy.bnk
Great! That should be enough for just one booster.
Now let's head on over to the local hobby store to check for Pokémon cards.
Once you're inside, change directories to the counter, and check all Pokémon booster packs' file access attributes. Since the booster is a directory, we have to pass in the
HobbyStore$ cd counter Counter$ ls | grep *.pkmn BoosterPack-Basic.pkmn BoosterPack-Fossil.pkmn BoosterPack-TeamRocket.pkmn BoosterPack-Jungle.pkmn BoosterPack-GymHeroes.pkmn $ ls -ld BoosterPack-Basic.pkmn drwxr--r-- 1 HobbyStore root 3.99USD Apr 21 16:21 BoosterPack-Basic.pkmn
We can see that the owner has permissions
rwx, meaning he or she can enter inside the pack and list the contents.
For the other permissions (group and others) the
x option is not listed. Since this is a directory, that means we aren't able to access or list its contents. That's alright though! We'll learn how to handle all this through the command line!
Alright! Now let's go ahead and purchase it.
$ git checkout BoosterPack-Basic.pkmn Are you sure you want to purchase BooksterPack-Basic.pkmn for 3.99 USD [Y/n]? Y Enter pin: Loading >>>>>>>>>>>>>>> 100% Transaction complete.
Unfortunately since we are not of age yet, the HobbyShopEmployee has changed the file ownership rights to our dad instead of us. Boo-hoo.
HobbyShopEmployee$ sudo chown littleJohnnysDad BoosterPack-Basic.pkmn
Now that we have our booster, let's look at the file modes.
$ ls -ld BoosterPack-Basic.pkmn drwxr--r-- 1 littleJohnnysDad root 3.99USD Apr 21 16:21 BoosterPack-Basic.pkmn
Looks like nothing's really changed; we still need dad's permission to open the booster...
Here at Code Snipcademy, we unfortunately do not teach any black hat tricks. Thus, we'll put it on you to find out what your parent's root password is. After you figure this out, you may proceed!
Now that we know the root password, let's switch to dad's account!
$ su -l dad Password: ~littleJohnnysDad$
su command is used to switch users, and
-l option will load your dad's environment variables and set the current working directory to his home.
Now we have to change the booster's group to
kids, which we are part of.
$ chown :kids BoosterPack-Basic.pkmn drwxr--r-- 1 littleJohnnysDad kids 3.99USD Apr 21 16:21 BoosterPack-Basic.pkmn
Now let's change the group accession so that we can list and open the booster pack.
$ chmod g+rwx BoosterPack.pkmn $ ls -ld BoosterPack-Basic.pkmn drwxrwxr-- LittleJohnny kids 3.99USD Apr 21 16:21 BoosterPack-Basic.pkmn
Woohoo! Now we can be in our normal user account and open boosters!
Now, before you get too excited and pee your pants, let's think about this. Your parents will probably find out what you did and immediately change the password. However, we can go into the /etc/sudoers file to grant us permanent access.
To edit the /etc/sudoers file, use the
Great! Now add this line to the file, which will give us access to all root commands.
littleJohnny ALL=(ALL) ALL
Now we can use the
sudo command to do exactly we just did!
WOOOOO!!!! NOW LET'S OPEN THAT BOOSTER PACK!!!
$ cd BoosterPack-Basic.pkmn $ ls -l ...
See how fun and exciting that was? If you have 10 minutes to spare, learn more about Linux Command line permissions. Or feel free to browse through our command-line tutorial series!
Command Line Kung Fu is packed with dozens of tips and practical real-world examples. You won't find theoretical examples in this book. The examples demonstrate how to solve actual problems. The tactics are easy to find, too. Each chapter covers a specific topic and groups related tips and examples together.$ Check price
Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.$ Check price