Slobodan Krajinoic's GLS Project - a step-by-step instruction manual for creating a Generic Linux Server that is secure, stable and up-to-date. After installation, the GLS can be configured for a more specific purpose: mail server, firewall, dns, etc.

Thursday, February 21, 2008

Generic Linux Server

This document describes how to install a Generic Linux Server. This document is a Work In Progress, updated regularly, since March 2001.

This doc is derived from my private collection of notes and different bits of useful information collected over the years from various sources: Internet, books, personal experience, etc. I hope it may be found useful for everybody who is interested in creating a secure and stable basic Linux server, which can then be adapted for more specific tasks.

Internet access is required to complete the installation.


Get the Ubuntu Server 6.06.2 LTS Installion CD

a. First, download the Ubuntu Server installation CD suitable for your hardware platform.
* CDs can be downloaded from http://releases.ubuntu.com/
b. Burn the CD image to a CD-R.

Installing Ubuntu Server 6.06.2 LTS

a. Boot up from the Ubuntu Server Installation CD you created.
b. Select 'Install to Hard Disk'
* After system has booted up, the Ubuntu installation auto-starts.
c. On the first screen you need to select the installation language:
* Select your language:
d. Choose a keyboard layout:
* (Setup starts to inspect your hardware setup:)
e. If your network doesn't have DHCP, you can configure network manually:
f. Insert the hostname for your system, for example 'myhostname' (used hereafter)
g. Insert your domain name, for example 'mydomain.com': (used hereafter)


Disk Partitioning

I generally partition in the following manner:

PARTITION .. BOOTABLE .. SIZE ........... FS .......... MOUNT-POINT ..... NOTE
1 ................... Y ............. 500MB ......... ext3 ......... /boot .................. (*1)
2 ................... N ................ 1GB .......... swap ........ swap ................. (*2)

3 ................... N .............. 20GB .......... xfs ........... /root ................... (*3)
4 ....................N ............ the rest ........ xfs ........... /


Notes:
*1 =
needs enough space to ensure that kernel upgrades don’t fill it
*2 =
1-2x system memory, usually 2-8GB
*3 =
Usually 10% of your hard drive, To separate /root file system from / file system

The reasons for partitioning as above are as follows:


1. /boot must be at the beginning of the disk to ensure compatibility with BIOSes and bootloaders.
* Also, it should be ext3 for bootloader and rescue CD purposes
2. /root must be in a separate file space for security reasons

I use XFS because it seems better to me than JFS, ext3 and ResierFS.

TimeZone and New User

a. Select your timezone.
b. Create a new user (eg. "myNewUser")

* (Base system installation procedure starts...)

c. Remove installation CD and reboot system...
*( Base system installation is finished)
*(System will reboot)


Enable The root Account

Ubuntu disables the root user account by default. Because we must run all the steps from this tutorial as root user, we must re-enable the root account now. To enable it:

a. login as MyNewUser, then run:

$ sudo passwd root

to set the root password. Afterwards we become root by running:

$ su -


Updating 'apt' repositories

In order to update the system software, we must first update the 'apt' repositories to include: main, restricted, backports, universe and multiverse. We must also disable cdrom access. This is done by editing '/etc/apt/sources.list' file.

6a. Edit the sources.list file

# nano -w /etc/apt/sources.list

Here is an example of the finished sources.list file:
root@server:~#
cat /etc/apt/sources.list

-----------------------------------------------------------------------------------------------
#
# deb cdrom:[Ubuntu-Server 6.06.2 _Dapper Drake_ - Release amd64 (20080110.1)]/dapper main restricted
###deb cdrom:[Ubuntu-Server 6.06.2 _Dapper Drake_ - Release amd64 (20080110.1)]/ dapper main restricted
deb http://ca.archive.ubuntu.com/ubuntu/ dapper main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ dapper main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://ca.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://ca.archive.ubuntu.com/ubuntu/ dapper universe multiverse
deb-src http://ca.archive.ubuntu.com/ubuntu/ dapper universe multiverse
## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ca.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
deb-src http://ca.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu dapper-security main restricted
deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted
deb http://security.ubuntu.com/ubuntu dapper-security universe
deb-src http://security.ubuntu.com/ubuntu dapper-security universe
-----------------------------------------------------------------------------------------------


