Sei sulla pagina 1di 28

Linux System Administration

LINUX SYSTEM ADMINISTRATION


(Ubuntu and Red Hat)

Linux System Administration

What you will learn:


Introduction To Linux History Of Linux Kernel And Shell Installation Concepts Of File System Brief Overview Of Windows And Linux Boot Loader Troubleshooting Grub Error Terminals In Linux Apt-Get Command Useful Linux Commands Directory Structure In Linux Difference Between $ And # Sign (Concept Of Super User Do[Sudo]) Adding Users And Groups Enable/Disable ROOT Account in Linux (Ubuntu!) File Permissions Tar And G-Zip Setting JAVA Path In Linux

Linux Servers:
Telnet Server SSH(Secure Shell) Server Apache(httpd) Server FTP(File Transfer Protocol) Server DNS(Domain Naming Server) DHCP(Dynamic Host Configuration Protocol) Server SQUID Proxy Server SAMBA Server

Commands and Configurations Related to Ubu n

t uand RE D H AT Are Discussed Here

Linux System Administration

INTRODUCTION AND HISTORY OF LINUX:


Linux is a free open source operating system kernel built by a student to replace UNIX in 1990s. UNIX was the Major used OS in most universities. UNIX started asking students to pay money for the usage and development of the system. A professor developed MINIX in order to replace UNIX, which was used by Linus Torvalds. Linus started to develop the Linux Kernel. In the same time Richard Stallman started to develop GNU and constructed Free Software Foundation. This operating system is still being developed by many developers. And today thousands of flavors of Linux are available. Most of them are free and some are licensed. Linux is most commonly used operating system in server market. But due to its complexity it is not user friendly operating system. For an ordinary user Windows operating system is suitable. But for a network administrator, Linux is the most appropriate OS. As it is clear that this OS is not a user friendly OS, so it not difficult to assume that it is not the default OS in many PCs. Windows is the default OS for all the PCs. The firewall system in Linux is very strong and this OS is very secure. Only a few hackers can hack Linux because understanding LINUX is a very complex task. But Windows firewall seldom works. Take a look at this illustration and you will have an idea about the complexity of different Operating Systems. Specially Linux

We will talk about the installation but before that before installation process let us look at some of the important things. These are:

Linux System Administration

o KERNEL AND SHELL:


Kernel: At a high level, the kernel in an operating system serves as the bridge between applications and the actual data processing of the hardware the OS is running on. The kernel manages system resources and abstracts resources that applications must access.

Shell: In an operating system there is a special program called the shell. The shell accepts human readable commands and translates them into something the kernel can read and process. In Linux, there are various shells. Most common and most used are: BASH(Bourne-Again SHell) CSH(C Shell) KSH(Korn Shell) To find all the available shells in your system, use the following command: $ cat /etc/shells

Now lets move on towards the installation process

INSTALLATION:
Here well discuss about the installation of Ubuntu. First of all GET UBUNTU. There are two ways you can get Ubuntu. One is that if you have a faster internet connection and a CD writer you can download its ISO file from
http://www.ubuntu.com/desktop/get-ubuntu/download and then write it on a CD. Get a free burner from http://download.cnet.com/Free-Easy-CD-DVD-Burner/3000-2646_4-10627009.html Or you can order it from its official website http://www.ubuntu.com

Linux System Administration

Now have a look how to Burn an ISO file. Its easy.

Install the FREE EASY BURNER and open it. And click on create an image, now follow the wizard. Keep the speed unchanged and finish the wizard. And when the wizard is finished. You are ready to go.

Now boot from this CD and start the installation. 1. Select the Install Ubuntu option.

Linux System Administration

2. Select the language

3. Select your location

Linux System Administration

4. Select the keyboard layout(Better leave it unchanged)

5. On the next screen select the third option and click forward

6. Now click on add button

Linux System Administration

