Computer
Networking
and
Practical
Security

Fall 2006
course
navigation

Unix Introduction/Refresher

This serves as *minimum* unix knowledge base for this course. Students new to the command line should not be discouraged if they are not already familiar with all of the following, but they should study this section closely, as the tools and concepts here will re-appear regularly when dealing with both networking and security. The network utilities and files sections can be skipped initially, as their usage will be explained in more depth in the system administration GettingStarted section.

Contents

Fundamental Concepts

Why Unix?

Unix-based operating systems are by and large the most robust and secure systems available. Despite comprising only a small percentage of the personal computer market, they are far more common in business, education, and any networking settings due to their efficient multitasking, network implementation, and largely open-sourced design (not all versions of Unix are open-source, but most rely largely on an open-source software base). Due to their multitasking implementation (and decades of testing), Unix systems also tend to be very hard to crash (though certainly not impossible), which also makes them ideal for servers that need to run unhindered for months on end.
The term "Unix" no longer refers to one specific operating system, as the project has divided over the years, though all share a similar framework. Some of the most popular derivations include Linux, SunOS (Solaris), and Mac OSX. Linux itself is divided into many different distributions, or "distros", which tend to have unique filesystems and slightly different organization. It is usually easy to translate knowledge of one into understanding of another though. From here out, unless otherwise noted, examples will be for a Linux system (with details when distro specific).

The Shell

Whenever you're at the command line, you're using a "shell" to interact with the computer. Shells, as the name suggests, separate users and allow them each their own unique interface. They're also nesting (think Russian dolls, only with lots of space between each doll). I can be logged in as "joedirt, type "su fishpaste" ("su" means "substitute user"), and find myself in a new shell for fishpaste. Any changes I make to fishpaste's shell will not affect joedirt's. Similarly, I can be logged in as "mork" on my machine, then use ssh to log into the cs server as "mindy". Again, this is a separate shell and won't affect mork's carefully edited shell initialization file.
A shell has a collection of "environment variables", variables that can affect the behavior of the shell and applications running within it. Several of these are created and updated by the shell itself, such as ones for user and present working directory, though you can create your own as you see fit.
There are different shells available, including bash, csh, and tcsh, and each has a slightly different syntax. Bash is the default shell on most systems and the most common, so we will use that for our examples.

Permissions and Root

Every file and directory on a unix box has a set of permissions. This set specifies different users' abilities to read, write, and/or execute. The permissions are divided into three categories: owner (each file has a unique user classified as owner), group (which can contain any number of users), and everyone else. This allows the owner to give only the minimum necessary access to other people.
You've probably heard "1337 haxxorz" claim they've "rooted" a box. Each Unix system has "root" account with access to everything. This can be very good or very very bad, depending on the circumstances, and you should be very careful when logged in as root. This is where you can accidentally destroy your filesystem and lose all your data with a single command, or where an attacker can "own the box", changing your passwords, deleting your logs, replacing harmless programs with malicious ones. On the other hand, you'll be able to access all parts of your system and do some pretty cool things, so be careful, not afraid.

Installing Applications

Most Linux systems have some sort of package manager -- a tool that will download, compile, and install applications from a repository for you. Debian/Ubuntu uses "apt-get" and Red Hat/Fedora uses "yum". Mac OSX also has a package manager called "fink". The repositories for these tools contain thousands of applications, including most of the most popular ones.
At times however, it is necessary to compile and install an application "by hand". To do this, move to the directory of the source code, run "./configure", "make", and "make install". In order, these three steps set up parameters for compilation and installation, compile an executable program, and copy the executable along with any libraries, man pages, etc. to their desired locations. Sometimes different systems require that ./configure be run with specific options in order for the program to successfully compile, which are not always obvious. At these times, the best thing to do is either search for distro/hardware specific installation instructions, or a pre-compiled compatible version.

Man pages

Man pages are your friend. All of the standard Unix tools (and most tools you install) will have a man (manual) page. You'll find information on what they do, how (and often advice on when) to use them, what options are available, and occasionally the odd history or math lesson. When all else fails, start here.

Frequently Used Utilities and Files

Basic Utilities

Common Files and Directories

Note that files and directories whose names begin with "." are considered "hidden", and will not be displayed by ls without the "-a" option.

Network Utilities

Network Files

Sources and Further Reading

1) http://en.wikipedia.org/wiki/Unix
For more information about any of the tools mentioned, read their respective man pages.