How to Setup Webmin 1.620 using YUM repository on CentOS 6.4 VPS

webminThis post will brief you on how to setup Webmin 1.620 using yum repository in CentOS 6.4 virtual private server (VPS). Webmin is an open source system administration and system configuration tool which provide you web-based interface to manage, administer and configure your CentOS VPS or dedicated server through web browser. It’s provide graphical interface remote administration instead of manually edit the configuration using command line from putty or console.

1. Enabling Yum repository for Webmin. Create the /etc/yum.repos.d/webmin.repo file containing :

[root@centos64 ~]# vi /etc/yum.repos.d/webmin.repo
[Webmin]
name=Webmin Distribution Neutral
#baseurl=http://download.webmin.com/download/yum
mirrorlist=http://download.webmin.com/download/yum/mirrorlist
enabled=1

2. Fetch and install my GPG key :

[root@centos64 ~]# wget http://www.webmin.com/jcameron-key.asc
[root@centos64 ~]# rpm --import jcameron-key.asc

3. Run “yum install” command to install all required dependencies :

[root@centos64 ~]# yum install webmin -y

Example :

[root@centos64 ~]# yum install webmin -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * Webmin: download.webmin.com
 * base: mirrors.hostemo.com
 * extras: mirrors.hostemo.com
 * updates: mirrors.hostemo.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package webmin.noarch 0:1.620-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                Arch                   Version                 Repository              Size
====================================================================================================
Installing:
 webmin                 noarch                 1.620-1                 Webmin                  21 M

Transaction Summary
====================================================================================================
Install       1 Package(s)

Total download size: 21 M
Installed size: 21 M
Downloading Packages:
webmin-1.620-1.noarch.rpm                                                    |  21 MB     04:09
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : webmin-1.620-1.noarch                                                            1/1
Operating system is CentOS Linux
Webmin install complete. You can now login to http://centos64.ehowstuff.local:10000/
as root with your root password.
  Verifying  : webmin-1.620-1.noarch                                                            1/1

Installed:
  webmin.noarch 0:1.620-1

Complete!

4. By default Webmin runs on port 10000, therefore port 10000 need to be open in order to allow you to access web base interface remotely.

[root@centos64 ~]# vi /etc/sysconfig/iptables

Add the following rule to existing iptables firewall :

-A INPUT -m state --state NEW -m tcp -p tcp --dport 10000 -j ACCEPT

Restart IPtables :

[root@centos64 ~]# service iptables restart

5. Access and login to Webmin using URL http://serveripaddress:10000/

7 Useful Linux Utilities

Linux UtilitiesThere are 7 useful linux utilities that you must install on new linux server. Most Linux distributions are equipped with tons of linux command utility, but if you have installed minimal operating system, all these software will not exist. These tools will very useful in your troubleshooting and will help to find possible causes of a problem. Most of the utilities have the same function in CentOS or Red Hat Enterprise Linux (RHEL).

You can easily identify whether the utility installed on your linux operating system or not. You will see one or more below warning :

[root@rhel62 ~]# wget
-bash: wget: command not found
[root@rhel62 ~]# telnet
-bash: telnet: command not found
[root@rhel62 ~]# scp
-bash: scp: command not found
[root@rhel62 ~]# man scp
-bash: man: command not found
[root@rhel62 ~]# nslookup
-bash: nslookup: command not found
[root@rhel62 ~]# dig
-bash: dig: command not found
[root@rhel62 ~]# host
-bash: host: command not found

7 Useful Linux Utilities

1. What is wget ?
Wget is a network utility to retrieve files from the Web using http and ftp, the two most widely used Internet protocols.

Example :

[root@rhel62 ~]# wget http://files2.zimbra.com/downloads/8.0.2_GA/zcs-8.0.2_GA_5569.RHEL6_64.20121210115059.tgz

2. What is telnet ?
Telnet is a network protocol used on the Internet or local area networks. Telnet is a user command and an underlying TCP/IP protocol for accessing remote computers and very useful for troubleshooting and verify the opened ports.

