How to mount a new Hard Drive on your Linux Server

This is a simple guide on how to mount and parition a new hard drive to be used only for backups.

This guide uses fdisk which is a very powerful tool but you should be fine as long as you are careful in what you do. Use this guide at your own risk!
What ever you do make sure to NOT use the command “fdisk /dev/sda” or “fdisk /dev/hda” as that means you are editing your main and boot partition!
Be careful and follow this guide precisely

First run fdisk to look at your available disks.

# fdisk -l

Disk /dev/hda: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 268 2048287+ 82 Linux swap
/dev/hda3 269 9726 75971385 83 Linux

Disk /dev/hdc: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

What we see above is two seperate disks, one being hda and the other is hdc. The hda is the main boot drive and as I stated above you do not want to touch it!

The first step is going to format the drive. If the drive is hdb, hdd, sdb, sdc, sdd simply replace “hdc” wherever you see in the guide with this.

#fdisk /dev/hdc

-press “n” for new partion
-press “p” for primary partition
-press “1” for the first partition
-press enter for the first AND last cylinders. This will make it automatically use the entire disk
-press “w” for write out to save what you have done

The next step is to make the filesystem readable by linux. I am going to have you format it in ext3 which is the most common filesystem type.

#mkfs.ext3 /dev/hdc1

Note that I have used “hdc1″ because it is the first partition. Now we are going to set the disk to automatically be mounted on boot as /backup. Again if you want it placed someplace else simply rename the directory.

#mkdir /backup

#pico -w /etc/fstab

Add the following line:

/dev/hdc1 /backup ext3 defaults 1 1

Now test it out

#mount /backup

This guide should work fine for any server, it is not dependent on control panel.

Posted in Linux, Server | Tagged , , | Leave a comment

How to Reset Forgotten Linux Root Password

Whenever you can’t remember your Root password, you can do this steps to reset it.

You can log in with single-user mode and create a new root password.

Reboot your computer. When GRUB is presenting the menu list, follow those instructions:

use the arrows to select the boot entry you want to modify
press e to edit the entry
use the arrows to go to kernel line
press e to edit this entry
at the end of the line add the word single (there should be a space between like / single)
press ENTER to go back to the parent menu
press b to boot this kernel

As root, changing password does not ask for your old password. Now, you can change root’s password by typing:

bash# passwd root

You’ll be asked to re-type the password for verification. Once you’re finished, the password will be changed and you can reboot by typing shutdown -r now at the prompt; then you can log in to root as before

If your boot loader is LILO follow this

At LILO boot loader type linux single and press [ENTER] key:

Boot: linux single

When you get the # prompt you will need to type passwd root to reset password:

# passwd root

Reboot system:

# sync
# reboot
Posted in Linux | Tagged , , | Leave a comment

How to find Network Card’s Mac Address in CentOS

Open SSH and type the following and press Enter:

/sbin/ifconfig | grep -i hwaddr

The sequence of hexadecimal digits that appears to the right of eth0 HWAddr (e.g. 08:00:27:ED:DA:8b) is your network card’s MAC Address

Posted in CentOS | Tagged , | Leave a comment

How to Change the SSH port on cPanel Servers

To change the SSH port login as root, and edit

/etc/ssh/sshd_config

Find the line that says Port 22 and change 22 to any number between 1024->65535 (above 30000 is best) and save the file.

Once done, run:

/etc/init.d/sshd restart

Now start a new SSH session (don’t close your existing one), to make sure that you can get in.

Posted in Cpanel Server, Linux, security | Tagged , , , | Leave a comment

How to Change Hostname and IP on a CentOS Server

1. RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit

nano /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=”plain.domainname.com”
GATEWAY=”111.222.333.1″
GATEWAYDEV=”eth0″
FORWARD_IPV4=”yes”

2. TCP/IP Network Configuration Files

This configures Linux so that it knows which DNS server will be resolving domain names into IP addresses

nano /etc/resolv.conf