Note that the following changes were made to the above file:
a. Line 3 - cdrom access commented out
b. Lines 8 and 9 uncommented
c. Lines 17 and 18 uncommented, and the word MULTIVERSE appended to end of line
d. Lines 26 to 31 uncommented - ensure that MULTIVERSE is at end of line as shown


6b. Now update repositories

# apt-get update

6c. Now we can proceed with an system upgrade

# apt-get upgrade -y

6d. Now reboot because the kernel image was updated

# shutdown -r now

6e. Log back in as root


MC - GNU Midnight Commander

GNU Midnight Commander is a file manager (Norton Commander clone) for free operating systems. Being a text mode application, GNU Midnight Commander can be used locally or remotely, on the console or under the X Windows System. By using the full screen space of the terminal screen, it provides an intuitive user interface to the operating system, proving to be a useful tool for users with any level of experience, from a newbie to a guru.

7a. Install Midnight Commander

# apt-get install mc -y

7b. Configure Midnight Commander
Now change the midnight commander settings so the startup folder is in the current folder, not at root.

# mv /usr/share/mc/bin/mc.sh /usr/share/mc/bin.mc.sh.norun
# cat /usr/share/mc/bin.mc.sh.norun >> /etc/bash.bashrc


SSH


SSH is a protocol designed to provide remote secure access for administration purpose - a text-only, secure PCAnywhere. OpenSSH encrypts all traffic (including passwords) to effectively eliminate eavesdropping, connection hijacking, and other network-level attacks. Ubuntu does not install OpenSSH by default, therefore we do it now.

8a. Install OpenSSH

# apt-get install ssh openssh-server -y

8b. Configure the /etc/ssh/sshd_config file

# nano -w /etc/ssh/sshd_config file

8c. Changing the default SSH port

In the sshd_config file, change the default SSH port (22) to deter most brute force attacks

8d. ServerKeyBits

The ServerKeyBits setting specifies how many bits to use in the server key. Change the default value to 1024. These bits are used when the daemon starts to generate its RSA key.

8e. Disabling root login

Disable root access login. Administrators should have to login under a non-privileged user name (MyNewUser) first & then su to root.

8F. SUMMARY OF CHANGES TO THE /etc/ssh/sshd_config FILE:

Port 38475
ServerKeyBits 1024
PermitRootLogin no
AllowUsers MyNewUser


Remove sudoers entries


Use the specialized program VISUDO to change the sudoers file. VISUDO changes both the passwords file and the shadow passwords file at the same time.

# visudo

The file /etc/sudoers should look something like this (do not include the dashed lines):

root@server:~# cat /etc/sudoers

----------------------------------------------------------------------------
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults
Defaults !lecture,tty_tickets,!fqdn
# User privilege specification
root ALL=(ALL) ALL
--------------------------------------------------------------------------------


Configure The Network


The Ubuntu installer configured our system to get its network settings via DHCP, so we must change that now because a server should have a static IP address.

10a. Edit the /etc/network/interfaces file

# nano -w /etc/network/interfaces

-----------------------------------------------------------------------------------
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 208.233.68.149
netmask 255.255.255.240
gateway 208.233.68.145
-----------------------------------------------------------------------------------

10b. Then restart your network

# /etc/init.d/networking restart

10c. Then edit /etc/resolv.conf file

# nano -w /etc/resolv.conf

10d. Make it look like this

-----------------------------------------------------------------------------------
search example.com
nameserver 208.233.3.3
nameserver 208.233.5.5
-----------------------------------------------------------------------------------

10e. Then edit /etc/hosts

# nano -w /etc/hosts

10f. Make it look like this

-----------------------------------------------------------------------------------
127.0.0.1 localhost.localdomain localhost
208.233.68.149 server.example.com server
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
-----------------------------------------------------------------------------------

10g. Restart the host services

# hostname
# hostname -f

Both should show MyServerName.MyDomain.com. If they do not, reboot the system:

# shutdown -r now

Afterwards, run these commands again, as follows:

