An introduction to Linux Part 4 Open a terminal window (Ctrl-Alt-T) and follow along with these step-by-step instruction to learn some more about how to navigate in the Linux Environment. Open the terminal window so that it is about the same size as this one, so both fit, side by side, and you can follow along interactively...
clear One of the difficulty (and beauties) of working in the terminal is that you can see all of the things you ve done in the past few minutes right there on the screen. Sometimes the screen gets messy, so you ll want to get used to using the clear command. It doesn t actually erase anything, but it pushes everything up, above the screen. You can scroll up and see it again if you like.
TMI Another way to make it easier to view things in Linux is looking around a directory to see what files and folders (directories) are there. Remember what a huge pain it was to look at all those files in /etc? No?...Well, let s go there and learn another trick for viewing large amounts of information. Enter the command cd /etc
ls less Enter ls to see the content of /etc. Too much information, huh? Well, let s pipe that information to the less command, so that we can see it one page at a time. Enter ls less with the character (the key above the [Enter] key, using [Shift]) and with spaces between each. Type q to quit and the arrow keys to move up and down. Neat, huh!
ls -C less And if you want to be even more organized, try entering this modification to see the output in columns (-C) a page at a time. In English, this would be look see, in columns, piped to see less information, a page at a time.
ls grep xxx What if you wanted to see only those files or folders in /etc that contained the characters app? Well, you can use the command/program/utility called grep to search for specific strings or characters. Enter ls grep app
ls -R grep yyyyyy How can we use this in working on CyberPatriot issues? Well, what if we wanted to find all of the files in the /etc directory that contained the name config (as in configuration)? Well, we d start with ls, to which we would add -R (the recursive option, to drill down through all the layers in /etc), and then grep for config This screen shot shows us just a few of the files found.
editing a file Let s put some of our new knowledge to work with a security file, one involving user passwords. We ll find out how to ensure that everyone uses a password that is strong and secure and is coded with the sha512 algorithm. Along the way, we ll learn how to use the nano program to edit an important security file. We ll start by going to the /etc directory, if you are not already there. cd /etc
locate Now let s look for a file that contains the word password because we remember that there is an important security file with that word in its name. We ll use the sudo command because maybe the file is only accessible to admin users. Well, that helps, but I need to know where it is located; that is, I need to know its path. Let s use the locate command with the word password Wow! Talk about TMI...
using locate & grep Let s show just a page at a time by piping to less Well, that is still TMI, so let s see if we can filter with just those files in /etc which contain the word password in their name Ah! Now we know where it is. Let s go there using cd
sudo nano and Ctrl w Let s look around and then, once we spot the file, open it as the superuser in a file editor called nano (named nano because it is small and easy to use) and then let s look for the part of the file that we want to check on and maybe modify. Type Ctrl w and enter the characters sha512 and click [Enter]
nano Alt w To keep looking for sha512 because it shows up multiple times in lines that start with #, meaning that the line is a comment and not read by the computer (just humans can read comments), let s let the nano editor fill the screen (click the box icon ) and click Alt w to keep hunting for the line that contains sha512 Ah! there it is If not there, we d want to modify the line to read
nano: Save and Quit Once the line reads correctly, we would click Ctrl o to output the file, click [Enter] to accept the file name, and then click Ctrl x to exit. What we have just done is examine a configuration file for password complexity (the more complex a password is, the harder it is to hack!) and, if the file is not the way it should be, edit it. Good work, hacker!
nano: quit without saving If you are working in the editor and realize that you have made changes you are not too sure about, you can exit the editor without saving any of your changes. Type Ctrl-x and you will see Type n and you will be back at your prompt, having exited nano without saving anything at all.