search name-of-domain.com – Name of your domain or ISP’s domain if using their name server
nameserver XXX.XXX.XXX.XXX – IP address of primary name server
nameserver XXX.XXX.XXX.XXX – IP address of secondary name server

3. Locally resolve node names to IP addresses

nano /etc/hosts

::1 localhost6.localdomain6 localhost6
# Do not remove the following line, or various programs
# that require network functionality will fail.
111.222.333.444 yourname.server.com yourname
127.0.0.1 localhost

4. Configuration settings for your first ethernet port

nano /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static
BROADCAST=111.222.333.255
IPADDR=111.222.333.444
NETMASK=255.255.255.0
NETWORK=111.222.333.0
ONBOOT=yes

And to finalize , you need to restart your network

service network restart
Posted in CentOS, Linux, Server | Tagged , , , | Leave a comment

How to Install Mod_Gzip with Apache

mod_gzip is an Internet Content Acceleration module for the popular Apache Web Server. It compresses the contents delivered to the client. There is no need to install any additional software on the client!

If you are having difficulties with getting mod_gzip to work when compiled with using easyapache, then you can go and use this step by step manual install.

Log into you server using shell and your root account and download mod_gzip-1.3.26.1a.tgz (or whatever the latest version) from sourceforge.net

I used

wget http://space.dl.sourceforge.net/project/mod-gzip/mod-gzip13x/mod_gzip-1.3.26.1a/mod_gzip-1.3.26.1a.tgz

after that

tar -zxvf mod_gzip-1.3.26.1a.tgz
cd mod_gzip-1.3.26.1a

make APXS=/usr/local/apache/bin/apxs
make install APXS=/usr/local/apache/bin/apxs

Then edit your httpd.conf file

pico /etc/httpd/conf/httpd.conf

and add the following (in the AddModule stuff):

first uncomment:

#LoadModule gzip_module libexec/mod_gzip.so

to

LoadModule gzip_module libexec/mod_gzip.so

and

#AddModule mod_gzip.c

to

AddModule mod_gzip.c

and after AddModule mod_gzip.c add this below

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
mod_gzip_update_static No
mod_gzip_command_version '/mod_gzip_status'
mod_gzip_temp_dir /tmp
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 500
mod_gzip_maximum_file_size 500000
mod_gzip_maximum_inmem_size 60000
mod_gzip_min_http 1000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.shtml$
mod_gzip_item_include file \.htm$
mod_gzip_item_include file \.shtm$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.phtml$
mod_gzip_item_exclude file \.js$
mod_gzip_item_exclude file \.css$
mod_gzip_item_exclude file \.wml$
mod_gzip_item_include file \.pl$
mod_gzip_item_include file \.cgi$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include mime ^text/plain$
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_include mime ^application/x-httpd-php
mod_gzip_item_include handler ^perl-script$
mod_gzip_item_exclude mime ^image/
mod_gzip_dechunk Yes
mod_gzip_add_header_count Yes
mod_gzip_send_vary Yes
</IfModule>

Then restart apache with

service httpd restart
Posted in Apache, Cpanel Server, dedicated server, Linux | Tagged , , | Leave a comment

How to Disable Telnet

Telnet sends clear text passwords and usernames through logins and should be disabled on all web servers and replaced with SSH.

Some hosting providers are not disabling telnet by default but you should ensure that it has been turned off as it’s a great security risk to your servers. TELNET server listens for incoming messages on port 23, and sends outgoing messages to port 23.

1. Login to your server through SSH and su to root.

2. Type

pico /etc/xinetd.d/telnet

3. Look for the line:

disable = no

and replace with

disable = yes

4. Now restart the inetd service:

/etc/rc.d/init.d/xinetd restart

5. Turn off it through chkconfig as well because it can still start through that.

/sbin/chkconfig telnet off

6. Scan your server to ensure port 23 is closed.

nmap -sT -O localhost

Also run

ps -aux | grep telnet

and if you find anything other than "grep telnet" as result kill the process.

