pete > courses > Crash Course in System Security (CSCI 1005), Winter 2025 > Day 02


Day 02: Introduction to Linux

goals:

intro to linux (or, rather, intro to linux from the shell)

This is very much drinking from the firehose! I do not expect you to be masters and mistresses of all these tools and concepts within the next few hours. Rather, I hope to provide you with basic understanding of the common methods of interaction and a broad but shallow survey of useful programs. You will see many of these concepts repeatedly over the next few weeks and grow intimately familiar with them; some of them, not so much. Consider this a reference, helping to jog your memory when you think to yourself, ``didn’t we talk about a program that does XYZ? I wonder what it was called and how it works?’’

running programs

directory hierarchy

permissions and file types

stdin/stdout/stderr

filters

pipelines

other useful tools

References


Exercises


Linux kernel scavenger hunt

Scoping the problem

I mentioned yesterday that the Linux kernel has a bazillion (approx) lines of code, in which potential vulnerabilities may be lurking. Count the lines of code in the Linux kernel.

This will involve determining what qualifies as "code" (the find and file commands might come in handy) and then doing the counting.

Customize your shell prompt

The contents of the bash environment variable PS1 controls the appearance of your shell prompt. Figure out the format of the magical incantation that speaks to PS1.

You can test new values for PS1 by setting its value in the current shell: export PS1="foo bar baz" (In very simple terms, export is the command to set an environment variable—it’s actually more complicated than this, but you don’t need to worry about those details right now).

You’ll note that, if you log out and log back in again, your prompt reverts to its default format. Make your change persistent by putting your export command in the file ~/.bashrc.

If you’re super-ambitious, try setting colors: http://misc.flogisoft.com/bash/tip_colors_and_formatting

If you’re super-super-ambitious, read the bash manpage to understand all the settings customization you can perform, as well as how/when/why ~/.bashrc is evaluated as opposed to ~/.bash_profile.

Explore processes

Programs are files on disk that may be executed. When they are executed, they become running processes. (We’ll explore how a program becomes a process later on.) The ps command shows running processes.

By default, ps doesn’t show many processes. Figure out why. Figure out how to show all processes currently running on the machine.

Memory leaks are bad. Generate a list of the top 5 memory hogs currently running.

Like intrepid American explorers, now you get to kill the stuff you’ve explored. The kill command terminates a process (again, it’s more complicated, but that’s all you need to know for now). Figure out how it works. Start up a program and kill it.

If you’re like me, you will not infrequently happen upon a situation in which you want to kill a bunch of processes at once. Write a shell pipeline that finds all processes containing the string "bash" and kills them. You will find the cut and xargs commands handy.

Advanced shell scripting

Like compiled programs such as ls, grep, and find, shell scripts can accept command-line arguments. Modify the shell script you wrote above to accept the filter string as a command-line argument. (You will find the Advanced Bash-Scripting Guide useful here—pay particular attention to not just the material on command-line arguments, but also that on quoting and interpolation.)

Further Arch Linux resources

You may come across some software for which Arch Linux does not provide a binary package (ie, packages containing compiled machine code). In this case, Arch often instead provides instructions on how to build a binary package of your very own; learn more about the Arch User Repository.

The Arch Linux Wiki is an immensely valuable repository of knowledge.

Among other things, it contains a list of common applications. Explore this list. Install software that piques your interest. Play around. Have fun.

Last modified: