You are on page 1of 45

Conversational Linux for

the Windows User

Copyright Jonathan Roper

Joe.roper@gmail.com

©JONATHAN ROPER PAGE 1 23/03/2008


1 About the Author

Joe Roper Has had a commercial and operational background


in the transport industry before moving into IT in the mid
nineties, and into communications in the late nineties. Joe is
one of the three lead developers with PBX in a Flash together
with Ward Mundy and Tom King, both of whom have
contributed to this document. Joe is also the Commercial
Director or A2Billing. www.a2billing.net.

A2Billing, licensed under the GPL, when combined with


Asterisk is a physical Telecom Platform and Soft-Switch
providing a wide range of telecoms services using either
traditional telephone technology or VoIP. It contains a real-time
billing engine which rates and bills and invoices calls, and
contains a payment gateway.

Joe is available for consultancy, Googling on "joe roper"+voip or


"joe roper"+wireless will show some of the projects that Joe has
been involved in, which may help establish his credentials.

This document is offered in the hope that it may be useful, but


no warranty for the accuracy of the document is either implied
or given. Please pass on errors and suggestions for
improvement on to joe.roper@gmail.com

This document is released under the creative commons license


– Attribution share. See
http://creativecommons.org/licenses/by-sa/3.0/legalcode

This license lets you remix, tweak, and build upon this work
even for commercial reasons, as long as you credit Joe Roper
and license your new creations under the identical terms. This
license is often compared to open source software licenses. All
new works based on yours will need to carry the same license,
so any derivatives will also allow commercial use.

©JONATHAN ROPER PAGE 2 23/03/2008


2 Table of Contents

1 About the Author...........................................................................................................................................2

2 Table of Contents...........................................................................................................................................3

3 Introduction....................................................................................................................................................7

4 Open Source ...................................................................................................................................................7


4.1 What is Open Source ..............................................................................................................................8
4.2 Can I modify the software?.....................................................................................................................8
4.3 I want to make a Business and sell OSS based products. .....................................................................8
4.4 Can I Sell a Modified Version? ..............................................................................................................9
4.5 I’ve written a killer App for the product; do I need to give it away?....................................................9
4.6 So how do I make money? ....................................................................................................................10

5 Preparation...................................................................................................................................................10
5.1 Virtual Machine ....................................................................................................................................10
5.1.1 VMware........................................................................................................................................10
5.1.2 Microsoft Virtual PC....................................................................................................................11
5.2 Hardware ..............................................................................................................................................11
5.3 PuTTY....................................................................................................................................................12
5.4 WinSCP .................................................................................................................................................12

6 Installation of ISO .......................................................................................................................................13


6.1 Burning the ISO ....................................................................................................................................13
6.2 Installation preparation (Hardware)...................................................................................................14
6.3 Installation (vmware)............................................................................................................................14

7 Webmin.........................................................................................................................................................14

8 Linux for PBX systems ...............................................................................................................................15


8.1 Concept of Linux...................................................................................................................................15
8.2 Why CentOS ..........................................................................................................................................15
8.3 The Command Line...............................................................................................................................16
8.4 GUI – startx...........................................................................................................................................16
8.5 Accessing the System ............................................................................................................................17
8.6 SSH and Putty .......................................................................................................................................17
8.7 SSH and WinSCP..................................................................................................................................18
8.8 SSH ........................................................................................................................................................20
8.9 SCP ........................................................................................................................................................20

9 Linux Filesystem..........................................................................................................................................20
9.1 Linux File System Explained ................................................................................................................21

©JONATHAN ROPER PAGE 3 23/03/2008


9.2 Directories.............................................................................................................................................22
9.2.1 /sbin...............................................................................................................................................22
9.2.2 /bin ................................................................................................................................................22
9.2.3 /boot ..............................................................................................................................................22
9.2.4 /dev................................................................................................................................................22
9.2.5 /etc.................................................................................................................................................23
9.2.6 /home ............................................................................................................................................23
9.2.7 /lib .................................................................................................................................................23
9.2.8 /lost+found....................................................................................................................................23
9.2.9 /mnt ...............................................................................................................................................24
9.2.10 /opt ................................................................................................................................................24
9.2.11 /proc ..............................................................................................................................................24
9.2.12 /root...............................................................................................................................................24
9.2.13 /tmp ...............................................................................................................................................24
9.2.14 /usr.................................................................................................................................................24
9.2.15 /var ................................................................................................................................................25

10 Command Line Construction................................................................................................................25


10.1 Where to get help ..................................................................................................................................25
10.1.1 --help or --h...................................................................................................................................25
10.1.2 man <<command>>.....................................................................................................................25
10.1.3 apropos <<keyword>>.................................................................................................................25
10.1.4 whatis <<keyword>>...................................................................................................................26
10.1.5 tab key...........................................................................................................................................26

11 Filesystem Navigation and Commands................................................................................................26


11.1 # ls..........................................................................................................................................................26
11.2 # cd.........................................................................................................................................................26
11.3 # pwd .....................................................................................................................................................26
11.4 # cp.........................................................................................................................................................26
11.5 # mv........................................................................................................................................................26
11.6 # mkdir...................................................................................................................................................27
11.7 # find......................................................................................................................................................27
11.8 # grep.....................................................................................................................................................27
11.9 # rm........................................................................................................................................................27
11.10 # touch...............................................................................................................................................27
11.11 Links / shortcuts................................................................................................................................27
11.12 # wget ................................................................................................................................................27

12 Disk Usage ................................................................................................................................................28


12.1 # du ........................................................................................................................................................28
12.2 # df .........................................................................................................................................................28

13 Editing and reading files ........................................................................................................................28


13.1 Nano ......................................................................................................................................................29
13.2 WinSCP .................................................................................................................................................29
13.3 # cat .......................................................................................................................................................29
13.4 # less ......................................................................................................................................................29
13.5 # tail.......................................................................................................................................................29

©JONATHAN ROPER PAGE 4 23/03/2008


13.6 # head ....................................................................................................................................................29

14 File Ownership and permissions...........................................................................................................29


14.1 The Basics .............................................................................................................................................29
14.2 Chmod ...................................................................................................................................................30
14.3 Chown....................................................................................................................................................31
14.4 chgrp......................................................................................................................................................31

15 Services .....................................................................................................................................................31
15.1 # chkconfig ............................................................................................................................................32
15.2 /etc/rc.d/rc.local ....................................................................................................................................32
15.3 Stopping services and processes. .........................................................................................................32
15.4 # ps aux..................................................................................................................................................33
15.5 # kill .......................................................................................................................................................33
15.6 # kill -9...................................................................................................................................................33
15.7 # top .......................................................................................................................................................33

16 Reboot and shutdown.............................................................................................................................33


16.1 # reboot..................................................................................................................................................33
16.2 # shutdown –h now ...............................................................................................................................33

17 Pipe............................................................................................................................................................34
17.1 # | ...........................................................................................................................................................34
17.2 Redirect Output.....................................................................................................................................34
17.3 # >..........................................................................................................................................................34
17.4 ## >>.....................................................................................................................................................34

18 Compression ............................................................................................................................................34
18.1 # tar........................................................................................................................................................35
18.2 # gzip......................................................................................................................................................35
18.3 # bzip......................................................................................................................................................35
18.4 # zip & unzip .........................................................................................................................................35

19 Networking...............................................................................................................................................36
19.1 # ifconfig................................................................................................................................................36
19.2 # system-config-network.......................................................................................................................36
19.3 # resolv.conf ..........................................................................................................................................36
19.4 # hostname.............................................................................................................................................37
19.5 # ifdown .................................................................................................................................................37
19.6 # ifup......................................................................................................................................................37
19.7 # ping .....................................................................................................................................................37
19.8 # traceroute ...........................................................................................................................................37
19.9 # mtr.......................................................................................................................................................37

©JONATHAN ROPER PAGE 5 23/03/2008


20 Network Security.....................................................................................................................................37
20.1.1 Iptables..........................................................................................................................................37

21 Installing software...................................................................................................................................38
21.1 Compiling from source .........................................................................................................................38
21.1.1 # make clean.................................................................................................................................38
21.1.2 # ./configure..................................................................................................................................38
21.1.3 # make...........................................................................................................................................38
21.1.4 # make install................................................................................................................................38
21.2 # yum .....................................................................................................................................................38
21.3 # rpm......................................................................................................................................................39

22 Logs ...........................................................................................................................................................39
22.1 /var/log/messages..................................................................................................................................39
22.2 /var/log/dmesg.......................................................................................................................................39
22.3 /var/log/asterisk/full ..............................................................................................................................39
22.4 # logrotate .............................................................................................................................................40

23 Crontab.....................................................................................................................................................40

24 Users and Groups....................................................................................................................................40


24.1 Users......................................................................................................................................................40
24.2 Groups...................................................................................................................................................40
24.3 # sudo.....................................................................................................................................................40

25 Network Services.....................................................................................................................................41
25.1 NTP........................................................................................................................................................41
25.2 DNS........................................................................................................................................................41
25.3 DHCP ....................................................................................................................................................42
25.4 TFTP......................................................................................................................................................42
25.4.1 Option 66......................................................................................................................................42
25.5 Sendmail / Postfix..................................................................................................................................42
25.6 Apache...................................................................................................................................................42
25.7 PHP .......................................................................................................................................................43
25.8 MySQL...................................................................................................................................................43

26 Hardware..................................................................................................................................................43
26.1 # lspci....................................................................................................................................................43
26.2 # cat /proc/interrupts ............................................................................................................................43

27 SSH Tunnelling........................................................................................................................................43
27.1 Example One.........................................................................................................................................44
27.2 Example Two.........................................................................................................................................44

28 Conclusion................................................................................................................................................45

©JONATHAN ROPER PAGE 6 23/03/2008


3 Introduction

The purpose of the manual is to explain some basic commands


for Linux to the Windows user, to give them confidence to use
Linux.

Linux, in the PBX environment does not usually have a


graphical user interface. However even if it did, it would be
more complicated to explain that then to simply use the
command line interface.

Linux differs from Windows in that a range of windows


Managers and graphical user interfaces can be used, the most
popular of which are Gnome and KDE.

The following sections should give some techniques that the


user, more familiar with Windows, can use to manage and
configure their PBX system.

This manual concentrates on the CentOS (Community


Enterprise Operating System) as this is one of the most widely
used in PBX deployments. It is based on Red Hat Enterprise
Linux (RHEL) and is supported for seven years after release.

By the time you have practiced the commands in this manual,


you should have “Conversational Linux”

4 Open Source

There has been an explosion and growth of open source


software in the last few years, especially in the telecoms market.
Open Source software in many cases is every bit as good as the
commercial equivalent.

The first thing to understand is that Open Source Licensing is


in no way anti-commercial. OSS software is, and always has
been commercial. What it is, is Anti Lock in.

For your customers, OSS is a huge selling point. They will


always be able to get support for their product, even if they do
not buy it from you. If you do a good job, then of course they
will have no reason to move.

©JONATHAN ROPER PAGE 7 23/03/2008


4.1 What is Open Source
Open Source software is software that is released under a
license that allows you to modify the program to suit yourself.
Open Source is generally but not always free of charge. Open
Source software used to be called Free Software. The Free in the
name DID NOT refer to the price, but to the Freedom to modify
and alter the program.

One of the most popular licenses is GPL v2 –

http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.

There is a GPL v3, but this has not been widely adopted as yet.

The idea with OSS software is that you can contribute to the
development of the product, and enjoy the fruits of your labour.
The code can be inspected by your peers, and commented
about publicly. This concentrates the mind to do it properly.

A worthwhile read is the Beekeeper analogy

http://wiki.pentaho.org/display/BEEKEEPER/The+Beekeeper

The advice below is based opinion, and before making


commercial decisions based on this advice, you would be
advised to do your own research.

4.2 Can I modify the software?


If the software is for your own use, you can do whatever you
want with it. There are no restrictions of any note. However, if
you are going to re-distribute or sell your software, read on.

It is a good idea to return your modifications back to the


community for inclusion in future releases. In this way, when a
new feature is added, you may not have to re-apply your
modifications, and the product gets ever better.

Remember that the copyright is still held by the original


developer, so if you take a script, copy it, and pass it off as your
own, and place your own copyright on it, that is illegal, and
morally wrong.

4.3 I want to make a Business and sell OSS based products.


You may redistribute GPL software, and indeed you may make
a charge for the software. You must give the same rights to your
customers as you have received from the original distributor of
the OSS software. So given that you have the right to modify the

©JONATHAN ROPER PAGE 8 23/03/2008


software, so does your customer. They also have the right to
redistribute the software as well.

You can make more money by adding other elements to the


sale, such as hardware, guarantees, training, and support

4.4 Can I Sell a Modified Version?


Yes, you can make modifications to the software. However, any
changes that you make to the software must be clearly marked
and commented. If you make a mistake and break something,
the reputations of the original developers should not be
affected.(Section 2a of the GPL)

Additionally, under the terms of the GPL, you must make your
modifications freely (as in make no charge) available to any and
all third parties, e.g. post a link to it on your website. (Section
2b of the GPL)

So you can re-brand as your own? The basic tenant of


Copyright law is that it gives the copyright holder the right to be
credited for the work. In order to be sure, you would need to
take legal advice, or simply ask permission of the copyright
holder. The copyright law is nothing to do with the GPL.

However, it is good manners, and a good strategy to talk to the


original developers to get them to provide or give permissions
fort a re-branded system, for which they make a charge which
goes to support the project, and of course, updates and changes
to the original code are unlikely to break your customised copy,
and of course you stay in the development loop.

4.5 I’ve written a killer App for the product; do I need to give it
away?
You may write an application or modification to the product,
but do not want to release the code as it gives you a competitive
advantage. The answer to this is a little more grey, and to a
great degree, depends on your moral radar’

A suggested guideline is that if you have to modify the original


released code in order to make your application work, then your
work will have to fall under the GPL. If you do not release the
code to the GPL, then you could be in breach of the license, and
lose the right to use the product. (Section 4 of the GPL)

If the code communicates at arms length from the original code,


then that is acceptable. (Read Section 2c carefully)

©JONATHAN ROPER PAGE 9 23/03/2008


4.6 So how do I make money?
Providers of OSS software want you to make money from their
work. That’s the point. Of course they would also like money
and receive help as well.