# hostname
# hostname -f

Now they should show MyServerName.MyDomain.com.


DNS

Having a local DNS cache is highly recommended, this can have a big effect on the server performance. djbdns is a replacement for BIND. It is secure, reliable, small, fast, etc etc etc. dnscache is a recursive resolver, intended to be listed in /etc/resolv.conf's "nameserver" entry. It makes DNS queries via UDP and TCP as needed. daemontools manages all the djbdns services and daemons.

11a. Download the install files for daemontools and djbdns

# apt-get install daemontools-installer djbdns-installer -y

11b. Then build/install daemontools

# build-daemontools

(just hit [Enter] at any questions it asks)

11c. Then build/install djbdns

# build-djbdns

(just hit [Enter] at any questions it asks)

11d. Configure the dnscache program

# dnscache-conf dnscache dnslog /etc/dnscache

11e. Create a symlink to the dnscache program
Create a link to the dnscache program in the /service directory so svscan will start it.

# ln -s /etc/dnscache /service

11f. Verify that the dnscache service is running
Wait at least 5 seconds, then run:

# sleep 5
# svstat /service/dnscache

11g. Create a new resolv.conf
(pointing to ourselves as the DNS server)

# echo "domain example.com" > /etc/resolv.conf
# echo "nameserver 127.0.0.1" >> /etc/resolv.conf

11h. DNS resolve test
Test that you are able to resolve a host name on the Internet:

# dnsip
http://www.cnn.com/

11i. Verify dnscache is working
Tail the log file to verify dnscache is working, run:

#tail -40 /service/dnscache/log/main/current


NTP - Network Time Protocol


NTP is a protocol designed to synchronize the clocks of computers over a network. Many server processes depend on the system clock for proper operation, so it is crucial to have NTP running and to select servers that are reliable and close to you from a network standpoint.

12a. Install the NTP client

# apt-get install ntp ntpdate -y

12b. Create the script to update the system clock

# cd /etc/init.d
# touch ntp-update.sh
# chmod 755 ntp-update.sh

12c. Edit the system time update script

# nano -w /etc/init.d/ntp-update.sh

12d. Make the ntp-update.sh file look like this:

-----------------------------------------------------------------------------------
#!/bin/sh -e
#
sleep 5
ntpdate -u 0.north-america.pool.ntp.org
hwclock --adjust
hwclock --systohc
# wait 1 hour
sleep 3600
/etc/init.d/ntp-update.sh &

-----------------------------------------------------------------------------------

12e. Configure Linux to run the script automatically

# nano -w /etc/rc.local


Make the /etc/rc.local file look like this

-----------------------------------------------------------------------------------
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#
# NTP script
#
/etc/init.d/ntp-update.sh &
#
exit 0
-----------------------------------------------------------------------------------


13. SMAIL

Most of the services on server send messages to the local root account. We will soon disable that account, so the best way to deal with those messages is to forward them elsewhere. For that reason we create an email account outside the organization (on yahoo or gmail, etc) - something like MyCompanyRoot@gmail.com. We then setup forwarding of all messages sent to this server's admin account admin@MyDomain.com to there. This way you will have redundancy even if your mail server is down or inaccessible. My recommendation is to use this account to receive messages from all servers in your organization.

Smail is an implementation of an Electronic Mail Transport Agent (MTA), i.e. a program used for sending and receiving electronic mail, for Unix-like (POSIX compatible) systems.

Smail's job is to accept mail messages from local files or programs running on the local machine (such as any mail user agent), and deliver those messages to the appropriate destinations, whether to remote hosts or to files or programs on the local machine, etc.

13a. Install and configure smail

# apt-get --purge install smail

13b. The following messages will appear