7. Here, allocate the space you want Ubuntu to install on, and select Extended-4 file system (File systems will be discussed in the next article), and select / as mount point and click ok.

MOUNT POINT:
A mount point is a directory or file at which a new file system, directory, or file is made accessible.

8. Now select the free space which you have already specified for swap area and select swap area. There is no mount point for swap area. SWAP AREA: This is a virtual memory used to speed up the Linux processes.

CONCEPTS OF FILE SYSTEM:


Drives are storage media, which can hold a file system. When a disk is formatted in a drive, it becomes organized and prepared to receive data. When we format a disk, it receives a file system. Formatting can be compared to starting a library. You must install the book shelves and the catalogue system before any books are put in place. Once the library is ready, bring on the books! Similar is the case with a disk. When we format it, we "burn in" a file system to make it ready to receive data (files).

Linux System Administration

We can format with any one of several different file systems: FAT File Allocation Table is the original, old 16 bit DOS system is probably used in 90% of all PCs. It is also called FAT16 contrary to: FAT32 This is a new addition to FAT, which Microsoft introduced with Windows 95 B the December 96 version (OSR2). The performance has been even improved with Windows 98. NTFS from Windows NT This is a 32 bit file system like HPFS, but not compatible with it. NTFS can only be used in Windows NT/2000/XP. If it was available for use in Windows 95/98, it may be preferable to FAT and FAT32. UNIX UNIX servers have their own file system. Here the use of upper/lower case in file naming is significant. Extended 2-3 and 4 are the main file systems Used in Linux. UFS, NFS and HSFS are also used. The file system is actually the interface between operating system and drives.

BRIEF OVERVIEW OF WINDOWS AND LINUX BOOT LOADER:


Boot loader is a piece of code that runs before any operating system is running. It is used to boot other operating systems. Usually each operating system has a set of boot loaders specific for it. Boot loaders usually contain several ways to boot the OS kernel and also contain commands for debugging and/or modifying the kernel environment. Windows has boot-loader named NTLDR; 512 bytes is fixed for this. And UNIX has GRUB boot-loader, which is mainly used. LILO is also used.

Linux System Administration

TROUBLESHOOTING GRUB ERROR:


Sometimes when you boot your PC, an error may occur like this: This is known as GRUB error. To overcome this error, reboot your system and boot from win98 CD. And write down the following command when the black screen appears:

fdisk /mbr

TERMINALS IN LINUX:
There are 7 terminals in Ubuntu. Each terminal can be accessed by pressing [ctrl + alt (F1 to F7)]. All the terminals are command line and only one is with graphical interface which we use mostly. Different terminals are used by those

professionals, who work in command line mode.

APT-GET COMMAND:
apt-get is the command-line tool for handling packages for Debian Linux which is use to: Install/manage individual packages Upgrade packages

10

Linux System Administration Apply security patch(s) Keep Debian system up to date Download source .deb files For example if you want to install wine after downloading it from the internet, you may write this command to complete the operation: apt-get install wine(version)

USEFUL LINUX COMMANDS:


The command structure is as follows: $ command [[-] option(s)] [option-argument(s)] [command-argument(s)] The commands used in all the Linux flavours are almost same. Here is a list of some commands which are used in both in Red Hat and Ubuntu and will be used most often. For more information on any command type man and then write down the command ( man stands for manual page ). For example if you want to know about the ls command, open the terminal and write down man ls and you will get all the information about this command. ls pwd mkdir cd rmdir rm rm rf cp mv cat more less list directory contents print name of current/working directory make directories is used to change the directory remove empty directories remove any file removes any file or any filled directory recursively and forcefully. copy files and directories move (rename) files to read content of any file. But you can not edit it! file perusal filter for crt viewing opposite to more

11