Example :

[root@rhel62 ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 rhel62.ehowstuff.local ESMTP Postfix

3. What is scp ?
scp also call secure copy, is remote file copy utility between hosts on a network. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Example :

[root@rhel62 ~]# scp root@192.168.2.60:/tmp/VMwareTools-9.2.2-893683.tar.gz .
The authenticity of host '192.168.2.60 (192.168.2.60)' can't be established.
RSA key fingerprint is 76:78:87:36:44:c1:46:fa:c4:b4:61:4a:e5:b3:be:e3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.60' (RSA) to the list of known hosts.
root@192.168.2.60's password:
VMwareTools-9.2.2-893683.tar.gz                                                       100%   63MB  63.3MB/s   00:01

4. What is man ?
man is used to display the manual page for other commands It’s help to explain the functions for the commands that commonly used. The term “man” is short for manual.

Example :

[root@rhel62 ~]# man wget
WGET(1)                            GNU Wget                            WGET(1)

NAME
       Wget - The non-interactive network downloader.

SYNOPSIS
       wget [option]... [URL]...

DESCRIPTION
       GNU Wget is a free utility for non-interactive download of files from the Web.  It supports HTTP,
       HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.

       Wget is non-interactive, meaning that it can work in the background, while the user is not logged on.
       This allows you to start a retrieval and disconnect from the system, letting Wget finish the work.
       By contrast, most of the Web browsers require constant userâs presence, which can be a great
       hindrance when transferring a lot of data.

       Wget can follow links in HTML, XHTML, and CSS pages, to create local versions of remote web sites,
       fully recreating the directory structure of the original site.  This is sometimes referred to as
       "recursive downloading."  While doing that, Wget respects the Robot Exclusion Standard (/robots.txt).
       Wget can be instructed to convert the links in downloaded files to point at the local files, for
       offline viewing.

5. What is nslookup, dig, host ?
nslookup, dig and host are part of the bind utilities.These utilities are the basic tools for DNS client and DNS server troubleshooting.

Examples :

[root@rhel62 ~]# nslookup
> set type=mx
> ehowstuff.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
ehowstuff.com   mail exchanger = 0 ehowstuff.com.

Authoritative answers can be found from:
>
[root@rhel62 ~]# dig ehowstuff.com

; < <>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 < <>> ehowstuff.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<
[root@rhel62 ~]# host -t mx ehowstuff.com
ehowstuff.com mail is handled by 0 ehowstuff.com.

How to install wget, scpt, telnet, man, nslookup, dig and host utilities ?

Simply run the following commands :

[root@rhel62 ~]# yum install wget telnet openssh-clients bind-utils man -y

How to Remove Volume Group and Physical Volume on LVM

icon-redhatlinuxBasically, adding and removing LVM will always involves these three logical “layers” which are Physical volumes (pv), Volume groups (vg) and Logical volumes (lv). This post assumed that the Logical volumes haven’t created. In certain situation, linux administrators are required to remove the existing Physical Volume or Volume Group only. It is possible to perform the required task if that system administrator has the right skill on linux. The steps as below :

1. Display the physical volumes and Volume Group using pvdisplay command :

[root@centos63 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               vg_data
  PV Size               4.99 GiB / not usable 2.41 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              1278
  Free PE               1278
  Allocated PE          0
  PV UUID               qTmTeq-8qoL-xxEk-Dj5V-zOjl-vEag-P6Jl7L

2. Remove the Volume Group using vgremove command :

[root@centos63 ~]# vgremove vg_data
  Volume group "vg_data" successfully removed

3. Remove Physical Volume using pvremove command :

[root@centos63 ~]# pvremove /dev/sdb1
  Labels on physical volume "/dev/sdb1" successfully wiped

Additional Note :
How to Remove a Logical Volume on CentOS 6.3/RHEL6

Configure Network Time Protocol (NTP) on CentOS 6.3

Linux LogoAs opposed to the manual setup, it is possible to synchronize the system clock with a remote server over the Network Time Protocol (NTP). NTP is an Internet protocol used to synchronize the clocks of computers or servers to some NTP server on internet or intranet.

Steps A
1. To synchronization immediately or for the one-time synchronization only, use the ntpdate command as below :

[root@centos63 ~]# ntpdate -q time.internet.com

2. Enable running the ntpdate at boot time:

[root@centos63 ~]# chkconfig ntpdate on

Steps B
However, there are alternative way to set the ntpd daemon to synchronize the time at boot time automatically :

1. Install ntpd service daemon :

[root@centos63 ~]# yum install ntp -y

2. Open the NTP configuration file /etc/ntp.conf :

[root@centos63 ~]# vi /etc/ntp.conf

3. Now add or edit the list of public NTP servers.

server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org

4. Set the proper permissions, giving the unrestricted access to localhost only:

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1

5. Restart the NTP daemon:

[root@centos63 ~]# service ntpd restart
Shutting down ntpd:                                        [  OK  ]
Starting ntpd:                                             [  OK  ]

6.Set ntpd daemon is started at boot time :

[root@centos63 ~]# chkconfig ntpd on

How to Install Webmin 1.600 on Linux CentOS 6.3 Using RPM

webminWebmin is a open source web-based system administration tool and system configuration tool for Unix servers and services. It’s useful for linux administrator especially the Linux newbies as it can avoid misconfiguration and avoid doing mistake. Webmin can administer other services and server configuration using a web browser remotely. You can setup user accounts, Apache, MySQL, FTP. DNS, file sharing and Etc. Follow below steps to install Webmin 1.600 on Linux CentOS 6.3 Using RPM package.

1. Download required RPM file :

http://download.webmin.com/download/yum/

[root@centos63 ~]# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.600-1.noarch.rpm

2. Add the GPG Key:

[root@centos63 ~]# rpm --import http://www.webmin.com/jcameron-key.asc

3. Install RPM version of Webmin as below :

[root@centos63 ~]# rpm -Uvh webmin-1.600-1.noarch.rpm
Preparing...                ########################################### [100%]
Operating system is CentOS Linux
   1:webmin                 ########################################### [100%]
Webmin install complete. You can now login to http://centos63.ehowstuff.local:10000/
as root with your root password.

4. Start, Stop and Restart Webmin service :

To start :

[root@centos63 ~]# /etc/rc.d/init.d/webmin start

To Stop :

[root@centos63 ~]# /etc/rc.d/init.d/webmin stop
Stopping Webmin server in /usr/libexec/webmin

To Restart :

[root@centos63 ~]# /etc/rc.d/init.d/webmin restart
Stopping Webmin server in /usr/libexec/webmin
Starting Webmin server in /usr/libexec/webmin
Pre-loaded WebminCore

How to Secure OpenSSH (SSHD) on Linux

OpenSSH is a open source alternative to the proprietary Secure Shell software. It is also the SSH connectivity tools that allows you to remotely login, transfer remote file via scp or sftp. It was created as an open source alternative to the proprietary Secure Shell software. OpenSSH options are controlled through the /etc/ssh/sshd_config file. In order to improve OpenSSH server security, certain default sshd setting need to be change. This post will show you three example to Secure OpenSSH (SSHD) on Linux. This steps has been tested on CentOS 6.3 and may working on CentOS 6.2, CentOS 5.x and Redhat Enterprise Linux 5 (RHEL 5) and Redhat Enterprise Linux 6 (RHEL 6).

1.Change SSH Default Port :

By default ssh runs on port 22. Hacker would need to know the SSH port number in order to access your system. One of the method to improve security is to change the default port to a non-standard port. That would helps to stop brute force attacks.

#Port 22

Uncomment and change to :

Port 2202

2. Disable Root Login (PermitRootLogin) :

Add the following entry to sshd_config to disable root to login to the server directly.

#PermitRootLogin yes

Uncomment and change to :

PermitRootLogin no

3. Listen Specific IP only :

By default ssh will listen on all of the above ip-addresses. If you want users to login only using ip-address 192.168.1.200 and 192.168.1.202, do the following in your sshd_config :

ListenAddress 192.168.1.200
ListenAddress 192.168.1.202

How to Install Subversion on CentOS 6.3

This post will cover the quick steps to install Subversion 1.6 on linux CentOS 6.3 server. Apache Subversion (often abbreviated SVN) is a open source software versioning and revision control system. Some people called it source code control(SCC) software and source code management(SCM) software. By using subversion, developer will able to keep tracks the changes of their code, who is authoring the file, compare the source code and etc.

[root@centos63 ~]# yum install subversion mod_dav_svn -y

Example :

[root@centos63 ~]# yum install subversion mod_dav_svn -y
Loaded plugins: fastestmirror, presto, priorities
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * extras: centos.ipserverone.com
 * updates: centos.ipserverone.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mod_dav_svn.i686 0:1.6.11-7.el6 will be installed
---> Package subversion.i686 0:1.6.11-7.el6 will be installed
--> Processing Dependency: perl(URI) >= 1.17 for package: subversion-1.6.11-7.el6.i686
--> Processing Dependency: libneon.so.27 for package: subversion-1.6.11-7.el6.i686
--> Running transaction check
---> Package neon.i686 0:0.29.3-2.el6 will be installed
--> Processing Dependency: libproxy.so.0 for package: neon-0.29.3-2.el6.i686
--> Processing Dependency: libpakchois.so.0 for package: neon-0.29.3-2.el6.i686
---> Package perl-URI.noarch 0:1.40-2.el6 will be installed
--> Running transaction check
---> Package libproxy.i686 0:0.3.0-2.el6 will be installed
--> Processing Dependency: libproxy-python = 0.3.0-2.el6 for package: libproxy-0.3.0-2.el6.i686
--> Processing Dependency: libproxy-bin = 0.3.0-2.el6 for package: libproxy-0.3.0-2.el6.i686
---> Package pakchois.i686 0:0.4-3.2.el6 will be installed
--> Running transaction check
---> Package libproxy-bin.i686 0:0.3.0-2.el6 will be installed
---> Package libproxy-python.i686 0:0.3.0-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                      Arch                Version                   Repository         Size
====================================================================================================
Installing:
 mod_dav_svn                  i686                1.6.11-7.el6              base               80 k
 subversion                   i686                1.6.11-7.el6              base              2.2 M
Installing for dependencies:
 libproxy                     i686                0.3.0-2.el6               base               38 k
 libproxy-bin                 i686                0.3.0-2.el6               base              8.0 k
 libproxy-python              i686                0.3.0-2.el6               base              8.3 k
 neon                         i686                0.29.3-2.el6              base              120 k
 pakchois                     i686                0.4-3.2.el6               base               21 k
 perl-URI                     noarch              1.40-2.el6                base              117 k

Transaction Summary
====================================================================================================
Install       8 Package(s)

Total download size: 2.6 M
Installed size: 12 M
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 2.6 M
(1/8): libproxy-0.3.0-2.el6.i686.rpm                                         |  38 kB     00:00
(2/8): libproxy-bin-0.3.0-2.el6.i686.rpm                                     | 8.0 kB     00:00
(3/8): libproxy-python-0.3.0-2.el6.i686.rpm                                  | 8.3 kB     00:00
(4/8): mod_dav_svn-1.6.11-7.el6.i686.rpm                                     |  80 kB     00:00
(5/8): neon-0.29.3-2.el6.i686.rpm                                            | 120 kB     00:00
(6/8): pakchois-0.4-3.2.el6.i686.rpm                                         |  21 kB     00:00
(7/8): perl-URI-1.40-2.el6.noarch.rpm                                        | 117 kB     00:00
(8/8): subversion-1.6.11-7.el6.i686.rpm                                      | 2.2 MB     00:20
----------------------------------------------------------------------------------------------------
Total                                                               111 kB/s | 2.6 MB     00:24
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : perl-URI-1.40-2.el6.noarch                                                       1/8
  Installing : libproxy-python-0.3.0-2.el6.i686                                                 2/8
  Installing : libproxy-0.3.0-2.el6.i686                                                        3/8
  Installing : libproxy-bin-0.3.0-2.el6.i686                                                    4/8
  Installing : pakchois-0.4-3.2.el6.i686                                                        5/8
  Installing : neon-0.29.3-2.el6.i686                                                           6/8
  Installing : subversion-1.6.11-7.el6.i686                                                     7/8
  Installing : mod_dav_svn-1.6.11-7.el6.i686                                                    8/8
  Verifying  : libproxy-bin-0.3.0-2.el6.i686                                                    1/8
  Verifying  : libproxy-python-0.3.0-2.el6.i686                                                 2/8
  Verifying  : perl-URI-1.40-2.el6.noarch                                                       3/8
  Verifying  : pakchois-0.4-3.2.el6.i686                                                        4/8
  Verifying  : mod_dav_svn-1.6.11-7.el6.i686                                                    5/8
  Verifying  : neon-0.29.3-2.el6.i686                                                           6/8
  Verifying  : libproxy-0.3.0-2.el6.i686                                                        7/8
  Verifying  : subversion-1.6.11-7.el6.i686                                                     8/8

Installed:
  mod_dav_svn.i686 0:1.6.11-7.el6                   subversion.i686 0:1.6.11-7.el6

Dependency Installed:
  libproxy.i686 0:0.3.0-2.el6  libproxy-bin.i686 0:0.3.0-2.el6  libproxy-python.i686 0:0.3.0-2.el6
  neon.i686 0:0.29.3-2.el6     pakchois.i686 0:0.4-3.2.el6      perl-URI.noarch 0:1.40-2.el6

Complete!

How to Find Default Gateway IP address on Linux

A default gateway is the node (a router) or network point on the computer network that serves as an access point and entrance to another network. It passes traffic between different subnets and networks. Computers running on the network using IP, a default gateway address is needed to reach all computers that are not on the same local IP subnet. This post will show you how to Find default gateway IP address on linux operating system. This command has been tested on CentOS 6.3.

1. Print default gateway using route command :

[root@centos63 ~]# route

Output :

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

2. Print default gateway using netstat command :

[root@centos63 ~]# netstat -rn

Output :

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

Note : The flag U indicates that route is up and G indicates that it is gateway.

How to Remove a Logical Volume on CentOS 6.3/RHEL6

In previous post, i have cover the steps to create additional Logical volume manager (LVM). In certain situation, linux administrator is required to remove the existing logical volume. It is possible to perform the required task if that system administrator has the right skill on linux. Otherwise, they will put themselves and the organization in the disaster or risk as this working with the system’s data. This post assumed centos63_vol has been created and will be remove later. In summary, removing a logical volume (centos63_vol) will involve the following processes:

a) Unmount the LV
b) Remove the LV
c) Update /etc/fstab

