Linux: disk usage command – du

du is a standard unix command to calculate disk space from Unix/Linux system.

To get the sum space of the directory,

du

To get sum space with human-readable,

du -sh

To get sub directories space

du -sh *

To get sub directories space with all hidden folder,

du -sk .[!.]* * | sort -n

Centos: List SSH user last password changed date with cPanel

To secure your server with cPanel, you might want to consider to request your cPanel user to change your password quarterly.

To get this done, you may consider to use the command name chage.

[email protected] [~]# chage -l username
Last password change                                    : Jul 28, 2012
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

To list all user Last password change date, you may do with the following command,

for i in `ls -l /var/cpanel/users | grep -vE '(\.|system)'| awk '{print $9}'`;do echo $i&&chage -l $i|grep Last;done;

Howto: Configure CloudLinux kernel on pv xen

In other to switch your hosted server with pv xen to CloudLinux server, you may refer to the step as below,

1. Make sure that /etc/sysconfig/kernel is as line below, if the file is not exist, create it,

UPDATEDEFAULT=yes
DEFAULTKERNEL=kernel-xen

2. Install grub if it is not,

yum install grub

3. Check /etc/modprobe.conf is exists and with the following line it is not,

alias eth0 xennet
alias scsi_hostadapter xenblk

4. If you have install the newer kernel, run the following line,

mkinitrd -f /boot/initrd-2.6.xxx.img 2.6.xxx

‘xx’ should be the same as you newly installed kernel-xen version

5. Else, install kernel,

yum install kernel-xen

6. Check if /boot/grub/grub.conf exists, else create it,

ln -s /boot/grub/grub.conf /boot/grub/menu.lst
ln -s /boot/grub/grub.conf /etc/grub.conf

7. Make sure that the /etc/grub.conf is look like,

default=0
timeout=10
title CentOS (2.6.18-308.11.1.el5xen)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-308.11.1.el5xen console=xvc0 root=/dev/sda1 ro
initrd /boot/initrd-2.6.18-308.11.1.el5xen.img

Make sure that the vmlinuz and initrd should be the same.

8. Ask your hosting provider to change the kernel type to pygrub and reboot it.

Linux: Enable and Disable services during Startup

Do you ever wonder that how to setup CentOS (RedHat) Linux server startup service and how the services running?

With CentOS, you may use the command named chkconfig to configure your startup services.

First of all, you need to understand what is Linux runlevels, for more information, you may refer to the URL below,
http://www.mickgenie.com/understand-linux-runlevels/

In this example, let say we could like to set the runlevel at 2, 3, and 5 with httpd (Apache).

To enable the services in startup,

# chkconfig httpd --add
# chkconfig httpd on --level 235

To check which runlevel you have set,

# chkconfig --list httpd

To disable the startup,

# chkconfig httpd off

iftop: Installation guide

If you have a server and you wish to get the actual bandwidth usage on real time basis, you may simply install iftop from your server to track the information time by time.

iftop is a good network monitoring tool to check real time network bandwidth usage and CPU usage.

To download iftop,

# cd /usr/src
# wget http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.17.tar.gz

To install iftop,

# cd /usr/src
# tar zxf iftop-0.17.tar.gz
# cd iftop-0.17

# ./configure
# make
# make install

To use iftop, you may simply type in iftop,

iftop

Or specify the network interface,

iftop -i eth0

SSH: jailshell: fork: retry: Resource temporarily unavailable

Today, one of the customer SSH(cPanel) getting error as below when they logged into their jailed shell access.

-jailshell: fork: retry: Resource temporarily unavailable
-jailshell: fork: retry: Resource temporarily unavailable
-jailshell: fork: retry: Resource temporarily unavailable
-jailshell: fork: retry: Resource temporarily unavailable

To overcome the problem, simply run the following command from root.

for i in `ps aux | grep username | awk '{print $2}'`; do kill -9 $i; done

for i in `cat /proc/mounts | grep username | awk '{print $2}'`; do umount $i; done

Where you should replace the username to your created user.

Apache: service httpd does not support chkconfig

As you know, when you installed your Apache service to your Centos/Redhat server manually (make & make install but not yum) and could like to run the service automatically, you should copy the apachectl from the Apache bin folder to /etc/init.d/ folder as named httpd.

Then you might want to set the chkconfig and facing the error as below,

service httpd does not support chkconfig

To fix this issue, you may simply add the following line to your file at /etc/init.d/httpd.

#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache/logs/httpd.pid
# config: /usr/local/apache/conf/httpd.conf

Then you may chkconfig again,

chkconfig --level 235 httpd on

And now restart your httpd service.

Howto: Password protected a folder from Apache .htaccess

To protect a folder from your website, you may actually use the htpasswd feature available from the server.

To create a password protected folder to /home/user/public_html/important with user named admin, run the following command.

[[email protected] ~]# htpasswd -c /home/user/public_html/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
[[email protected] ~]#

Then, add the following code to your .htaccess file located at /home/user/public_html folder.

AuthUserFile /home/user/public_html/.htpasswd
AuthName "important"
AuthType Basic
Require valid-user

Now, access to your folder with the credential created.

Understand Linux-based RAM and it’s cache

Linux Operating System that powered by Linux kernel have an advanced disk cache algorithm that used to store frequently access data from Hard disk.

This is to explain why some Linux server’s RAM still getting high memory usage even you upgrade your RAM.

To find out how much memory using by the Linux-based server, you may use the linux command “free” to track it. To get the detailed/actual memory usage, you may run the following command from your Linux box.

free -m

You should get some result as below,

             total       used       free     shared    buffers     cached
Mem:         15905       2879      13026          0        384        900
-/+ buffers/cache:       1593      14311
Swap:         3999          0       3999

With the result above, you may see that the used memory is 2879MB and free memory is 13026MB. However, the cached memory is 1593MB while the actual free memory will be 14311MB.