Linux System Administration find lpr date cal bc ls a ls l clear whoami date df h uname a vi nano gedit which ps echo ping ifconfig chgrp chsh username useradd userdel shutdown h now search for files in a directory hierarchy print files print or set the system date and time displays a calendar calculator to see the hidden files to list the file contents in long format to clear the screen in terminal prints out your login name prints out date used to tell you about the free space in your system(-h for Human Readable format) Prints out the name of UNIX OS you are using text editor text editor text editor To locate the exact path of a program, you can use the which command Show information about the active processes Used to display a message used to check out the connectivity between two devices shows the network interface cards configuration to change the group of a file to change shell of a user add a user delete a user shutting down the system

12

Linux System Administration

DIRECTORY STRUCTURE IN LINUX:


One of the most noticeable differences between Linux and Windows is the directory structure. Not only is the format different, but the logic of where to find things is different.
In Windows, you use this format to access a directory

D:\Folder\subfolder\file.txt
In Linux, this is the basic format

/Folder/subfolder/file.txt Youll notice that the slashes are forward slashes in Linux versus backslashes in Windows. Also, there is no drive name (C:, D:, etc.) in Linux. At boot, the root partition is mounted at /. All files, folders, devices and drives are mounted under /. It is important to note that files and folders in Linux are case sensitive. The Directory Structure in UNIX & Linux are a unified Directory Structure where in all the directories are unified under the / Root file system. Irrespective of where the File System is physically mounted all the directories are arranged hierarchically under the Root file system. These are the main directories in LINUX.

/root:
The Directory Structure starts with the Root file system / and is indeed the root directory for the whole structure. The partition where / (the root directory) will be located on a UNIX or UNIX-compatible system.

/boot:
The /boot directory contains the Boot loader files including Grub or LILO, the Kernel, initrd and system.map config files.

/sys:
This contains the Kernel, Firmware and system related files.

/sbin:
This directory contains the essential System Binaries and System Administration tools essential for the system operation and performance.

/bin:
This directory contains the essential binaries for users and those utilities that are required in single user mode. Examples include cat, ls, cp etc.

13

Linux System Administration

/lib:
Contains the library files for all the binaries held in the /sbin & /bin directories .

/dev:
The /dev directory contains the essential system files and drivers.

/etc:
The /etc directory contain essential System configuration files including /etc/hosts, /etc/resolv.conf, nsswitch.conf, defaults and network configuration files. These are mostly host specific system and application configuration files.

/home:
All the user home directories are held under this directory with the exception of the root home directory which is kept under /root directory. This directory holds users files, personal settings like .profile etc.

/media:
This directory is a generic mount point for removable media like CD-ROM, USB, Floppies etc.

/mnt:
This directory is a generic mount point for temporary file systems. This comes handy particularly when troubleshooting from CDROM etc wherein you might have to mount the Root file system and edit configurations.

/opt:
This directory is a rarely used directory in Linux for Optional Software Packages. This is extensively used in UNIX OS like Sun Solaris where the software packages are installed.

/usr:
This directory is a sub hierarchy to the root file system which is a User data directory. It contains user specific utilities and applications. You will again see a lot of important but not critical file systems are mounted. Here you would again find a bin, sbin & lib directory which contains non-critical user and system binaries and related libraries and a share directory.

/var:
The /var directory is mostly mounted as a separate file system under the root where in all the variable content like logs, spool files for printers, mail, running process, lock files etc. Care has to be taken in planning this file system and maintenance as this can fill up pretty quickly and when the File System is full can cause system and application operational issues.

/temp:
This directory is a temporary file system which hold temporary files which are cleared at system reboot. There is also a /var/tmp directory which holds temporary files too. The only difference between the two is that /var/tmp directory holds files that are protected at system reboot. In other words, /var/tmp files are not flushed upon a reboot.

14

Linux System Administration

DIFFERENCE BETWEEN $ AND # SIGN (CONCEPT OF SUPER USER DO [SUDO]):