1. Begin by listing all the logical volumes on the system :

[root@centos63 ~]# lvs
  LV           VG          Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
  lv_root      vg_centos63 -wi-ao-- 5.54g
  lv_swap      vg_centos63 -wi-ao-- 1.97g
  centos63_vol vg_data     -wi-ao-- 4.99g

2. Check current disk layout and find where centos63_vol is mounted :

[root@centos63 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                      5.5G  2.2G  3.1G  41% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda1             485M   65M  395M  15% /boot
/dev/mapper/vg_data-centos63_vol
                      5.0G  139M  4.6G   3% /mydata

3. View current /etc/fstab value :

[root@centos63 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Jul 15 20:17:38 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_centos63-lv_root /                       ext4    defaults        1 1
UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos63-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/vg_data/centos63_vol /mydata                       ext4    defaults        1 1

4. Unmount centos63_vol (mounted at /mydata) :

[root@centos63 ~]# umount /mydata

5. Verify that centos63_vol has unmounted :

[root@centos63 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                      5.5G  2.2G  3.1G  41% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda1             485M   65M  395M  15% /boot

6. Remove the logical volume /dev/mapper/vg_data-centos63_vol :

[root@centos63 ~]# lvremove /dev/mapper/vg_data-centos63_vol
Do you really want to remove active logical volume centos63_vol? [y/n]: y
  Logical volume "centos63_vol" successfully removed

7. Verify the logical volume has been removed :

[root@centos63 ~]# lvs
  LV      VG          Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
  lv_root vg_centos63 -wi-ao-- 5.54g
  lv_swap vg_centos63 -wi-ao-- 1.97g
[root@centos63 ~]#

8. Update /etc/fstab to reflect the removal of the file system :

[root@centos63 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Jul 15 20:17:38 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_centos63-lv_root /                       ext4    defaults        1 1
UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos63-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

How to Check Realtime RAM Memory Usage Available in Linux VPS

rhelOn the previous post, i have teach you on how to check the memory usage on linux virtual Private Server (VPS) but only top command had provide real-time information and updates . This quick post will covers on how to check realtime RAM memory usage available in Linux VPS using watch command. Watch runs command repeatedly, displaying its output change over time or at regular intervals. Watch will run until interrupted. This command has been tested on Redhat Linux Enterprise 6 (RHEL 6) and may working on CentOS 6.x as well.

The basic syntax of watch is :

# watch [option(s)] command

1. Check memory usage using “top” command. Watch command not required for top command as top will update the result periodically. :

[root@rhel6 ~]# top

2. Check memory usage using “/proc/meminfo” with watch command :

[root@rhel6 ~]# watch -n 1 cat /proc/meminfo

Output :

Every 1.0s: cat /proc/meminfo                                               Mon Oct 15 13:48:17 2012

MemTotal:        1031320 kB
MemFree:          626372 kB
Buffers:           58576 kB
Cached:           217004 kB
SwapCached:            0 kB
Active:           148516 kB
Inactive:         164708 kB
Active(anon):      37816 kB
Inactive(anon):       84 kB
Active(file):     110700 kB
Inactive(file):   164624 kB
Unevictable:           0 kB
Mlocked:               0 kB
HighTotal:        141256 kB
HighFree:            280 kB
LowTotal:         890064 kB
LowFree:          626092 kB
SwapTotal:       2064376 kB
SwapFree:        2064376 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:         37652 kB
Mapped:            19096 kB
Shmem:               264 kB
Slab:              81048 kB
SReclaimable:      62096 kB
SUnreclaim:        18952 kB
..
..
..

3. Check memory usage using “free” with watch command :

[root@rhel6 ~]# watch -n 1 free

Output :

Every 1.0s: free                                                            Mon Oct 15 13:47:26 2012

             total       used       free     shared    buffers     cached
Mem:       1031320     404548     626772          0      58564     217004
-/+ buffers/cache:     128980     902340
Swap:      2064376          0    2064376

4. Check memory usage using “vmstat” with watch command :

[root@rhel6 ~]# watch -n 1 vmstat

Output :

Every 1.0s: vmstat                                                          Mon Oct 15 13:46:44 2012

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 626280  58552 217004   30    0     0    14   46   73  0  1 98  1  0

4 Top Command Howto on Linux RHEL 6/CentOS 6

In this article, i will help you to explore most frequently used top commands that linux system administrator use when analyzing the linux performance and use for daily system administrative jobs. Top command displays system summary information such as tasks currently being managed by the Linux kernel, displays ongoing look at processor activity in real time and will displays a listing of the most CPU-intensive tasks on the system. It also will show the processor and memory are being used and other information like running processes. It will help you to summarize how much of your system’s resources are taking up.

1. How to display top command result :

[root@rhel6 ~]# top

top
This command will show information like tasks, memory, cpu load average, swap and number of users. Press ‘q’ to quit window.

2. How to display selected user using top -u :

[root@rhel6 ~]# top -u apache

top

3. How to display specific process with given PIDs Using top -p(e.g PID 2449, 2450) :

[root@rhel6 ~]# top -p 2449,2450

top

4. How to quit top command after a specified number of iterations :

[root@rhel6 ~]# top -n 10

This top command will automatically exit after 10 number of repetition.

How to Setup Secure SSH Without Password on Linux CentOS

This quick post will show the steps to setup SSH access without password, but with passphrase key on Linux CentOS. After completely performed the following steps, you can ssh from one system to another without specifying any password. This steps has been tested on CentOS 6.3 and may working on other CentOS versions and Redhat Enterprise linux versions as well.

Client = 192.168.1.54
Server = 192.168.1.55

1. Create Public and private keys from openssh and save it :

[root@client ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
9c:41:a8:b5:d1:7f:64:c5:91:89:38:bf:5a:4c:30:16 root@centos63.ehowstuff.local
The key's randomart image is:
+--[ RSA 2048]----+
|       o. Eo +o+ |
|      +.. * + +  |
|     o o.o B     |
|    . .. o. +    |
|        S  + .   |
|            +    |
|           o     |
|          .      |
|                 |
+-----------------+
[root@client ~]# ls -l /root/.ssh/
total 8
-rw------- 1 root root 1743 Oct  4 23:04 id_rsa
-rw-r--r-- 1 root root  411 Oct  4 23:04 id_rsa.pub

2. Change the mode of public key :

[root@client ~]# chmod 600 /root/.ssh/id_rsa.pub
[root@client ~]# ls -l /root/.ssh/
total 8
-rw------- 1 root root 1743 Oct  4 23:04 id_rsa
-rw------- 1 root root  411 Oct  4 23:04 id_rsa.pub

3. Make a .ssh directory in the home of the user on server :

[root@server ~]# mkdir .ssh
[root@server ~]# cd .ssh/
[root@server .ssh]# pwd
/root/.ssh

4. From Client, transport the key to the server :

[root@client .ssh]# scp id_rsa.pub root@192.168.1.55:/root/.ssh/
The authenticity of host '192.168.1.55 (192.168.1.55)' can't be established.
RSA key fingerprint is 71:fc:a2:51:b3:ed:bc:7b:68:ec:9e:51:a8:04:ab:fd.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.55' (RSA) to the list of known hosts.
root@192.168.1.55's password:
id_rsa.pub                                                        100%  411     0.4KB/s   00

5. Change the key to authorized key in .ssh folder :

[root@server ~]# cd .ssh/
[root@server .ssh]# pwd
/root/.ssh
[root@server .ssh]# cat id_rsa.pub >>authorized_keys
[root@server .ssh]# ls
authorized_keys  id_rsa.pub

View the authorized_keys :

[root@ldap .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqToSfMUihcL/lFA6chuVTO77FAHNJFs102lULCVS8XwLFoDbauHdk61x3/rAHDj1HSFbb/heuHUdRndT1CJvSaK+lZ6mKMqvfqlGBvgcF+9t0+Mx3/8Nwaoy891bmiRV81UA8ywwSGx/hw6+LgLTn0F1dh+bhezdAyIV+WMM6QUW9v6APncLw0EtbZX/IMuJCizT+ka+yUgxRB8nteTKYyG1/fCwo7utKBD9Sypt4VBvMFIcoKhIoTzhAxUDxXwmOGn5mUB8aDLzUsf3eJuGOMLVH/k+zByt6tfZ9V/EFUMOVmXV33XCgewJa6RiUm0aXnmYWd722ju/tZyFqzip1w== root@client.ehowstuff.local

6. Now Connect your server without passsword but with the passphrase key :

[root@client ~]# ssh root@192.168.1.55
Enter passphrase for key '/root/.ssh/id_rsa':
Last login: Thu Oct  4 23:08:17 2012 from 192.168.1.52
[root@server ~]#