-----------------------------------------------------------------------------------
Reading package lists... Done
Building dependency tree... Done
smail is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0B of archives.
After unpacking 0B of additional disk space will be used.
Setting up smail (3.2.0.115-5.1) ...
I can do certain kinds of automatic configuration of your mail system, by
asking you a number of questions. Later you may want to confirm and/or correct
your answers. In any case, comprehensive information on configuring Smail is
in smail(5) and in /usr/share/doc/smail/ .
You must choose one of the options below:
(1) Internet site: you send and receive Internet mail on this
machine, using SMTP over TCP/IP, select this if you have a smarthost
reachable over SMTP.
(2) UUCP to smarthost (upstream site):
You send and receive mail via UUCP; outbound mail is sent to your
smarthost (probably your service provider) for routing and delivery.
(3) No mail is to be delivered or routed here. Any mail generated on this
system is sent to a central mail switch using SMTP. This configuration is
for workstation, which have mounted /var/mail from a central server.
(4) Local delivery only:
You are not on a network. Mail for local users is delivered.
(5) No configuration will be done now; your mail system will be broken and
should not be used. Use /usr/sbin/smailconfig as root, later.
Select a number from 1 to 4, from the list above.
-----------------------------------------------------------------------------------
Enter value (default=`4', `x' to restart): 1
-----------------------------------------------------------------------------------

What is the `visible' mail name of your system ?
This will appear on From: lines of outgoing messages.
-----------------------------------------------------------------------------------
Enter value (default=`server.example.com', `x' to restart): ip149.MyDomain.com
-----------------------------------------------------------------------------------
Does this system have any other names which may appear on incoming
mail messages, apart from the visible name above (ip149.MyDomain.com)
and the system's hostname (server.example.com) ?
If so enter them here, separated with spaces or commas. If there are
none, say `none'.
-----------------------------------------------------------------------------------
Enter value (default=`none', `x' to restart): none
-----------------------------------------------------------------------------------
Do you have a smarthost available (and accessible via SMTP) ?
A smarthost is a system to which you forward mail you don't want to
deliver yourself; it presumably has better connectivity or routing
information than you do. Commercial providers usually provide a
smarthost for their customers, and large organisations will often have
a site mail switch which can be used. Use of a smarthost is strongly
recommended (you'll be able to specify exactly when to use it soon).
If a smarthost is available please enter its name (otherwise, `none').
-----------------------------------------------------------------------------------
Enter value (`x' to restart): none
-----------------------------------------------------------------------------------
Do you want to relay mail from anybody ?
If you allow relay from somewhere, that machine will send it's mail
to this server for delivery, you will become it's smarthost.
You can specify the word 'localnet', that will dinamically match
the net of your localhost, or you can specify the net by it's ip
number and using wildcards. (Example: 192.168.1.*).
If you want to relay to everyone, just write 'all'.
Beware, allowing everyone to relay from your machine, will let
spamers send their junk-mail througth your machine, making you
responsible for that. You shouldn't allow mail relaying from
unknown machines.
You can especify more than one net separating the ip numbers by ':'
-----------------------------------------------------------------------------------
Enter value (default=`127.0.0.1', `x' to restart):127.0.0.1
-----------------------------------------------------------------------------------
Mail for the `postmaster' and `root' accounts is usually redirected
to one or more user accounts, of the actual system administrators.
By default, I'll set things up so that mail for `postmaster' and for
various system accounts is redirected to `root', and mail for `root'
is redirected to a real user. This can be changed by editing /etc/aliases.
Note that postmaster-mail should usually be read on the system it is
directed to, rather than being forwarded elsewhere, so (at least one of)
the users you choose should not redirect their mail off this machine.
Which user account(s) should system administrator mail go to ?
Enter one or more usernames separated by spaces or commas . Enter
`none' if you want to leave this mail in `root's mailbox - NB this
is strongly discouraged. Also, note that usernames should be lowercase !
-----------------------------------------------------------------------------------
Enter value (`x' to restart): none
-----------------------------------------------------------------------------------

The following configuration has been entered:
Mail generated on this system will have `ip149.MyDomain.com' used
as the host part (after the @) in the From: field and similar places.
Message-ID's, Received lines, etc. will use the system's canonical
hostname, which is currently set to server.example.com.
The following hostname(s) will be recognised as referring to this system:
mail.areyouverified.com, ip149.example.com
Mail for postmaster, root, etc. will be sent to root.
Local mail is delivered.
Outbound remote mail is looked up in the Internet DNS, and delivered
using that data if any is found; failing that messages are bounced.
Mail for the non-DNS UUCP and BITNET domains are sent to the backbone
sites uu.net and cunyvm.cuny.edu for routing, respectively.
Is this OK ? Hit Return or type `y' to confirm it and install,
or `n' to make changes (in which case we'll go round again, giving you

-----------------------------------------------------------------------------------
your previous answers as defaults. (y/n) y
-----------------------------------------------------------------------------------

You have to select a method starting smail:
The decision as to whether to use a smail daemon, or the inet
daemon depends upon how much mail passes through your site and whether
or not you can always spare 300K of virtual memory.
(1) Generate a line in /etc/inetd.conf. For every remote-connections a
smail session is started. It is the standard.
(2) To invoke a smail daemon at system boot time.
Select a number from 1 to 2, from the list above.
-----------------------------------------------------------------------------------
Enter value (default=`1', `x' to restart): 1
-----------------------------------------------------------------------------------
Current crontab entry for smail:
# Default `mail' user's crontab, supplied Smail for Debian Linux.
# See /usr/doc/smail/copyright for details, or read smail(5) for details of
# how to configure Smail. Autoconfiguration done by /usr/sbin/smailconfig.
# (min, hour) (dm,m,dw) (command)
3,23,43 * * * * runq
Configuration installed.

Would you like to send a test message now ? Select one of:
Return or Y Yes, test offsite delivery with a message to Harald Alvestrand's
Linux Counter project - you should then receive an autoreply
to postmaster@ip149.example.com.
Do not use this option until mail routing to your machine has
been properly enabled, please !
L Just a local message from root@ip149.example.com
to postmaster@ip149.example.com.
N No, thanks. (You can do this later using /usr/sbin/smailtest.)
-----------------------------------------------------------------------------------
Send a test message now ? (y/l/n) l
-----------------------------------------------------------------------------------
Test message sent.
Good. You have a recent smail configuration
You have selected to start smail in inetd.conf
You have mail in /var/mail/root


13c. Root account forwarding
After installation and configuration you must add root account forwarding in /etc/aliases, then run the newaliases command to re-read the aliases into memory.

# echo "root: example-co-root@gmail.com" >> /etc/aliases
# newaliases


13d. Test if forwarding is working

# /usr/sbin/smailtest --localonly

13e. Your screen will display these messages
Would you like to send a test message from `root' to `postmaster' ?
Send a test message now ? (y/n)
y

13f. Check the new external email account
Check your new MyCompanyRoot@gmail.com email account and you should have received the test message.


SYSTEM LOG

14a. Update /etc/logrotate.conf

# nano -w /etc/logrotate.conf

14b. Make the logrotate.conf file look like this

-----------------------------------------------------------------------------------
# see "man logrotate" for details
# rotate log files daily
daily

# keep 260 weeks worth of backlogs
rotate 1825
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0664 root utmp
rotate 1
}
# system-specific logs may be configured here
-----------------------------------------------------------------------------------

logcheck

# apt-get install logcheck -y


logwatch


# apt-get install logwatch -y


MUNIN


17a. Install Munin

# apt-get install munin munin-node


17b. Configure MUNIN

# nano -w /etc/munin/munin.conf

17c. Change these lines from:

# a simple host tree
[localhost.localdomain]

to:

# a simple host tree
[server.example.com]


17d. Restart Munin

# /etc/init.d/munin-node restart


thttpd


18a. Install thttpd

# apt-get install thttpd thttpd-util

18b. Configure thttpd

# nano -w /etc/thttpd/thttpd.conf

18c. Change default port number

port = 38964

18d. Change expected program directory

dir = /var/www/munin

18e. Ensure that port is not firewalled
On your firewall, ensure the port you specified above (18c) is not blocked by your firewall.

18f. Verify that Munin is working
go to http://MyServerName.MyDomain.com:38964


32-bit extensions


If you are running 64-bit Linux, you must install the 32-bit Extensions to allow 64-bit Linux to run 32-bit applications.

# apt-get install ia32-libs linux32 -y



About Me

Vancouver, British Columbia, Canada
http://victoryoverfraud.com/aboutus.php?section=management_team