There are a number of ways that both the provider of the OSS
software and the reseller can make money from OSS.

1. If the code is an original work, licensed under the GPL, then


the developers and project owners may make a charge for
the software. The purchaser of the software can resell the
software if they wish, or indeed give it away if they so desire.
After all, they still own the copyright.

2. Sell installation services, support and guarantees with the


product, See Digium as an example of this.

3. Provide other Value Add Services, e.g. minutes and DID for
PBX services.

4. Provide and sell documentation for the project.

5. Provide a service for updating and fixing the product.

5 Preparation

To work through the exercises below, a test machine is


required, virtual or real, as well as some useful tools to be
downloaded from the internet. An internet connection is also
required.

5.1 Virtual Machine


A virtual machine is a program that allows operating systems to
run in a window on a Windows, Linux or Mac PC. For the
purposes of this manual, we will be concentrating on Windows.
Note that it is not generally possible to run a production PBX on
a virtual PC or server.

Installing a virtual machine on a PC will not affect any existing


data on the server.

5.1.1 VMware

VMware from, www.vmware.com is one of the most popular


virtual environments, as it supports all the major operating
systems.

©JONATHAN ROPER PAGE 10 23/03/2008


In our case we only need VMware player, which will play an
existing VMware image. VMware player is free of charge, but
you do have to register to download it.

You will need a VMware hard disk, and the .vmx configuration
file. The .vmx file controls the attributes of the virtual machine,
such as the memory, presence of network interfaces, the
CDRom etc. It is a text file can be edited with notepad or
wordpad. There is a blank hard disk and basic configuration file
available from: -

http://www.pbxinaflash.com/downloads/pbxinaflash.zip

Alternatively, you can upgrade to VMware server, which has a


cost, to create your own VMware disks.

There is also a free open source program called VMX Builder,


which will allow you to create your own hard disks and
machine configurations. This can be found at: -

http://petruska.stardock.net/software/VMware.html

5.1.2 Microsoft Virtual PC

There is another virtual machine program available to you


called Virtual PC, which is a free download from Microsoft.

This is available from:-

http://www.microsoft.com/windows/products/winfamily/virtu
alpc/default.mspx

For server grade hardware, Microsoft Virtual Server is also


available.

During the installation of Microsoft Virtual PC, there may be


warnings about the operating system not being compatible.
This is the case with Windows XP home edition. Note the
warnings and continue with the install. There seem to be no
side effects to installing VPC with Windows XP, despite the
warnings.

5.2 Hardware
Almost any hardware will do to run Linux on. Bear in mind that
most Linux installs will delete any data on the PC, so do not
install your main machine.

©JONATHAN ROPER PAGE 11 23/03/2008


Hardware that should be excluded with CentOS 5, the OS we
will be using for this manual, is anything with an i586
architecture, as this is not supported. An example of this
hardware would be a Via EPIA C3 processor.

10Gb is more than sufficient for the hard drive. 256Mb of RAM
or more is recommended.

Motherboards with onboard LAN may or may not be supported.


It has been noted that Nvidia chipsets do have problems
recognising the LAN, so it may be necessary to buy a network
card to circumvent this problem. It will only be a matter of time
before CentOS provides the drivers for more modern hardware.

The advice is to research the motherboard on the internet to see


if there are likely to be any compatibility problems.

5.3 PuTTY

PuTTY is a windows program used to remote manage Linux


machines from the command line. It gives a window onto the
Linux machine, and any commands typed into the Putty
window are executed on the remote machine.

Putty is available from


http://www.chiark.greenend.org.uk/~sgtatham/putty/

It is one executable file, so it can be run from a Windows


desktop without needing to install it on the machine. It can be
simply deleted afterwards if you are on a guest on some else’s
machine.

Putty is free of charge

5.4 WinSCP
WinSCP is a program similar to Windows Explorer. It is a good
program for those more used to Windows than they are to the
command line.

It allows drag and drop copying to and from the desktop, as well
as changing permissions on files, editing files, and running non
interactive commands.

WinSCP is available from http://winscp.net/eng/index.php

©JONATHAN ROPER PAGE 12 23/03/2008


Note that this program is installed into Windows, so it may not
be suitable for installing on a guest PC.

WinSCP is free of charge

6 Installation of ISO

One can download the ISO’s prepared by the various PBX


aggregators such as PBX in a Flash, or CentOS can be
downloaded from the CentOS website.

There are ISO images on DVD and CD for many different


computer architectures. The one we will most likely to be
interested in is the i386 architecture. However, modern
hardware and processors often support 64bit operating
systems, so you may also wish to try the x86_64 download as
well, which will make full use of the architecture and 64 bit
capabilities.

64 bit machines can address far more memory. Typically, 32 bit


architecture can only address up to 4Gb of memory, whereas
64 bit can address considerably more. Any more than 4Gb of
memory on a 32 bit operating system is a waste of money,
unless a special kernel is compiled.

6.1 Burning the ISO


When the ISO has been downloaded e.g. pbxinaflash.iso it
needs to be burnt to a CD.

An ISO image is an image of the disk, which tells the CD burner


where to put the relevant files and directories. It is not sufficient
to simply copy the ISO onto the CD, it needs to be burnt
properly.

The usual, most popular tool to do this is Nero. This program is


often bundled with PC’s from OEM distributors.

Depending on the version, look for “Burn CD image”

If Nero is not available, then there is a Windows power toy


available from
http://isorecorder.alexfeinman.com/isorecorder.htm
which will burn an ISO image onto CD.

©JONATHAN ROPER PAGE 13 23/03/2008


Note that on virtual machines, it is not necessary to burn the
ISO to a physical CD, as the VM image allows you to mount the
ISO image as if it was a physical CD.

6.2 Installation preparation (Hardware)


The first job is to make the machine bootable from the CDROM
drive. Hardware varies, but in most cases it is necessary to
enter the BIOS, often by pressing F2, or del during the initial
boot up. Once the BIOS is open, then the boot order can be
altered so it boots from CD first, and then the hard drive.

In other cases, it may be necessary to press a key combination


to enter the boot options, e.g. F12. This allows you to select the
boot device. Chose CDROM.

For machines without a CDROM, a USB CDROM drive may


have to be purchased, and a modern PC should boot from a
USB interface. This may not be the case with older machines.

Ensure that all data that you want to keep has been backed up.

To check that the CD is in good order, then at the boot of the


CD, type linux mediacheck.

6.3 Installation (vmware)


On a fresh virtual machine, there will be no requirement to do
any preparation apart from to ensure that the ISO image is in
the right place relative to the VM image. For VMware, open the
.vmx file and find the line which points to the ISO e.g.

ide0:1.fileName = "c:\ippbx\concordiax.iso"

Ensure it points to the filename of the ISO image.

In Microsoft VPC, simply check the properties and options.

Future installations over the top of existing installs will require


you to bring up the boot order menu. In VMware, press escape
as the system boots. Be quick or you will miss it.

7 Webmin

Webmin is the swiss army knife of Linux administration for the


Linux Conversational. It simplifies changes to be made to the
system. It allows the configuration of Linux though a web based
UI, which runs separately in its own process.

©JONATHAN ROPER PAGE 14 23/03/2008