Number Sign (#) is used to represent the root account which owes all the administrative privileges. And the Dollar sign ($) is for the regular user. Now let us study them in detail. Now let us talk about it in detail. As it is clear that LINUX is a multi-user system, the task of adding/removing users is common. After installing LINUX two user accounts are created. One is root and the other is a regular user. The root account is an account which has all the administrative rights. And the regular user is a user with access to most of the resources but there are some restrictions due to some security reasons. To execute any command while you are a regular user, you will use a word sudo before doing any operation. For example you are a regular user and not the root user, and you want to download and install wine. You will type the following command: $ sudo apt-get install wine(version) Sudo stands for super user do! In your Linux distribution you will see many user accounts like bin, daemon, shutdown, and others etc. Have you ever wondered what these accounts are? These are called the system accounts. These accounts do not have any passwords because they are not designed for login purpose. These accounts are also called no-login accounts. CAUTION!!!!!! - Do not delete them or you will lose the proper functionality of some programs.

ADDING USERS AND GROUPS:


Adding users and groups is very easy. But before we proceed to the technical work, basics should be clear. When we add a user, their information is kept in /home directory. And if you want to see more detailed information about the user, you can check out the passwd and shadow files in /etc directory by using the following commands. cat /etc/passwd to show passwd file. cat /etc/shadow to show shadow file. Passwd file shows you the detailed information about the users but if you want to get more information, you can see the shadow file in the same /etc directory.

15

Linux System Administration

However, the password in /etc/passwd is stored as a single "x" character (i.e. not actually stored in this file). A second file, called /etc/shadow, contains encrypted password as well as other information such as account or password expiration values, etc. The /etc/shadow file is readable only by the root account and is therefore less of a security risk. With shadow passwords, the /etc/passwd file contains account information, and looks like this: Zaeem16:x:561:561:Zaeem Hassan:/home/Zaeem16:/bin/bash Each field in a passwd entry is separated with colon characters : and are as follows:

Username, up to 8 characters. Case-sensitive, usually all lowercase


An "x" in the password field. Passwords are stored in the /etc/shadow file. Numeric user id . This is assigned by the adduser script. UNIX uses this field, plus the following group field to identify which files belongs to the user. Numeric group id . Red Hat uses group ids in a fairly unique manner for enhanced file security. Usually the group id will match the user id. Full name of user. I'm not sure what the maximum length for this field is, but try to keep it reasonable (under 30 characters). User's home directory . Usually /home/username (e.g. /home/smithj). All user's personal files, web pages, mail forwarding, etc. will be stored here. User's "shell account ". Often set to ``/bin/bash'' to provide access to the bash shell (my personal favorite shell). As with the passwd file, each field in the shadow file is also separated with colon characters ":", and are as follows:

Username , up to 8 characters. Case-sensitive, usually all lowercase. A direct match to


the username in the /etc/passwd file. Password , 13 character encrypted. A blank entry (e.g. ::) indicates a password is not required to log in (usually a bad idea), and a ``*'' entry (e.g. :*:) indicates the account has been disabled. The number of days since the password was last changed . The number of days before password may be changed (0 indicates it may be changed at any time) The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years) The number of days to warn user of an expiring password (7 for a full week) The number of days after password expires that account is disabled The number of days since that an account has been disabled A reserved field for possible future use.

16

Linux System Administration

Now let us start adding users step by step: You want to create an account with the name Zaeem Type the command: adduser Zaeem

Now if you want to check out the details related to this user, you can go to the following directory and can view the details about the new user Zaeem. nano /etc/passwd

Now to give a password to this user use the following command and change the password: passwd Zaeem

17

Linux System Administration

Now finally if you want to see the detailed info about this user , go to the following directory and all the details will be visible over there: nano /etc/shadow

If you want to see the password policies related to users, go to this directory: cd /etc/login.def

To see all the groups on your system go to this directory: cat /etc/groups

Now suppose that you have a user Zaeem and there are two groups on the system, named students and the other one teachers. You want to ass this user to both of these groups. To do this, use the following command: useradd Zaeem G teachers, students

