This is my first tutorial so I hope you enjoy it. Linux Basics by dingus dingus@linuxmail.org www.rootslash.com July 21, 2001 Table of Contents: 1) Introduction 2) Privileged Users 3) Installation 4) Directory Structure 5) Command Line 6) Text Editors 7) Pipes and Redirection 8) Shortcuts 9) Compiling and Installing Packages 10) Network Tools 11) Ownership 12) Permissions 13) Administrative Commands 14) Users and Groups 15) Conclusion -------------------------------------------------------------------- 1) Introduction -------------------------------------------------------------------- This tutorial is intended for those who are new to Linux or want to review and improve their basic skills. I, dingus, will attempt to cover the general aspects of installation to being able to understand the basics of your Linux machine. This tutorial is also best utilized when the reader, you, are at your computer trying these commands yourself. Although I do believe I give enough information to just simply read through it, you will definitely get more out of it by doing it as I go along. If you have questions, comments or complaints please feel free to go to my website and find thee most appropriate way to contact me. If you did not spot the URL above, the address is www.rootslash.com -------------------------------------------------------------------- 2) Privileged Users -------------------------------------------------------------------- Before diving into everything we need to know what “root” is. “root” is a user and can do anything to any file even it if is not owned by him or her. The user has no limitations. “root” is often referred to as the super user account as it really is a “super” account. All other users only have permission to edit files they own. For information on permissions you should skip to the “Permissions” section of this tutorial. There are also privileged accounts, which may have some super user abilities as well. -------------------------------------------------------------------- 3) Installation -------------------------------------------------------------------- I'm not going to tell you how to install Linux in this section simply because it varies from distribution to distribution. Before installing Linux make sure to read all documents which came with it. If you downloaded Linux then make sure that you go your distribution's web page and read all the installation material. It would also be a good idea to print the installation instructions out as well so you are able to look at it during the installation. Most Linux distributions give you a choice of how you want to install. The options are usually something along the lines of "Default Install" which installs all available packages and "Custom" which allows you to choose which packages to install. Make sure to choose "Custom" install because this will allow you to choose what is installed into your system. By having less installed, it lowers the likely hood of being cracked. The reason is because if you have fewer applications and services running there are less vulnerabilities in which you can be cracked. Another reason to install only what is needed is that your system will have less to run and handle, resulting in higher system performance. -------------------------------------------------------------------- 3.2) fdisk -------------------------------------------------------------------- “fdisk” is a partition tool that comes in the default installation of all Linux distributions. It must be run as root. At the very minimum you should at least make a root partition as well as a swap partition. Although the swap partition is not required it is highly recommended. The swap partition is used for virtual memory and the root partition is used for all the other files that go into your system. Some users like to make partitions for /home, /var and other big directories if they are running a server. This is for security reasons so that someone does not try to launch a Denial of Service attack by overflowing the amount of logs which is held in the /var directory. So if you are planning on running a server you might consider making a separate partition for /var as well as other directories. Now that that is out of the way, we will get on to creating partitions. When first booting up from either a boot disk or CD-ROM you should get a prompt. Type: fdisk /dev/hda substituting /dev/hda for the drive you want to partition. All drives including CD-ROM, floppy and any other kind of drives you can think of are in the /dev directory. It might happen that your hard drive is not labeled "hda" and could be something like "hdb" or "hdc." In that case substitute "hda" with the proper drive. If you have SCSI hard drives they will be labeled "sdx" where "x" is a letter a-z. So for example if you were a SCSI hard drive user you would execute this command: fdisk /dev/sda After you have specified which drive you want to partition it's a good idea to take a look at how that disk is setup by using the "p" command. It will "print" the current partitions within that disk. I'm going to assume you want to delete all partitions and install Linux on a fresh hard drive. So to delete them type "d" and then "1" and then "d" again then "2" and so on until all partitions are deleted. The "d" stands for delete obviously and the numbers such as "1" and "2" are the partition numbers. Now type "p" to make sure nothing is listed other then the headings. If everything is gone you are all set to start creating your new partitions, if there are still partitions listed then delete them using the method described previously. We are now going to make the swap partition by typing "n" which means "new" partition. When you type that it will ask for either extended or primary. Choose primary by typing "p." fdisk will proceed to ask which partition number and you will respond with "1" since this is your first partition that you are creating. Then it will ask for the first cylinder, just choose the default by either entering the number or pressing enter. Then it asks for the last cylinder or size or size in megabytes or size in kilobytes. You will want to use the size in megabytes option by typing: +128M. That is if you have 64 megabytes of ram. It is a good rule of thumb to use double the amount of ram you have for your swap space. So in our case we have 64 megabytes of ram so we chose 128 megabytes for our swap space. So if we had 128 megabytes of ram we would put 256 megabytes for our swap. Although you do not have to always use double, it is just a good idea. We are now done creating our swap partition. Now we will create our root file system partition. This is pretty much the same as creating the swap partition except we just change a few things. We type "n" again for a new partition and then it will ask us if we want a primary or extended partition, we choose primary by typing "p." For partition number we choose "2" since it is our second partition and then choose the default for the first and last cylinders. Of course you can change the default but the default is all right for what we are doing. We are almost done using fdisk. We just need to change the type of the first partition we made to specify it as the swap partition. To do this we type "t" which stands for "type" and we type 82. The second partition we made which is the root partition does not need to be changed because it is on the default 83, which is "Linux Native." Now that we have done that type "p" one last time to make sure everything is all right. If all is good type "w" to "write" your partition table to your hard drive and you are done. -------------------------------------------------------------------- 4) Directory Structure -------------------------------------------------------------------- The / directory stands for the root directory. It is the top of the directory tree. All directories below are held in this directory. The /bin directory is where all executable files are held. "bin" stands for binaries. Commands such as "ls" and "cd" are contained here. The /boot directory is self explanitory. It contains the boot files needed to start the system such as LILO (Linux Loader). The /cdrom directory is a mounting place for your CD-ROM although you may mount it to any directory you want. The /dev directory is where all your "devices" are held. All your devices are treated like files. Your partitions, floppy, CD-ROM etc. are found here. The /etc directory contains the majority of the configuration files. Most are in text form and so you get to edit them with your favorite text editor. The /home directory is self-explanatory. It holds all the users' home directories. So for example, my user name is "dingus" so I would be /home/dingus. It does not hold the root user's home directory however. The /lib directory stands for "libraries" which contains shared library files such as the kernal modules and C Library. The /lost+found directory is where fragments of data are placed when your system does not know where they belong. This is especially true if you shut your system down improperly causing fsck to run. When fsck cannot find a place for a fragment it is placed in this directory. The /mnt directory is the typical directory for a person to mount file systems to such as your CD-ROM and floppy. The /proc directory contains information about the system. The /root directory is the home directory of the root user. The /sbin directory means "system binaries" and contains binaries for system administration such as monitoring and configuring. Commands such as "mount" and "shutdown" are found here. The programs can only be run by root or during boot time. The /tmp diretory is for temporary files. The /var directory contains the log files, mail spools, lock spools, and printer spools. -------------------------------------------------------------------- 5) The Command Line -------------------------------------------------------------------- In the section I will discuss various useful commands. I cannot write about every command there is because that would be a book in it self. Here is how I will give examples. command