Webmin is a web based application. By default, it is installed on
port 10,000 however that port is sometimes changed for
security. E.g. PiaF puts Webmin on 9001.

To access Webmin, type the URL of your server appended with


“:10000” e.g. http://myserver.com:10000 or in some cases
https://myserver.com:10000

If Webmin is installed after the operating system, the password


is usually the same as the root password. However, if it is
installed with the OS, then the password has to be set
separately.

8 Linux for PBX systems

8.1 Concept of Linux


Linux is based on Unix which is a very mature operating
system. Linux is known to be very robust, and suits “always on”
applications as it can be run for many years without needing a
reboot.

The stability is maintained by the mindset of most Linux


developers. Most Linux programs only do one thing, but do it
really well.

The make up of most operating systems is based on a layered


model, and programs and functions only talk to their direct
neighbours. E.G.

- Hardware talks to the Kernel


- The Kernel talks to applications.

In this way the kernel knows all about the hardware in a


machine, and does not allow applications to talk directly to the
hardware, which may cause a conflict.

Thus, whenever new hardware is added, it may be necessary to


recompile the kernel, or compile the hardware drivers against
the kernel so that they know how to interact with each other.

8.2 Why CentOS


A quick Google will throw up a lot of Linux distributions which
have their own positives and negatives. People are as loyal to
their particular distribution as they are to their football team.

©JONATHAN ROPER PAGE 15 23/03/2008


There are advantages and disadvantages to them all, but, a
choice as to be made, in this case, CentOS has been chosen.

CentOS is Redhat Linux with all the branding taken out. RHEL
is not usually available free of charge, and requires an annual
support fee, and as such, has lots of paid developers working
on the system. Not surprisingly, this allows it to spend more
money on the development and support of hardware, and has
been adopted as the defacto distribution for servers.

Fedora Core is the hairy bleeding edge of RHEL. Older versions


of Fedora Core cascade into RHEL, which in turn is released as
CentOS.

CentOS is distributed completely free of charge, and is licensed


under the GPL.

The reasons for choosing Centos, is that enjoys the same


benefits of RHEL. RHEL updates are usually ported into
CentOS within 72 hours of them becoming available.

CentOS is maintained for seven years after release, so the


current 5.1 release is set to be supported until 2014.

A side benefit is that if you were to ever release a PBX where the
customer wanted to have some guarantees about the stability, a
PBX could easily be built using RHEL and Asterisk Business
Edition.

For more information on Centos, see www.centos.org

8.3 The Command Line


With a PBX install, it is not usually necessary to spend too long
at the command line. Only long enough to configure the
hardware, software and network and do any trouble shooting
that may be required. After this time, most configurations are
done via web pages.

8.4 GUI – startx


Graphical user interfaces (also known as X) can be installed to
CentOS, and there are a few choices. However, GUI’s are rarely
installed on Servers, as servers are rarely touched once
installed. GUI’s use quite a lot OS system resources. If no one is
looking at the GUI, then there is no point in one being present.

©JONATHAN ROPER PAGE 16 23/03/2008


Having said that, the amount of resources required to run a
GUI on a modern server is only a small percentage of the
available power.

If a GUI has been installed, then it can be started with the


command startx. When you have finished with the GUI, it can
be stopped with the key combination CTRL-ALT-BACKSPACE.

8.5 Accessing the System


The main method of accessing the server is via a protocol called
SSH. Secure Shell. The commands and screen output is
encrypted, so it is a secure method of connecting.

SSH is a TCP connection on port 22. For a public server, this


may need to be changed to a non standard port.

8.6 SSH and Putty


To access the command line from Windows, PuTTY has to be
launched. It will bring up a screen as below:-

©JONATHAN ROPER PAGE 17 23/03/2008


Simply fill in the IP address or hostname and click open.

You will then be prompted for the username - usually root,


press enter, then type the password. As you are typing the
password, there will be no screen output, so just keep typing
and press enter.

If authenticated properly, then you will end up in your home


directory. In the case of root, you will be in the /root directory

When first connecting to a Linux machine, you will get a


prompt if you have never connected before. Accept this prompt.
If you have connected to the machine before and you get this
prompt, and then ensure that you have not been redirected to
another machine.

To copy a command from the Windows desktop, right click and


copy the text, click in the Putty window and right click. This will
paste the contents of the clipboard into the remote machine at
the command prompt.

To copy from the Putty window, simply highlight the text to be


copied. This places the text on the windows clipboard. Right
click to paste the text at the command prompt, or paste the
contents into another Windows application

8.7 SSH and WinSCP


WinSCP is a program which gives you a window onto the
remote machine.

©JONATHAN ROPER PAGE 18 23/03/2008


WinSCP also comes with its own internal text editor.

©JONATHAN ROPER PAGE 19 23/03/2008


8.8 SSH
It is possible to ssh from one Linux machine to another. Simply
type ssh ipaddress or ssh root@ipaddress.

8.9 SCP
Secure copy. Copy a file. Using the SCP protocol, copy files from
one Linux machine to another.

9 Linux Filesystem

The Linux file system has a number of partitions. At its most


simple, it contains three partitions: -

- The boot partition – this contains the mechanism to boot the


system.
- The Swap partition – This is where stuff held in RAM is
shifted to the hard drive, which pretends to be RAM, albeit,
very much slower.
- The main file system – this contains the files and folders as
well as applications.

There is no need to worry about this too much. For the


moment, just go with the options offered to your doing the
install.

©JONATHAN ROPER PAGE 20 23/03/2008