Following is another useful technique to add a user:

18

Linux System Administration

Enable/Disable ROOT Account in Linux (Ubuntu!):


In almost all Linux versions root account is enabled, but in some versions root account is disabled by default. Ubuntu is one of the versions of Linux in which root is disabled. Following is the command to enable the root account in Ubuntu: sudo passwd root This will prompt you to set a new password for the root account. And this command is used to disable the root account: sudo passwd l root

File Permissions:
To check the permissions for any file or directory in Linux, simply type the following command and you will get the permissions set on the files and directories: ls -l

File permissions are shown according to the following syntax example:

drwerwerwe
There are a total of 10 characters in this example, as in all Linux files. The first character indicates the type of file, and the next three indicate read, write, and execute permission for each of the three user types, user, group and other. Following table will make you understand the concept of file permissions more clearly: The values for Read, Write and Execute are as follows: R=4 W=2 X=1

19

Linux System Administration

If there is a "-" in a particular location, there is no permission. This may be found in any field whether read, write, or execute field. Lets take an example: A user Zaeem created a directory named MyFile and the group to which this file belongs to is MyGroup. The size of the directory is 124 bytes, and the date created is 12 th April, 2010. Following is the illustration of the given example:

Now the question arises that how to change the permissions of a file/directory. Its simple. Use chmod command.

If you want to change the permissions for the file named Zaeem, so that only user can read and write it and group can only read it, following command will be used. chmod Zaeem u=rw, g+r

Before going towards the numerical configuration, you should understand the concept of umask. The umask command is used to set and determine the default file creation permissions on the system. It is the octal complement of the desired file mode for the specific file type. Default umask is 0022 .Default permissions are: 777 - Executable files 666 - Text files The permission for the creation of new executable files is calculated by subtracting the umask value from the default permission value for the file type being created. An example for a text file is shown with a default umask value of 022:

20

Linux System Administration

It means that a user can read and write the file, and group members and other users can only read the file. In Ubuntu the configuration file is placed in /etc/profile And in Red Hat it is located in /etc/bashrc

Tar and G-zip:


Tar: Tar is a utility used to archive files or folders. The switches used with the tar commands are: z: c: v: f: x: Unzip Create Verbose List Extract

For example you want to zip a directory named MyDir and the tar name is MyDir.bkp, use the following command:

tar<space> cvf<space>MyDir.bkp<space>MyDir
And to untar the same file use the following command:

tar<space> xvf<space>MyDir.bkp
G-zip: This utility is used to zip a file/directory. Use the following to compress the directory named MyDir.tar:

gzip<space>MyDir.tar
21

Linux System Administration

And to unzip use the z switch:

tar<space>zxvf<space>MyDir.tar.gz
This is all about the tar and gzip concept.

Setting JAVA Path in Linux:


You need to setup global config in /etc/profile OR /etc/bash.bashrc files for all users: # vi /etc/profile Next setup PATH / JAVA_PATH variables as follows: My java development kit is placed in /usr directory so I will use the following path: export PATH=$PATH:/usr/java/jdk1.5.0_07/bin Save and close the file. The java path will be set. There are several other methods to set the path. You can search the on the web if youre interested.

Linux Servers:
This is an important section and the first server we are going to cover is telnet server. But before doing this let us study a command through which we will connect the two computers by giving the ip-address to the Linux machine. The command is:

22

Linux System Administration

When you type in this command, following screen will appear: Select the Network Configuration option.

Select the device and assign the ip address and the subnet mask and you are done. You have now given a static ip-address to your Linux Machine. Select ok and then restart the service by typing the following command:

Service network restart This will restart the service and now the server is assigned and configured with a static ip.

23

Linux System Administration

Now lets move towards the installation and proper configuration of different servers.

TELNET SERVER:

WHAT IS TELNET?
Telnet stands for Telecommunications Network. Telnet is based on the telnet protocol that provides the ability to connect to computers or servers over the Internet as well as having the ability to control remote UNIX based systems. Like most Internet applications and protocols telnet uses a standard port number, which in this case is port 23. However different telnet ports can be used by the server that the client is connecting to. Unlike most things, telnet has remained very much the same as it did when it was created and as such has a text based command driven interface, which may deter some but for those who appreciate it find telnet is a very useful tool. Although not widely used anymore, it is still convenient because some commands execute faster over telnet than over the Web or any other similar systems.

How secure is Telnet?


When Telnet was initially developed in 1969, most users of networked computers were in the computer departments of academic institutions, or at large private and government research facilities. In this environment, security was not nearly as much of a concern as it became after the bandwidth explosion of the 1990s. The rise in the number of people with access to the Internet, and by extension, the number of people attempting to hack other people's servers, made encrypted alternatives much more of a necessity. Experts in computer security recommend that the use of Telnet for remote logins should be discontinued under all normal circumstances. The short answer to this is simple, but not very! Telnet is not encrypted at all so if a skilled hacker is listening to a telnet session they could theoretically log all of the data being transferred, including usernames and passwords. There are however more secure variations of telnet available, otherwise known as Secure Shell (SSH). SSH is simply a secure variation of telnet using encryption methods to provide extensive security measures.

24

Linux System Administration

>>>>>How to Access Telnet<<<<<


IMPORTANT INFORMATION:
Before you can start using telnet, you need three pieces of information. First, you need to know the Internet name or unique IP address of the unit you want to communicate with. If you dont know the Internet name of the machine, the IP address will do (usually comes in the form of 255.255.255.255. For example: 192.168.0.255). Second and third, you need a valid username and password to be able to gain access to the server.

BRINGING UP THE TELNET PROGRAM:


Windows has a built-in telnet program that can be accessed from the command window. Other operating systems have their versions, too, and some free programs can also be downloaded from the Internet. To access the telnet program in Windows, bring up the command prompt by going to;

Start>Run and typing cmd.exe. A window with a black background will pop
up. In the command prompt, type telnet Internet name/IP address. For example: telnet professor.nyc.edu. Once connected, you will be prompted to supply your username and password.

IN LINUX:
In Linux operating system telnet utility is not installed by default. We have to install it by ourselves. There are two ways by which we can install TELNET in Linux.

25

Linux System Administration

One is by command line interface and one is using graphic user mode. Both the ways are easy. Let us discuss them one by one.

CLI
In CLI mode we go to Applications>Accessories>terminal.

Log in to ROOT account by using the following command. sudo su. You will be prompted to give the ROOT password. Once youre in the root account, download the Telnet package by typing in apt-get install telnetd The next screen will prompt you for the confirmation to the act. Press y and hit enter. The package will be downloaded and installed on your PC.

GUI:
In GUI mode go to: System>Administration>Synaptic Package Manager.

26

Linux System Administration

In the search tab, type telnetd. And download all the relative packages. This is the easiest way to install telnet.

OPENING THE PORT 23 FOR TELNET:

First of all open the port number 23 to enable telnet services. This can be done by giving the following command: ufw allow 23

LOGGING IN LINUX:
Simply supply the necessary details and press enter. After being verified, you are then taken to the root directory of the machine you have just accessed. If you cant login, verify with your systems administrator that you have permission to access the server. Otherwise, you wont be able to use telnet for your intended purpose.

EXECUTING COMMANDS:
Once inside the machine, you can issue a variety of commands for the other machine to perform. For example, you can type ls l and press enter to see a list of files in the

27

Linux System Administration

current directory. You can also browse files, move them, rename them and copy them. A whole slew of other commands is available by typing ?/help. In Red

Hat:

Package name for telnet is telnet-server AND Service name is xinetd. The configuration files are placed in /etc/xinetd.d/telnet To switch on the From now onwards, red hat version of Linux will be used. So lets start configuring other servers on rhel5.

28

Potrebbero piacerti anche