Posted in Linux, security | Tagged , , | Leave a comment

How to Install, Configure and Securing a new cPanel Server

First Install cPanel on the new server

root@server [~]# mkdir /home/cpins
root@server [~]#cd /home/cpins
root@server [~]#wget http://layer1.cpanel.net/latest

after this give screen command

root@server [~]#screen

If it works then OK ,but if did’nt work use

root@server [~]#yum install screen (Install all the dependencies with it )

now give screen command

root@server [~]#screen

after that give ‘ll’ or ls and you will see the file as ‘latest’

root@server [~]# ls

latest

change permission to 755

root@server [~]#chmod 755 latest

and then after give this command

#sh latest

After Installation you need to configure your WHM by login to http://yourip:2086

Now Harden/Secure the server :-

Steps to Harden server :-

Install csf as almost 80 % of your server can be secured by installing csf :-

Steps to install csf :-

Download CSF script from

root@server [~]http://www.configserver.com/free/csf.tgz

Untar File

root@server [~]tar -xzxf csf.tar.gz

Install using following command

root@server [~]sh /csf/install.sh

That’s it! Wait for installation to finish.

Once you finish with the installation login to WHM by http://yourip:2086

WHM >> Plugins >>Config Server Security and Firewall >> Click on “Check Server Security” and from here you can increase the rating which will secure your server.

Further you can optimize your httpd and mysql by adding some manual entried in httpd.conf and my.cnf file respectively

Go to /etc/httpd/conf/httpd.conf file by your favorite editor but before that do take the backup of your files

root@server [~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf-bk

Now Go to /etc/httpd/conf/httpd.conf file

root@server [~]# nano /etc/httpd/conf/httpd.conf

and add the following entries :-

Timeout 90
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 5
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 1200
MaxClients 1200

Save and exit and restart apache service

root@server [~]# /etc/init.d/httpd restart

Now go to /etc/my.cnf but before that take a backup of it

root@server [~] cp /etc/my.cnf   /etc/my.cnf-bk
root@server [~] nano /etc/my.cnf

Add the following entries :-

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-locking
max_connections=500
query_cache_limit=1M
query_cache_size=16M
query_cache_type=1
max_user_connections=25
interactive_timeout=10
wait_timeout=10
connect_timeout=10
thread_cache_size=128
key_buffer=16M
join_buffer=1M
max_allowed_packet=16M
table_cache=1024
record_buffer=1M
sort_buffer_size=2M
read_buffer_size=1M
max_connect_errors=10
thread_concurrency=8
myisam_sort_buffer_size=32M
server-id=1
local-infile=0

[mysqld_safe]
open_files_limit = 8192

[mysqldump]
quick
max_allowed_packet=16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer=32M
sort_buffer=32M
read_buffer=16M
write_buffer=16M

[myisamchk]
key_buffer=32M
sort_buffer=32M
read_buffer=16M
write_buffer=16M

[mysqlhotcopy]
interactive-timeout

Save and Exit and restart mysql service

root@server [~] # /etc/init.d/mysql restart

Thats it.

Posted in Cpanel Server, dedicated server, Linux, Server, Web Hosting | Tagged , , , , | Leave a comment

MySQL Database size shows 0 MB in cPanel

When checked in MySQL database I see the size as 0 mb. So made some changes and it worked.

1) SSH to your server as root and edit the cpanel.config file

root@server[~]# nano /var/cpanel/cpanel.config

Search for

disk_usage_include_sqldbs=0

and change to

disk_usage_include_sqldbs=1

If the parameter is not present, add it. Save the file and execute the following command:

root@server[~]# /scripts/update_db_cache

Also you can do this from WHM

2) Login to the WHM, goto Tweak Settings >> ‘SQL’ section and enable the following option:

When displaying disk usage in cpanel/WHM include Postgresql and MySQL.

Thats it.

Posted in Cpanel Server, Linux, mysql, Server | Tagged , , , | Leave a comment