9.1 Linux File System Explained
Original article by Mayank Sarup mayank@freeos.com Posted: (2001-01-03
10:08:44 EST http://www.freeos.com/articles/3102 )

The first thing that most new users shifting from Windows will
find confusing is navigating the Linux file system. The Linux file
system does things a lot more differently than the Windows file
system. This article explains the differences and takes you
through the layout of the Linux file system.

For starters, there is only a single hierarchal directory


structure. Everything starts from the root directory, represented
by '/', and then expands into sub-directories. Where
DOS/Windows had various partitions and then directories
under those partitions, Linux places all the partitions under the
root directory by 'mounting' them under specific directories.
Closest to root under Windows would be c:.

Under Windows, the various partitions are detected at boot and


assigned a drive letter. Under Linux, unless you mount a
partition or a device, the system does not know of the existence
of that partition or device. This might not seem to be the easiest
way to provide access to your partitions or devices but it offers
great flexibility.

This kind of layout, known as the unified file system, does offer
several advantages over the approach that Windows uses. Let's
take the example of the /usr directory.

This directory off the root directory contains most of the system
executables. With the Linux file system, you can choose to
mount it off another partition or even off another machine over
the network. The underlying system will not know the difference
because /usr appears to be a local directory that is part of the
local directory structure! How many times have you wished to
move around executables and data under Windows, only to run
into registry and system errors? Try moving c:/windows/system
to another partition or drive. (No; Don't!!!)

Another point likely to confuse new users is the use of the


frontslash '/' instead of the backslash '' as in DOS/Windows. So
c:\windows\system would be /c/windows/system. Well, Linux
is not going against convention here. Unix has been around a
lot longer than Windows and was the standard a lot before
Windows was. Rather, DOS took the different path, using '/' for
command-line options and “\” as the directory separator.

©JONATHAN ROPER PAGE 21 23/03/2008


To liven up matters even more, Linux also chooses to be case
sensitive. What this means that the case, whether in capitals or
not, of the characters becomes very important. So this is not
the same as THIS or ThIs for that matter. This one feature
probably causes the most problems for new users.

9.2 Directories
We now move on to the layout or the directory structure of the
Linux file system. Given below is the result of a 'ls -p' in the root
directory.

bin/ dev/ home/ lost+found/ proc/ sbin/ usr/ boot/ etc/ lib/
mnt/ root/ tmp/ var/

9.2.1 /sbin

This directory contains all the binaries that are essential to the
working of the system. These include system administration as
well as maintenance and hardware configuration programs.
Find lilo, fdisk, init, ifconfig etc here. These are the essential
programs that are required by all the users. Another directory
that contains system binaries is /usr/sbin. This directory
contains other binaries of use to the system administrator. This
is where you will find the network daemons for your system
along with other binaries that only the system administrator
has access to, but which are not required for system
maintenance, repair etc.

9.2.2 /bin

In contrast to /sbin, the bin directory contains several useful


commands that are used by both the system administrator as
well as non-privileged users. This directory usually contains the
shells like bash, csh etc. as well as much used commands like
cp, mv, rm, cat, ls. There also is /usr/bin, which contains other
user binaries. These binaries on the other hand are not
essential for the user. The binaries in /bin however, a user
cannot do without.

9.2.3 /boot

This directory contains the system map file as well as the Linux
kernel. Lilo places the boot sector backups in this directory.

9.2.4 /dev

This is a very interesting directory that highlights one important


characteristic of the Linux file system - everything is a file or a

©JONATHAN ROPER PAGE 22 23/03/2008


directory. Look through this directory and you should see hda1,
hda2 etc, which represent the various partitions on the first
master drive of the system. /dev/cdrom and /dev/fd0 represent
your CDROM drive and your floppy drive. This may seem
strange but it will make sense if you compare the
characteristics of files to that of your hardware. Both can be
read from and written to. Take /dev/dsp, for instance. This file
represents your speaker device. So any data written to this file
will be re-directed to your speaker. Try 'cat /etc/lilo.conf >
/dev/dsp' and you should hear some sound on the speaker.
That's the sound of your lilo.conf file! Similarly, sending data to
and reading from /dev/ttyS0 ( COM 1 ) will allow you to
communicate with a device attached there - your modem.

9.2.5 /etc

This directory contains all the configuration files for your


system. Your lilo.conf file lies in this directory as does hosts,
resolv.conf and fstab. Under this directory will be X11 sub-
directory which contains the configuration files for X. More
importantly, the /etc/rc.d directory contains the system start-
up scripts. This is a good directory to backup often. It will
definitely save you a lot of re-configuration later if you re-install
or lose your current installation.

9.2.6 /home

Linux is a multi-user environment so each user is also assigned


a specific directory which is accessible only to them and the
system administrator. These are the user home directories,
which can be found under /home/username. This directory
also contains the user specific settings for programs like IRC, X
etc.

9.2.7 /lib

This contains all the shared libraries that are required by


system programs. Windows equivalent to a shared library
would be a DLL file.

9.2.8 /lost+found

Linux should always go through a proper shutdown. Sometimes


your system might crash or a power failure might take the
machine down. Either way, at the next boot, a lengthy file
system check using fsck will be done. Fsck will go through the
system and try to recover any corrupt files that it finds. The
result of this recovery operation will be placed in this directory.
The files recovered are not likely to be complete or make much

©JONATHAN ROPER PAGE 23 23/03/2008


sense but there always is a chance that something worthwhile
is recovered.

9.2.9 /mnt

This is a generic mount point under which you mount your file
systems or devices. Mounting is the process by which you make
a file system available to the system. After mounting your files
will be accessible under the mount-point. This directory usually
contains mount points or sub-directories where you mount
your floppy and your CD. You can also create additional mount-
points here if you want. There is no limitation to creating a
mount-point anywhere on your system but convention says
that you do not litter your file system with mount-points.

9.2.10 /opt

This directory contains all the software and add-on packages


that are not part of the default installation. Generally you will
find KDE and StarOffice here. Again, this directory is not used
very often as it's mostly a standard in Unix installations.

9.2.11 /proc

This is a special directory on your system that is a pseudo file


system held in memory and tracks running processes on the
machine. Most of the information is /proc is updated live to
match the current state of the operating system.

9.2.12 /root

We talked about user home directories earlier and well this one
is the home directory of the user root. This is not to be confused
with the system root, which is directory at the highest level in
the file system.

9.2.13 /tmp

This directory contains mostly files that are required


temporarily. Many programs use this to create lock files and for
temporary storage of data. On some systems, this directory is
cleared out at boot or at shutdown.

9.2.14 /usr

This is one of the most important directories in the system as it


contains all the user binaries. X and its supporting libraries can
be found here. User programs like telnet, ftp etc are also placed
here. /usr/doc contains useful system documentation.

©JONATHAN ROPER PAGE 24 23/03/2008


/usr/src/linux contains the source code for the Linux kernel. If
you are compiling programs from source such as Asterisk, you
would put the source files under /usr/src

9.2.15 /var

This directory contains spooling data like mail and also the
output from the printer daemon. The system logs are also kept
here in /var/log/messages. You will also find the database for
BIND in /var/named and for NIS in /var/yp.

This was a short and basic look at the Linux file system. You do
need to have at least this basic knowledge of the layout of the
file system to fully utilize its potential. One good place to read
about the file system is this detailed document at
www.pathname.com/fhs/1.2/fsstnd-toc.html that specifies the
standard structure of the Linux file system.

10 Command Line Construction

Most Linux commands are formed in the same way: -

Command – options Filename

Below is a list of resources on the server to get information on a


particular command.

10.1 Where to get help

10.1.1 --help or --h

Typing a command followed with –help will generally give a


quick aide memoire on the command

10.1.2 man <<command>>

man stands for Manual. Type man followed by the command


line for a complete guide to how the command works, and what
it does. Press “q” to exit man, space to page down, and enter to
go one line at a time.

10.1.3 apropos <<keyword>>

If you cannot remember the command, apropos followed by a


keyword will return all commands that have that keyword in
the command on in its description.

©JONATHAN ROPER PAGE 25 23/03/2008


10.1.4 whatis <<keyword>>

Whatis is very similar to apropos. Before it can be used, run


/usr/sbin/makewhatis

10.1.5 tab key

The tab key will auto-complete either a command or a filename,


pressing it twice in succession will return all options.

11 Filesystem Navigation and Commands

There are a number of commands that are useful for navigating


around the filesystem, and performing operations on the
filesystem. There are usually a number of options with each
command that change the output or behaviour of the
command. Type <<command>> -h for more information of the
command or man <<command>> to get a complete description.

11.1 # ls
Like dir in Dos, it lists the current directory. It lists the contents
of the current directory. With the –al switch, it displays the
permissions and ownership of the files as well.

11.2 # cd
Change Directory, type cd /path/to/directory cd / takes you to
the root of the filesystem, while cd ~ takes you to your home
directory. cd .. takes you up one directory level.

11.3 # pwd
Tells you where you are in the directory system.

11.4 # cp
copy, copies a file from one place to another, e.g cp file.txt ~
would copy the file.txt to your home directory. You can copy
recursively, e.g the directory and all subdirectories using the –r
switch

11.5 # mv
Moves a file from one location to another. This is also a popular
method of renaming a file. E.g. mv file.txt newfile.txt would
rename file.txt to newfile.txt

©JONATHAN ROPER PAGE 26 23/03/2008


11.6 # mkdir
mkdir <<directory name>> make a new directory.

11.7 # find
Find a file on the file system. This is memory intensive, so if the
system is being used as a PBX, it may cause some voice quality
issues. The usual syntax is find –name filename. Wildcards can
be used such as * Note that the find command only looks in the
current directory and all sub directories. So to search the
complete file system, you need to either do cd / to get to the
root of the file system,, or find / -name name* to find all files
that begin with name.

11.8 # grep
Searches the contents of the files for the word stated – e.g. grep
-i tom would find all files with the word “tom” in them.

11.9 # rm
Remove a file, Note that there is no undelete command, or
recycle bin in Linux, so when a file is deleted, it is gone for ever.
A tip to ensure that there are no mistakes is to try the
command substituting ls for rm. E.g. to remove all files that end
in txt you may want to type rm *.txt but try the command ls
*.txt to ensure that it does what you think it is going to do. The
–r switch deletes all subdirectories and their files. The –f forces
the delete, and does not prompt, so if you have a large directory
and subdirectory to delete, then a valid command would be rm
–rf * which would delete everything in the current directory.

11.10 # touch
Create an empty file. E.g. touch newfile.txt will create a new file
called newfile.txt in the current directory.

11.11 Links / shortcuts


The concept of shortcuts is available in Linux using the ln
command. Make a link from a directory to a file or directory.

11.12 # wget
Downloads a file from the internet using http. E.g. wget
www.mysite.com/filename.txt

©JONATHAN ROPER PAGE 27 23/03/2008


12 Disk Usage

12.1 # du
Shows the contents, directory and file sizes.

12.2 # df
Shows the current disk usage. Note that if a hard drive becomes
full. Linux will cease to work, and may become inaccessible to
SSH. Where you are running an FTP site, it may be a good idea
to put the FTP site on it’s own partition so that it’s becoming
full does not cause problem with the operating system.

13 Editing and reading files

There are a large number of text editors available. We will cover


Nano in this document, as it is easy for the beginner to use,
with plenty of help.

Note that files created in Windows applications such as Notepad


or WordPad may not work on Linux systems because of the non
standard way the Windows puts carriage returns and line
breaks into files. Additionally, files that are moved via a
Windows using the FTP ascii protocol may also be damaged
because of this line feed issue. I would advise that all files are
edited and moved within Linux.

In most files, the “#” denotes that the following characters are
simply comments. However, in Asterisk Dial plans, # means
include the named file. Comments are denoted by a semi-colon
“;”

Other file types are commented differently

<!--- This is an HTML Comment -->

// This is a PHP comment for a single phrase

/* this comments out


several lines in PHP code */

©JONATHAN ROPER PAGE 28 23/03/2008


13.1 Nano
Nano is a GPL’d text editor for use at the Linux command line.
To open or create a new file, type nano –w filename.txt The –w
switch helps the system to read punctuation and make it more
readable.

When done editing type CTRL X Y Enter

13.2 WinSCP
WinSCP can be used for editing files in a familiar Windows
interface, simply right click on the file to edit, and click edit.
Save when done.

13.3 # cat
Cat lists the entire contents of a file in one go.

13.4 # less
Lists the contents of a file one page at a time. Press q to exit.
E.g. less myfile.txt

13.5 # tail
Lists the last 10 lines of a file. There are switches to change this
value. Tail –f logfilename shows the log in realtime.

13.6 # head
Lists and displays the top 10 lines of a file.

14 File Ownership and permissions

Every file is owned by one of the users on the system.


Depending on the permissions assigned to that file depends on
whether a file can be viewed, edited and executed.

14.1 The Basics


Typing ls –al shows all the files and directories, with their
ownership.

There are 10 entries showing the permissions. For example: -

-rw-r--r-- 1 root root 23237 Feb 13 17:56 install.log

©JONATHAN ROPER PAGE 29 23/03/2008


drwxr-xr-x 2 root root 4096 Feb 14 00:08 centos-cd1

The first letter can be a:-


- = file
- d = directory
- l = link

The next sections total 9 characters, and can be divided into


three.

- 1,2,3 = Owner permissions


- 4,5,6 = Group Permisions
- 7,8,9 = Others - Everyone else

Each section can have read, write and execute permissions. (r x


and w)

14.2 Chmod
(Parts reproduced from http://www.freeos.com/articles/3127/ By Mayank Sarup)

The command chmod modifies the permissions. It uses a


system of numbers to apply the permissions.

At its simplest, you can add execute permissions to a file simply


by typing chmod +x somefile, which would add executable
permissions to somefile.

There is another way in which you can specify the file


permissions. The
permission bits r,w and x are assigned a number.

- r=4
- w=2
- x=1

Now you can use numbers, which are the sum of the various
permission bits.
E.g - rwx will be 4+3+1 = 7. rx becomes 4+1 = 5. The chmod
command now
becomes chmod xyz filename where x,y and z are numbers
representing the permissions of user, group and others
respectively. Each number is the sum of the permissions to be
set and are calculated as given above.

Chmod 644 somefile

- 6 = 4 + 2 = rw
- 4=r
- 4=r

©JONATHAN ROPER PAGE 30 23/03/2008


As you can see, the permissions for somefile are being set to -
rwr--r--. This is a simpler and quicker way of setting the file
permissions. Refer to the table below as a quick reference.

- 0 - ---
- 1 - --x
- 2 - -w-
- 3 - -wx
- 4 - r—
- 5 - r-x
- 6 - rw-
- 7 – rwx

Tip: The easiest way to set the permissions is to right click on the file or
directory in WinSCP, select properties. You can then tick the permission
you want to allow.

14.3 Chown
In addition to the file permission, you can also modify the
owner and group of the file. The chown program is used here
and its syntax is very simple. You need to be the owner of a file
or root to do this.

chown new-owner somefile

Or to change the owner and the group recursively

# chown –R Group:Owner /path/to/directory

14.4 chgrp
To change group, user the chgrp command. Syntax is similar to
chown. You
will need to be the owner of the file and also belong to the same
group as
the file, or you should be root.

chgrp new-grp somefile

15 Services

Services on a Linux system are often known as Daemons. They


typically run in the background and are launched at boot time.

©JONATHAN ROPER PAGE 31 23/03/2008


Typically, daemons end with a d as in sshd for the SSH service
or Daemon. Services can be stopped, started, restarted and the
status queried:-

Service <<Daemon Name>> status | start | stop |restart

15.1 # chkconfig
To start services automatically at boot time, the chkconfig
command is used.

However, we need to know which run level is used. Normally


this is three for our purposes.

The run levels for CentOS are as follows: -

- 0 - Halt
- 1 - Single user
- 2 - Not used/User definable
- 3 - Full multi-user, console logins only
- 4 - Not used/User definable
- 5 - Full multi-user, with display manager as well as
console logins
- 6 - Reboot

So if we want the SSH server to run in levels 3, 4 and 5 we


would type: -

# chkconfig --level 345 sshd on

to turn it off:-

# chkconfig --level 345 sshd off

In order to discover what services are running type

# chkconfig –list

15.2 /etc/rc.d/rc.local
This file is like the windows startup folder. Processes and
scripts can be launched from here at the end of the boot
process.

15.3 Stopping services and processes.


Usually an active session, such as a find, which is taking a long
time can be stopped pressing CTRL C

©JONATHAN ROPER PAGE 32 23/03/2008


However sometimes, it is impossible to stop a service, so
something more dramatic has to be used. This is the Linux
equivalent of CTRL-ALT-DEL in Windows

The first thing to discover is the process ID, or the PID.

15.4 # ps aux
Shows a list of running processes, with the PID and some other
metrics

15.5 # kill
Kills the process. Kill 235 where 235 is the PID to kill

15.6 # kill -9
Force kills the process kill -9 235 force kills the PID

15.7 # top
Shows the running processeswith the most processor intensive
at the top. This displays in real-time.

16 Reboot and shutdown

16.1 # reboot
Reboots the Server

16.2 # shutdown –h now


Usage: shutdown [-akrhHPfnc] [-t secs] time [warning
message]
-a: use /etc/shutdown.allow
-k: don't really shutdown, only warn.
-r: reboot after shutdown.
-h: halt after shutdown.
-P: halt action is to turn off power.
-H: halt action is to just halt.
-f: do a 'fast' reboot (skip fsck).
-F: Force fsck on reboot.
-n: do not go through "init" but go down real fast.
-c: cancel a running shutdown.
-t secs: delay between warning and kill signal.
** the "time" argument is mandatory! (try "now") **

©JONATHAN ROPER PAGE 33 23/03/2008


17 Pipe

17.1 # |
The pipe command allows the output of one command to be
piped into the input of another command.

17.2 Redirect Output


The > symbol redirects output from a command to another
destination such as a file so you can analyse the contents at
your leisure.

e.g. ls –al > list.txt willl send the output of ls –al to a the text
file; list.txt

17.3 # >
Appends to the end of an existing file.

17.4 ## >>
Clears the file first.

18 Compression

In order to compress a file, or amalgamate a large number of


files into one large file, the following commands can be used, or
a directory or file can be compressed using the WinSCP utility.

Strictly speaking, TAR, derived from tape archive is not really


used for compression. The same extraction command will work.
Note that unTAR’ing a TAR file extracts the files into the same
directory tree in which they were stored beginning at the
location from which the command is executed. Thus, if
/var/myfile.txt is included in the archive, then extracting the
archive from the root directory would place the file in /var while
extracting the archive from /junk would place the file in
/junk/var.

There's another beauty and curse to tarballs. They preserve the


ownership and permissions of the original files which are
included in the archive. This includes the ownership and
permissions of the original directory structure as well. If you are
creating a tarball, be mindful of the consequences of creating a

©JONATHAN ROPER PAGE 34 23/03/2008


tarball with a directory structure with ownership and
permissions which may differ from those on target systems.

Creating a Tarball is a two stage process. First all the files are
put into a TAR file, and then they are compressed using a
compression utility such as Gzip or Bzip.

18.1 # tar
Strictly speaking, TAR, derived from the words Tape ARchive is
not really used for compression. It simply rolls a number of files
into one big file (Tarball)

The most popular command is tar –zxfv filename.tar.gz to


extract the files from an existing archive.

To archive and compress a file the following sequence is used: -

tar -cf filename.tar /etc/myfile.conf /var/lib/asterisk/agi-


bin/somefile.php

We can check that the tarfile is acceptable by executing tar -tf


filename.tar

Then we compress the tar file with: gzip filename.tar This


returns a file called filename.tar.gz. .tar.gz and .tgz are used
interchangeably

Tip: For untarring a file, do it from the command line – tar zxfv
filename.tar.gz. To tar and compress a file, it is easiest, and less
prone to error if you do it from within WinSCP. Select the
directories to be compressed, rightclick and select Tar.

18.2 # gzip
As above

18.3 # bzip
bzip –czvf filename.tar filename but using the bzip compression
algorithm

18.4 # zip & unzip


If a compressed file ends with the zip extension, use unzip to
decompress.

©JONATHAN ROPER PAGE 35 23/03/2008


19 Networking

In order to set up a machine on a network, you will need the


following information.

- The IP address
- Netmask
- Gateway
- DNS server

Please note that the command netconfig has been deprecated,


which is a fancy way of saying they’ve replaced it with
something else.

19.1 # ifconfig
Shows the current IP addresses of every interface, note that a
physical interface can have more than one IP address.

19.2 # system-config-network
A text based GUI to set the IP address of any interface. This
utility writes to:-
/etc/sysconfig/network-scripts/ifcfg-eth0 in the case of
network interface known as eth0. It can be manually edited if
necessary. With a fixed IP address the file should look like this:-

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.3.200
NETMASK=255.255.255.0
GATEWAY=192.168.3.254

Type service network restart to set the changes. Be careful you


do not lock your self out with a typing error.

19.3 # resolv.conf
The file containing the details of how to resolve an domain
name to an IP address.
To add a nameserver, type nano –w /etc/resolv.conf and add
the line: -

Nameserver 1.2.3.4

Where 1.2.3.4 is the DNS server. Often, but not always, the
gateway/router doubles up as the DNS Server

©JONATHAN ROPER PAGE 36 23/03/2008


Ping some internet domain names in order to check that DNS
resolution is working.

19.4 # hostname
Sets the name of the server.

19.5 # ifdown
Stop the interface, e.g. ifdown eth0

19.6 # ifup
Bring the interface back up again.

19.7 # ping
Send a packet to a host and measure the time it takes to make
the round trip. E.g. ping www.google.com

19.8 # traceroute
Trace the route to a host. E.g. traceroute www.google.com

19.9 # mtr
mtr is a very useful command combining ping and traceroute in
the same command. It shows the live status of the path to a
host. E.G. mtr www.google.com

20 Network Security

There is no substitute for having a good firewall, but Linux


contains IP tables that filter and manipulate packets.

20.1.1 Iptables

IP tables are are found in /etc/sysconfig/iptables they can be


managed by hand editing them, or it is much easier via
Webmin. Open Webmin and navigate to Networking then Linux
Firewall.

©JONATHAN ROPER PAGE 37 23/03/2008


21 Installing software

There are a number of ways of getting software on the server,


the following are methods are described below.

21.1 Compiling from source


In many cases, programs can be compiled from source. That is
to say that there is machine readable source code, and using
development tools on the server, software can be compiled and
installed.

Generally, the software is untarred to /usr/src/<package-


name>. Within the unzipped directory will be a readme file, or
install.txt which should be read before proceeding to see if there
is anything special that needs to be done.

In general, the commands are as follows:-

21.1.1 # make clean

Clean up any failed or previous installs.

21.1.2 # ./configure

Checks and configures the package ready for compiling and


installation, and ensures that all the dependencies are in place.
If the there is hardware to be installed, there is a very good
chance that you will need the kernel sources. (yum install
kernel-devel)

Watch the output for any errors. If there are dependencies


missing, then these may have to be installed first, probably
from the yum repositiory

21.1.3 # make

Compile the program.

21.1.4 # make install

Install the program

21.2 # yum
Use the CentOS repository, and other repositories to install and
update software. E.g.

©JONATHAN ROPER PAGE 38 23/03/2008


# Yum update updates the entire operating system. Note that if
any hardware has been compiled against the kernel, ie.zaptel,
then the package will have to recompiled as above.

# yum search <package name> search for a package.

# yum install <package name>

# yum –y install <package name> ; installs programs without


any further prompts.

21.3 # rpm
Many programs, e.g. webmin come as an rpm, or a pre-
compiled binary, so that the program does not have to be
compiled on the machine.

The usual command is rpm –iv <package name>

If the package is available on the yum repository, it is usually


better to install it from there. The RPM package may not be
specific to your own Linux distribution.

22 Logs

There are a large number of logs on the system, which can give
good information on any problems, who has accessed the
machine, and what they have done with them. To view them,
you can use less, tail, cat, and other similar commands as
listed above. A few of the more important logs are below.

22.1 /var/log/messages
Contains general system logging

22.2 /var/log/dmesg
Contains hardware loading information

22.3 /var/log/asterisk/full
Contains the Asterisk log file

©JONATHAN ROPER PAGE 39 23/03/2008


22.4 # logrotate
Logs can get quite large, so it is important to do some
housekeeping to ensure that the file system does not become
full.

This is usually done for you. But if not, read the man logrotate.

23 Crontab

The crontab is a way of making timed events happen on a


regular basis. They are also known as cron jobs.

Cron jobs are easiest set up in Webmin.

Crontabs can also be viewed and edited using crontab


command at the command line. Once in crontab, the editing
commands are the same as Vi editor, which is another text
editor supplied with Linux, and is about as user friendly as a
cornered rat. So I would urge you to use webmin for adding and
editing.

24 Users and Groups

24.1 Users
Users are people, and processes that have access to things on
the system

24.2 Groups
A group is a collection of users to make administration easier.

24.3 # sudo
It is not necessarily desirable to have root as the main access to
system. If hackers get access to the system, they can go
everywhere. Additionally, it is possible to make a mistake on the
system. By being a non root user, some of these mistakes can
be mitigated.

To set up a sudo user:-

# adduser myusername
# passwd myusername <password>

©JONATHAN ROPER PAGE 40 23/03/2008


To edit the sudoers file to run sudfo commands, nano
/etc/sudoers and add the following line: -

myusername ALL=(ALL) ALL

Now simply execute commands as the root user by typing sudo


<command>…

Alternatively, you can log on as root type “sudo –“ then enter


the password.

# sudo –i gives you complete root access without needing to


prefix commands with sudo.

25 Network Services

The server runs a few of the following services.

25.1 NTP
A time server. Linux can get its time from the internet, and act
as a time server for devices on your network. For this to
happen, ntpd must be running (service ntpd status) and port
123 udp must be open on the firewall

To force the computer to set the right time.

# service ntpd stop


# ntpdate 1.pool.ntp.org
# service ntpd start

Tip: Before commencing the installation of Linux, check that the


hardware clock in BIOS is set to the right time and date,
otherwise installation of packages may fail.

25.2 DNS
Domain Name resolution. Linux can be a domain name server.
The easiest way to set this up is in webmin. Click on servers,
then Bind.DNS Server, and set it up with the default values
offered by Webmin.

Port 53 must be open to allow DNS queries

©JONATHAN ROPER PAGE 41 23/03/2008


25.3 DHCP
DHCP, Dynamic Domain Name Server. Port 67 UDP must be
open to deliver IP addresses to it clients. This can be set up and
started in Webmin easily. If you wish to run a DHCP server on
your machine, ensure that you start it as a service. Refer to
chkconfig instructions above.

25.4 TFTP
A TFTP server is what a phone and other devices use to get
their configuration. Run these commands to get it running: -

# yum -y install tftp-server

# /sbin/chkconfig --level 345 xinetd on

# /sbin/chkconfig --level 345 tftp on

# service xinetd restart

To check it is running: -

netstat -nulp|grep 69

You should see a result that includes a line that looks similar to
the following:

udp 0 0 0.0.0.0:69 0.0.0.0:*

25.4.1 Option 66

Option 66 in the DHCP configuration is the setting that tells


TFTP enabled devices where to find the TFTP server.

25.5 Sendmail / Postfix


These programs are both popular programs for sending mail. To
set them up the way you want them. Webmin is the best option
for those with Conversational Linux

25.6 Apache
The web server, that delivers web pages. The Daemon is called
httpd. To restart apache, type httpd –k restart

In general, the files for the webserver are held in


/var/www/html.

©JONATHAN ROPER PAGE 42 23/03/2008


25.7 PHP
PHP is a language that when combined with Apache and
MySQL allows interactivity with the web page. Adding, removing
and displaying records from a database.

25.8 MySQL
MySQL is one of the most popular database systems. It can
handle many millions of records. If you have Apache and PHP
installed, the database can be viewed via phpMyAdmin. See
www.phpmyadmin.net. Do however note the licensing of
MySQL. It is undergoing change due to a commercial buyout.

26 Hardware

26.1 # lspci
Show the interrupts on the system, add –v for more information

26.2 # cat /proc/interrupts


As above, but from a different source

27 SSH Tunnelling

SSH has the ability to tunnel connections from your PC to any


other IP address that the CentOS server has access to. This can
be useful for reconfiguring routers or phones on the remote
network.

In putty, open a connection to the remote server. Once


connected, click on the little icon in the top left hand corner of
putty and select “Change Settings”

In the left hand side bar, select Connection, SSH, Tunnels

And you should end up with a screen like this: -

©JONATHAN ROPER PAGE 43 23/03/2008


27.1 Example One
Assume that we want to connect to the router which is on
192.168.3.254 using port 80. Fill in the boxes as follows: -

• Source port = 80

• Destination port = 192.168.3.254:80

• Leave Local and Auto as the defaults

Click add, then apply

On your local browser, Firefox or Internet Explorer, type


http://localhost and the router will appear in your web page.

27.2 Example Two


You wish to connect to a number of phones on the network,
that are on 192.168.3.201, 202, 203 etc, to match the
extension numbers, 201, 202, 203 etc.

You can add a number of tunnels, so to connect to


192.168.3.201

• Source Port = 201

©JONATHAN ROPER PAGE 44 23/03/2008


• Destination – 192.168.3.201:80

• Click add, then add the next phone

• Source Port = 202

• Destination = 192.168.3.202:80

Click Add, and continue in this manner. When you have added
all your phones, click Apply.

• To access extension 201, type http://localhost:201

• To access extension 202, type http://localhost:202

Ports 201 and 202 were only chosen to make it easy to


remember where to find the phones. Any source port can be
chosen

28 Conclusion

Now you have read this document, you should have enough
information and tools to be able to do basic Linux installs,
configuration and maintenance, as well as search for further
information should you need to.

The purpose of the above is not to give you a complete overview


of Linux, but just enough to get you started, and carry out
basic commands with an understanding of what you are doing
in the context of installing a PBX.

©JONATHAN ROPER PAGE 45 23/03/2008

You might also like