YUM tricks of the trade

# make yum update all programs every night


chkconfig yum on

# make yum install program and answer YES to all queries.

yum -y install

How to setup your first VPS – linode – PART 2

So we’ve setup our server, it is up to date, and root login has been disabled. Now to setup our webserver:

yum install httpd

We’ll assume you’ll be hosting more than one site so will be using Virtual Hosts, lets keep all the V-Host files in one file to make editting websites later on easier.

Lets edit the Vhost file

nano /etc/httpd/conf.d/vhost.conf


ServerAdmin admin1@email.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /srv/www/domain.com/public_html/
ErrorLog /srv/www/domain.com/logs/error.log
CustomLog /srv/www/domain.com/logs/access.log combined

Replace domain.com with your domain name, and insert your email address in the ServerAdmin section.

Now add in your domain web directories

mkdir -p /srv/www/domain.com/public_html
mkdir -p /srv/www/domain.com/logs

now lets start up the web server!

/etc/init.d/httpd start
/sbin/chkconfig --levels 235 httpd on

If all has gone well you should see the green OK box come up. To check that its worked, open up your browser and paste in the IP address, (of course make sure there is a html file in there!) and your web server should be alive!

Mysql install, execute the following commands and follow the prompts

yum install mysql-server
/sbin/chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
mysql_secure_installation

PHP Install

yum install php php-pear
yum install php-mysql

Restart Apache to activate PHP

/etc/init.d/httpd restart

Check that php has been installed successfully edit a file like this

nano phpinfo.php

and insert


Open your browser and navigate to this file http://youripaddress/phpinfo.php you should see something like this

phpinfo

phpinfo

How to setup your first VPS – linode – PART 1

linode

linode

For this example, we’ll be setting up a VPS with with awesome folks at Linode lets begin! Once we are past the account setup stuff, this guide will help you setup a VPS with any provider.

Select a plan

Select a plan

Select a plan, fill in the form, hand over your credit card details and submit! Within a few minutes you’ll receive an account activation. Using your login username and password, log into your control panel @ www.linode.com.

Click on deploy distro

For this example we’ll be spinning up a Centos 32bit distro, no need to make any other changes, just slot in your password. Once the image has been installed you’ll see this screen.

Click on the boot button.

Click on the network tab to find your ip address, we’ll need this to ssh into your new VPS to complete the setup process. Your IP is located ext to the heading eth0: in our case this is 173.255.216.68

On your local machine open up a terminal window (or download Putty if your are on Windows)

login

login

In your terminal type (replace 100.100.100.100 with your ip address)

ssh root@100.100.100.100

You may then be asked to authenticate your hosts RSA fingerprint, type YES  and hit enter.

Now you’ll be asked for your password, enter it and hit return.

Well done, you’ve made it into your new VPS! We’ll start doing a bit of house work to get your VPS up to scratch, first we’ll see if there are any updates that need to be installed, CENTOS has a package manager called YUM. To execute the update type this:

yum update

YUM will work out which packages need to be downloaded and present you a list that looks like this:

Yum UPDATE

Yum UPDATE

Hit y and then return and watch your system get updated.

The next thing to do is to remove ROOT access to your server, this is basic security 101, we will disable the user ROOT’s ability to log into our server via SSH, instead we’ll create another user with the name ‘superdude’ (you can pick whatever name you like, but try and avoid generic names like admin etc etc) whilst we are in this process we’ll also install a program called denyhosts which will monitor our system for illegal login attempts and ban people that are trying to access our machine.

adduser

adduser

useradd superdude
passwd superdude

Type in your new password, you’ll notice i typed in a common word found in a dictionary which CENTOS rejected, make sure your password is STRONG, this means alphanumeric combinations greater than 7 characters and also add in at least one special character like !@#$%^&*()><.

Now lets install denyhosts, to do this we must install the RPM repo like this.

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm

Install the GPG key

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

Verify the package

rpm -K rpmforge-release-0.5.1-1.el5.rf.*.rpm

Install RPMFORGE

rpm -i rpmforge-release-0.5.1-1.el5.rf.*.rpm

Now run yum Check.

yum check-update

Now lets install denyhosts with the following command.

yum -y install denyhosts

the default settings are ok, but if you want to customise your settings you need to edit this file

nano /etc/denyhosts/denyhosts.cfg

Now lets turn on the daemon so that it runs 24/7

chkconfig denyhosts on
service denyhosts start

Now lets turn off ROOT login access edit:

nano /etc/ssh/sshd_config

Find this section:

# Authentication:
#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

And modify to look like this:

# Authentication:
LoginGraceTime 2m
PermitRootLogin no
StrictModes yes
MaxAuthTries 6

Now lets restart sshd

/etc/init.d/sshd restart

Now the next time you SSH into your server you will need to log in with user superdude, however you won’t have root access until you log in as super user, to do this, you’ll need to execute

su -

followed by your ROOT PASSWORD

In our next edition we’ll setup the webserver/mysql/php

Yum Update excluding packages

http://www.cyberciti.biz/faq/redhat-centos-linux-yum-update-exclude-packages/

yum –exclude=perl* update

Block IP addresses with iptables

iptables -A INPUT -s IP-ADDRESS -j DROP

then save

service iptables save

ntop

http://www.banym.de/projects/centos-fedora/install-ntop-on-centos

System Prep | SecureCentos.com

Good place to start securing your Centos Build

nano -w /etc/sysconfig/network

via System Prep | SecureCentos.com.

Install OSSEC | SecureCentos.com

Please note a new version of ossec is available, 2.4.1 The link below describes installation of 2.3 which has some issues when rebooting etc etc

via Install OSSEC | SecureCentos.com.

Spawn Rsync Expect Timeout!

So you’ve written a bash script to do a rsync backup, but the script times out?

Scratching your heading trying to figure out what the issue is?

Well, if you are using expect to auto-insert your SSH password, then expect will timeout as it is not receiving any response.

You can set the timeout (in seconds) as such

set timeout 60

That will set the script to time out after 60 seconds if expect has received no trigger.

Setting the timeout to -1 will cause the ‘except’ script to never timeout, hence you’re RSYNC backup will execute and not fail due to an expect timeout.

Lighttpd Centos

Lighttpd is the web server of choice for low memory VPS applications.

Lighttpd is not included in the base CENTOS Repo, so you will need to install the RPMFORGE repo. then

yum install lighttpd lighttpd-fastcgi

Then setup some dir’s

mkdir /var/run/lighttpd
touch /var/run/lighttpd/php-fastcgi.socket
chown -R lighttpd:lighttpd /var/run/lighttpd/
nano /etc/php.ini

edith /etc/lighttpd/lighttpd.conf and either add or remove # to

mod_fastcgi

from the server modules

add access to php cgi with the following in the .conf file also

fastcgi.server = ( “.php” =>
( “localhost” =>
(
“socket” => “tmp/php-fastcgi.socket”,
“bin-path” => “/usr/bin/php-cgi”
)
)
)

info sourced from

http://davidwinter.me.uk/articles/2008/06/22/lighttpd-and-php-on-centos-5/

some good references for setting up .conf file with virtual hosts

http://www.cyberciti.biz/faq/howto-lighttpd-virtualhost-configuration/

http://www.linux.com/archive/feed/51673