US & Canada: 1-888-354-6128
Local & International: 1-206-438-5887
1-703-564-9887/1-604-638-2525
Thank you for choosing Superb as your dedicated hosting partner. We hope this document helps you on your way to administering your Linux server. The possible range of topics to cover is nearly limitless so it is not possible to cover everything. We've tried to cover the most important and relevant to you. The topics covered in this document will also be covered in books and other sources of information widely available on the net which you can use to further your understanding. As well, we will include relevant links throughout this document so that you can get more in depth information.
The LINUX operating system is made up of three parts; the kernel, the shell and the programs.
The kernel of Linux is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file "myfile"). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the Linux prompt % to the user, indicating that it is waiting for further commands.
The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).
Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the bash shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.
History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the cursor keys to scroll up and down the list or type history for a list of previous commands.
SSH was created to encrypt the data being sent over the network as well as provide an option that prevents passwords from being ever passed over the network. We recommend connection to your server via SSH. To connect to your server via SSH, you need to have a ssh client installed. We recommend one of the following:
For more information, please refer to The SSH FAQ
For security reason, please do not SSH to your server directly as root. Always connect using your own login first and then use the command su (switch user) to root. Root is used for administrative purposes. The root login is much like the administrative login on Windows or many other servers. You will have full access to all areas of the server. Therefore, only use root when you absolutely need to perform administrative tasks. All other times, log in as yourself.
Navigating around the files and directories of your hard drive could be a dreaded task for you, but it is necessary knowledge. In this section, we will cover some basic commands to help you navigate through your system.
% cd my_directory
there are two special directories called "." and ".."
In Linux, "." means the current directory, so typing
% cd . (NOTE: there is a space between cd and the dot)
means stay where you are (the my_directory directory). This may not seem very useful at first, but using "." as the name of the current directory will save a lot of typing, as you will see later.
".." means the parent of the current directory, so typing
% cd ..
will take you one directory up the hierarchy (back to your home directory). Try it now.
Note: typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system.
ls (list) The ls letters stand for list. Typing ls will give you a listing of all the files in the current directory. If you're new to Linux, chances are that the directories you are commonly in will be empty, and after the ls command is run, you are not given any information and will just be returned to the command prompt (the shell).
There are "hidden" files in Linux, too. Their file names start with a dot, and doing a normal ls will not show them in a directory. Many configuration files start with a dot on their file names because they would only get in the way of users who would like to see more commonly used items. To view hidden
% ls -a
To view more information about the files in a directory, use the -l flag with ls. It will show the file permissions as well as the file size, which are probably what are the most useful things to know about files.
You can put flags together, so to view all the files in a directory, show their permissions/size, and view all the files that way through the subdirectories, you could type:
% ls -laR
% pwd
The full pathname will look something like this:
/home/joe
which means that joe (your home directory) is inside the /home directory. ~ (your home directory) Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing % ls ~/html will list the contents of your html directory, no matter where you currently are in the file system.Typing % ls ~ would list the contents of your home directory; And typing% ls ~/.. would list the parent directory - that is one directory above your current one.
Most of the file management in Linux is done through the command line, so once you learn some basic commands and utilities, you will find it surprisingly easy and efficient.
There are other extensions to the cp command. You can use the -f parameter to force it. You can use the -a (arvhive) parameter to preserve all attributes of the original files or directories.
Using the cp command, you can copy an entire directory to its new destination. Suppose you want to copy a directory (and all of its contents) from /home/template/html/index.html to your current directory, you would type:
% cp -rpf /home/template/html/index.html .
To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two.It can also be used to rename a file, by "moving" the file to the same directory, but giving it a different name.
% rm -i my_file
To delete something in some other directory, use the full path as the file name. For example, if you want to delete a file called "foobar" that's in the directory /usr/local/src/, you would type:
% rm -i /usr/local/src/foobar
To remove an entire directory and all of its contents, type rm -rf /directory where "/directory" is the path to the directory that you want to delete. The "r" and "f" paramters stand for "recursive" and "force" respectively. We cannot stress how potentially harmful this rm command (used in conjunction with -rf) to your system's health. Do be careful.
Then type:
A common way to edit files is to download them to your local computer, edit them using your favourite text editor, and uploading them when you are done. However, if you wish to edit your files on the server itself, you have a variety of text editor tools at your disposal. The basic syntax to invoke these text editors is the same. Type the name of the editor followed by the file you want to edit, separated by a space in between. Non-existent files will be blank and will be created when you save.
Emacs is text editor that probably has more features than any other in the Unix/Linux world. In order to take advantage of its power, you will need to learn its commands. To start of it, there are two important commands you need to know:
While you're editing a certain file with emacs, you can save it with the [Ctrl]-x [Ctrl]-s keystrokes. Then to exit, type [Ctrl]-x [Ctrl]-c.
The instructions for using pico are located on the screen. You save the file by using the [Ctrl]-o keystroke (for write-out) and exit with [Ctrl]-x.
Shutting down and restarting properly will prevent your filesystem from being damaged. Filesystem damage is the most obvious of the consequences, but there are probably other things such as database corruptions etc. that may occur if proper shut down procedure is not followed. When you or as per your request, our technician issue a shutdown command, the system goes through a series of steps that properly terminate all processes that are running at that time.
To do a reboot, you can either type reboot or shutdown -r now. The -r parameter instructs the server to start up again right after the system finishes the shutdown cycle. The now parameter instructs the system to do it without delay. Instead of now, you can use 12:00 which means perform the shutdown command at exactly at 12 o'clock. Alternatively you can type shutdown -r +5 which instructs the system to shutdown in 5 minutes.
To shut down your system completely and not start it up again, such as when you require your system to be serviced by our technicians, type shutdown -h now, which instructs the shutdown program to begin system halt immediately.
There are rare cases in which your server may lock up entirely, and prevent you from being able to access a command prompt to perform these shutdown or reboot procedures. Only then will your last resort be to contact our online technicians to do a forced reboot (pressing the restart button on the server).
Whether or not you have many users on your system, it's important to understand the aspects of user management under Linux. Even if you're the only user, you should presumably have a separate account for yourself (an account other than root to do most of your work).
Each person using the system should have his or her own account. It is seldom a good idea to have several people share the same account. Not only is security an issue, but accounts are used to uniquely identify users to the system. You need to be able to keep track of who is doing what.
The system keeps track of a number of pieces of information about each user. They are summarized below.
passwd file
The file /etc/passwd contains this information about users. Each line in the file contains information about a single user; the format of each line is
username:x:UID:GID:full name:home directory:login shell
An example might be:
gshrub:x:102:100:George W. Shrub:/home/gshrub:/bin/bash
As we can see, the first field, "gshrub", is the username.
The next field, "x'', is no longer used. In the older system, it used to be the encrypted password. For security reasons, passwords are no longer stored in the /etc/password file which is world readable. Previously, any user with malicious intention can take the password and perform exhaustive dictionary password cracking algorithm to it and extract simple passwords. Nowaday, encrypted passwords are relegated to the file /etc/shadow which provide some degrees of extra security because it is not world readable. Shadow password provides some other features such as password expiration and so on; we will go over that briefly below.
The third field, "102", is the UID. This must be unique for each user. The fourth field, "100", is the GID. This user belongs to the group numbered 100. Group information, like user information, is stored in the file /etc/group.
The fifth field is the user's full name, "George W. Shrub". The last two fields are the user's home directory (/home/gshrub) and login shell (/bin/bash), respectively. It is not required that the user's home directory be given the same name as the username. It does help identify the directory, however.
shadow file In the /etc/shadow file, you will see a corresponding line for user "gshrub":
It follows the scheme:
group file The file /etc/group contains information about the group of the system. It's lines are like the one below:
following the scheme:
Linux provides you with a number of useful administrative tools for adding users to your system, so that you not need to manually modify the /etc/password and /etc/shadow files. These tools automate the steps for adding users. The command useradd adds the user in /etc/passwd, sets up /etc/group, creates a home directory and copies the files that reside in the directory /etc/skel to the user's home directory. The directory /etc/skel contains some ready-to-use configuration files, that are necessary for every user of your system.
As an example of how to use this command: % useradd -d /home/joe -k /etc/skel -s /bin/bash username
-d /home3/joe parameter pair gives the instruction to create a new directory /home/joe if that directory does not already exists. Furthermore, the directory will be owned by user joe and group joe (group joe is default since we did not specify the group using -g parameter). -k /etc/skel gives the instruction to use /etc/skel as the template directory when creating /home/joe. Therefore, if you wish to customize what files your users will get by default, modify /etc/skel or create another template directory and use that one with the -k parameter. -s /bin/bash allows the new user to have /bin/bash as this user's shell. username is the login name of the user.
What the useradd command actually is doing is the following steps:
Before the user can log into the server, you have to set the password for this user. So for user joe that you have just added, type:
% passwd joe
Please avoid using any simple, dictionary passwords or passwords based on publicly available information such as your phone number. Clever password cracking programs can solve them. Use a password that is at least 8 characters long, containing letters, numbers as well as other characters and in mixed cases.
Sometimes you may wish to change one or more attributes of a user. For example, suppose you decide to change the login from joe to johny, you can do this:
% usermod -l johny joe
Suppose you have also renamed the directory /home/joe to /home/johny, you would also need to change the information in the /etc/passwd file. You can do this by:
% usermod -d /home/johny johny (since the user name is now johny)
When you want to delete a user from your system, use the command userdel to do that. For example:
% userdel johny
Basically the userdel command performs these two steps:
The main purpose of quota is to limit the disk space or the number of inodes used by a user or group. Disk space is referred to the ammount of space allocated to the user whereas the inodes refer to the number of files that a user can access at a time. On every server where disk space is shared among users there is a need to restrict them to a certain amount of disk space. This is done to prevent some users hogging up the entire disk space. Inodes limitation is rarely used so we will not discuss it here.
Disk quotas are implemented per user (or per group) per disk partition. During the boot time each partition is checked to see if quota has been implemented on it or not. To implement user or group quotas for a given partition we specify usrquota or grpquota options in the fourth field of /etc/fstab file.
The contents of the above files are not in human readable form. The most important thing is in order for quota to work on a partition, you have to initialize this file. To do that you have to run quota check for both group and user. If you use the default -avu option it only checks the user quotas and uitilizes the aquota.user file only. Example:
Once you have initialize the aquota.user or the aquota.group or both files, you can finally turn on quota. Use this command:
Conversely, if you wish to turn off quota, use this command:
Now that quota to your desired partitions have been turned on, you can go ahead and allocate quota to your users. To accomplish this, you use the edquota (edit quota) command. The edquota command puts you into a "vi" editing mode so knowledge of the "vi" editor is necessary. Another editor may be specified with the EDITOR environment variable. You are NOT editing the aquota.user file directly. The /partition/aquota.user or aquota.group file is a binary file which you do not edit directly. The command edquota gives you an ascii interface with the text is prepared for you. When you ":wq" to save the file from the vi session, it is converted to binary by the edquota command and stored in the aquota.user or aquota.group file. edquota
To allocate 100MB of disk space for user joe in the "/" partition, you type:
Quotas for user joe: /dev/sdb6: blocks in use: 56, limits (soft = 0, hard = 0) inodes in use: 50, limits (soft = 0, hard = 0)
You need to change this text so it will look like (remember that we are only interested in limiting the space consumption and not the number of files:
Quotas for user joe: /dev/sdb6: blocks in use: 56, limits (soft = 100000, hard = 105000) inodes in use: 50, limits (soft = 0, hard = 0)
Explanation of terms:
Grace Period Grace period is a time limit before the soft limit is enforced for a file system with quota enabled. Also when it is enabled, the user absolutely cannot go beyond the hard limit if set. Time units of sec(onds), min(utes), hour(s), day(s), week(s), and month(s) can be used. To set a grace period for user joe, you type: % edquota -t joe Time units may be: days, hours, minutes, or seconds Grace period before enforcing soft limits for users: /dev/hda2: block grace period: 0 days, file grace period: 0 days
0 days indicate that grace period has NOT been enabled. Change the 0 days part to any length of time you feel reasonable. A good choice might be 7 days (or 1 week). Viewing a user's quota To view joe's current quota and usage information, type:
% quota -v joe
To display a summary report of all users' quota and usage information on your server, type:
% repquota -a
This topic is vast in its scope and it is not the intention of this document to cover it in any significant detail. If you wish to find out more, please refer to many available books and other resources on this topic. We will just point out the tools available to you and especially help you set up multiple IPs on your server.
These programs will modify values in the following files:
For any of the above command, if you wish to know more detail, please type man <command>.
Although there are configuration utilities you can use to help you perform this task, we will show you a simple manual procedure to do this. The rationale is that if something goes wrong with the configuration, at least you know what has been done and you can reverse it. What you are trying to accomplish is what many people refer to as IP address aliasing. That is, enabling multiple IP addresses on one ethernet card. Assuming that your server currently has the IP address: 192.168.100.4 and you wish to set up the additional 192.168.100.50 IP to it. The following is a step by step instructions on how to manually and permanently add that IP to your server:
Please note that if the new IP given to you does not belong to the same C-block as the IP of your server, the NETMASK and GATEWAY parameters will necessarily be different for this file. Please consult us for the the exact values of those.
To set up additional IPs, repeat the above procedure using different filename, such as ifcfg-eth:1, device=eth0:1, and change IPADDR as appropriate.
In order for your changes to take effect, you must restart your server's network functions. To do that, type:
At the time of this writing, Apache still dominates the internet as the most deployed web server. When we install your Linux server, we configure it with Apache web server. In this section, we will go over some Apache basics so that you can hopefully understand how it works and configure it to host your site(s).
% /etc/rc.d/init.d/httpd start % /etc/rc.d/init.d/httpd restart
Apache was set up on your server to serve its web pages from the directory /home/httpd/html/. The default home page for the default configuration is index.html.
If you intend to only serve one web site, then all you need to do is upload all your web content to this /home/httpd/html directory. However, Apache may be configured to host multiple domains each serving files from a different directory. This is referred to as virtual hosting, and it consists of two types:
Before we get into how to configure apache for virtual hosting, we need to focus on the all important /etc/httpd/conf/httpd.conf file.
This section of the configuration file deals with the default server. The default server (or main server) is the one that will handle any requests not captured by a <VirtualHost> stanza in your configuration. Directives and instructions that you set in this section are, in general, inherited by virtualhosts as well, so you can set some good default behaviours here rather than duplicating a lot of effort. Settings inside <VirtualHost> stanzas will override these options for that particular virtualhost only.