How to Create and Extract a gzip Compressed Archive File on Linux

Archiving and compressing files are useful when creating backups and transferring data across a network. One of the oldest and most common commands for creating and working with the backup archives is tar command. tar originally stood for tape archiver. With tar, we cab gather large sets of the files into a single file(archive). We can indicate that the archive should be compressed using gzip or bzip2 compression.

To use tar command, one of the three following options is required.
c = create and archive
x = extract and archive or
t = test or list the contents of an archive

Other options let you add vebosity(v), indicate the name of the archive file to create or extract and set the type of compression to use (g for gzip or j or bzip2).

This example will show an examples of tar syntax which will create (c) a gzip compressed(z) archive file (f /tmp/etc.tar.gz) of the /etc directory. Be verbose(v) with the output. This command has been tested on Redhat Enterprise Linux 6 (RHEL6) with root access and it will backup entire /etc directory.

[root@rhel6 ~]# tar cvzf /tmp/etc.tar.gz /etc

Meanwhile, this tar command will show hpw to extract(x) and view(v) all files from a gzip-compressed(z) archive(f /tmp/etc.tar.gz) to the /backup-test directory.

Create /backup-test directory and cd to /backup-test.

[root@rhel6 /]# mkdir /backup-test
[root@rhel6 /]# cd /backup-test
[root@rhel6 backup-test]# pwd
/backup-test

Extract(x) and view(v) all files from a gzip-compressed(z) archive(f /tmp/etc.tar.gz) to the /backup-test directory.

[root@rhel6 backup-test]# tar xvzf /tmp/etc.tar.gz

List the extracted directory ;

[root@rhel6 backup-test]# ls
etc

How to use Basic Regular Expression with grep command on Linux

Regular expressions are special text strings that used to search for and match patterns in text. To make the search expression more specific, it can work together with the grep command. The grep command is the General Regular Expression Parser; it searches a file for strings matching a given regular expression, and by default it the prints out any line containing a string that matches. There are many useful options which can be set for grep which affect it output. This examples will show how to use caret ^ and dollar sign $ to print more specific output. This examples has been tested on Redhat Enterprise Linux 6 server. It may works on CentOS as well.

The caret ^ is meta-characters that respectively match the empty string at the beginning of a line.

Anchor : line begins with...

Meanwhile, the dollar sign $ is a meta-characters that respectively match the empty string at the end of a line.

Anchor : line ends with...

Examples :
1. Print all usernames that begin with the letter e :

[root@rhel6 ~]# grep '^e' /etc/passwd
ehowstuff:x:503:503::/home/ehowstuff:/bin/bash

2. Print all usernames that begin with the letter g :

[root@rhel6 ~]# grep '^g' /etc/passwd
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

3. Print all usernames that begin with the letter a :

[root@rhel6 ~]# grep '^a' /etc/passwd
adm:x:3:4:adm:/var/adm:/sbin/nologin
abrt:x:499:499::/etc/abrt:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin

4. Print all lines that end with the letter h :

[root@rhel6 ~]# grep 'h$' /etc/passwd
root:x:0:0:root:/root:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
test:x:500:500::/home/test:/bin/bash
sambauser1:x:501:501::/home/sambauser1:/bin/bash
ftpuser:x:502:502::/home/ftpuser:/bin/bash
ehowstuff:x:503:503::/home/ehowstuff:/bin/bash
testuser:x:504:504::/home/testuser:/bin/bash

How to Create softlink with ln command on Linux

Symlink, also called softlink, is a symbolic path indicating the abstract location of another file. In addition, a softlink files has the same role as a Windows shortcut. In this post, i will show you on how to create softlink or symlink on linux server. This steps has been tested on linux CentOS 6.2 x86 server.

Some idea on to differentiates softlink and hard link :
A softlink can be used across files systems. A hard link increases the link count. When you create hard link you can remove the original file without losing data.

To create symlink, simply run this command :

ln -s [target directory or file] [symlink shortcut]
[root@centos62 ~]# ln -s /public/index.html /home/ehowstuff/index.html

After creating the symbolic link above, /public/index.html will point to /home/ehowstuff/index.html.

How to Restore and Recover Lost Bookmark on Mozilla Firefox

During normal usage of Firefox, you may discover that your Mozilla firefox has suddenly lost your bookmarks. In most cases, the bookmarks are not lost. Losing your bookmark just like you lost all your best friend contacts number. There are a number of reasons that can cause your bookmarks to disappear or suddenly lost from your Mozilla Firefox. The most common reasons is because Mozilla Firefox Web browser is not properly close before power down or restart the computer. Make sure you always close the browser before shutting down or restarting the computer. Another reasons are the bookmarks to disappear problem also be caused by a faulty or misconfigured plugin or extension, or even infected by malware.

This article i will help you restore and recover lost or missing bookmarks. Follow these quick steps.

1. Open your Mozilla Firefox.
2. Click on Bookmarks Menu.
firefox
3. Click Show All Bookmarks, Library window will appear.
4. On Library window, Click on “Import and Backup”.
firefox
5. Go to “Restore” then select on which date you want to restore.
6. When a message appears asking you to confirm the restore, click “Yes”.

How To Check SELinux Status on CentOS 5.8

SELinux is a Linux feature that provides a mechanism for supporting access control security policies in the Linux kernel. In this post, i will share on how to check Security-Enhanced Linux (SELinux) status on linux CentOS 5.8 server. First method to check the SELinux status is using sestatus command. Another method is check through configuration file.

1. Simply run sestatus command to immediately display the SELinux status :

[root@centos58 ~]# sestatus

Result :

SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 21
Policy from config file:        targeted

2. Display “/etc/selinux/config” config file to get SELINUX status :

[root@centos58 ~]# cat /etc/selinux/config

Example :

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0


In above configuration file, SELinux is set to “SELINUX=enforcing”, meaning that SELinux is enabled.

How to Change Hostname on CentOS 5.8

In this post, i will show you the basic guides on how to change the hostname on linux CentOS 5.8 server. Assumed that you have root account access on this CentOS server and this steps may working on RHEL 6, RHEl 5, CentOS 5.5, CentOS 5.6, CentOS 5.7, CentOS 6.0, CentOS 6.1 and CentOS 6.2.

1. Check current hostname :

[root@localhost ~]# hostname
localhost.localdomain

2. Modify “/etc/sysconfig/network” to change hostname :

[root@localhost ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

Change the hostname to the following :

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centos58.ehowtuff.local

Alternatively, you can execute the following command :

[root@localhost ~]# hostname centos58.ehowtuff.local

3. Change host file :

[root@localhost ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

127.0.0.1 centos58.ehowstuff.local centos58

4. Reboot the server.

[root@localhost ~]# reboot

How to Install Disqus on WordPress

Disqus is a world favorite comment system and discussion platform that improves discussion on websites or blogs and connects conversations across the web. It is free to register and you can install more that one websites in one account. In this post, i will share on how to install Disqus on WordPress blog.

1. Before you install disqus, your wordpress comment platform will look like below :
disqus

2.Go to disqus.com. Please register if you don’t have free account. You can proceed to login if you have an account on disqus.com.
disqus

3. Click Dashboard then press “+Add” :
disqus

4. Register your blog to use Disqus. Click continue to proceed :
disqus

5. Click Continue if you select default setting :
disqus

6. Select ” WordPress” :
disqus

7. Now it’s time to install the disqus plugin into your wordpress blog :
disqus

8. Login to your wordpress blog dashboard. Download the plugin name “Disqus comment system”. Activate the plugin :
disqus

9. After you have activated the disqus plugin, you may proceed to configure it :
disqus

10. continue to configure disqus :
disqus

11. Select a website that you want to configure disqus comment system :
disqus

12. Now you blog has been installed and configured with disqus.
disqus

13. Start to export your comments :
disqus

14. Please wait while it’s processing.. :
disqus

15. Your wordpress comments has been exported to disqus platform :
disqus

16. Your new blog comment will be more advance and interesting by using disqus comments system :
disqus

How to Check MX Record Using nslookup Command on Windows

nslookup is a command-line tool for network administrator and system administrator that available in many computer operating systems such as linux and windows for querying the Domain Name System (DNS). nslookup can obtain domain name or IP address or for any other specific DNS record. In this post, i will share how nslookup command will useful to check MX record on windows command prompt.

Open windows command prompt and enter “nslookup” command :

C:\>nslookup
Default Server:  google-public-dns-a.google.com
Address:  8.8.8.8

> set type=mx

or
Alternatively, you can run “set q=mx” which will return you the same result with “set type=mx” command :

C:\>nslookup
Default Server:  google-public-dns-a.google.com
Address:  8.8.8.8

> set q=mx

After entering “set typ=mx” or “set q=mx”, you can proceed to enter the domain name that you want to check it’s mx records. In this example, i will share the mx records for gmail.com, yahoo.com and bloggermy.com.

Check MX records for gmail.com

> gmail.com
Server:  google-public-dns-a.google.com
Address:  8.8.8.8

Non-authoritative answer:
gmail.com       MX preference = 30, mail exchanger = alt3.gmail-smtp-in.l.google.com
gmail.com       MX preference = 5, mail exchanger = gmail-smtp-in.l.google.com
gmail.com       MX preference = 40, mail exchanger = alt4.gmail-smtp-in.l.google.com
gmail.com       MX preference = 20, mail exchanger = alt2.gmail-smtp-in.l.google.com
gmail.com       MX preference = 10, mail exchanger = alt1.gmail-smtp-in.l.google.com

Check MX records for yahoo.com

> yahoo.com
Server:  google-public-dns-a.google.com
Address:  8.8.8.8

Non-authoritative answer:
yahoo.com       MX preference = 1, mail exchanger = mta5.am0.yahoodns.net
yahoo.com       MX preference = 1, mail exchanger = mta6.am0.yahoodns.net
yahoo.com       MX preference = 1, mail exchanger = mta7.am0.yahoodns.net

Check MX records for bloggermy.com

> bloggermy.com
Server:  google-public-dns-a.google.com
Address:  8.8.8.8

Non-authoritative answer:
bloggermy.com   MX preference = 5, mail exchanger = ALT1.ASPMX.L.GOOGLE.com
bloggermy.com   MX preference = 5, mail exchanger = ALT2.ASPMX.L.GOOGLE.com
bloggermy.com   MX preference = 10, mail exchanger = ASPMX2.GOOGLEMAIL.com
bloggermy.com   MX preference = 10, mail exchanger = ASPMX3.GOOGLEMAIL.com
bloggermy.com   MX preference = 0, mail exchanger = bloggermy.com
bloggermy.com   MX preference = 1, mail exchanger = ASPMX.L.GOOGLE.com

How to Check Opened Port on Linux VPS Server

By default, the linux operating system manages 65536 ports. If you run Virtual private Server (VPS) on linux platform, it is better to turn off any services or ports that you don’t actually need. This is to ensure your VPS server will not become avenues of attack for any security threats. Simply run these commands to easily see open ports on your Linux VPS server that are currently listening.

1. List opened ports with protocol name :

[root@vps-server ~]# netstat --listen --tcp

Examples :

[root@vps-server ~]# netstat --listen --tcp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 *:mysql                     *:*                         LISTEN
tcp        0      0 *:http                      *:*                         LISTEN
tcp        0      0 *:ftp                       *:*                         LISTEN
tcp        0      0 *:ssh                       *:*                         LISTEN

2. List opened ports with protocol number :

[root@vps-server ~]# netstat --listen --tcp -n

Examples :

[root@vps-server ~]# netstat --listen --tcp -n
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN

How to Check VPS Network Speed

Several important factors to consider before buying a Virtual Private Server (VPS) are Internet connection speed, I/O speed, CPU performance and the server or network uptime. Actually, you can get a complete comparison about the VPS performance at serverbear.com websites, but if you want a second opinion on how fast is your connection speed VPS, you can perform the speedtest by yourself. In this post I will share with you how to check the speed of network for Linux VPS. These steps have been tested on a CentOS 5 and CentOS 6 VPS hosted at different locations in the United States.

1. Test 100MB File on the CentOS 5 VPS located at North Carolina, USA :

# wget -O /dev/null - http://cachefly.cachefly.net/100mb.test

Example :

# wget -O /dev/null - http://cachefly.cachefly.net/100mb.test
--2012-04-19 17:40:00--  http://cachefly.cachefly.net/100mb.test
Resolving cachefly.cachefly.net... 205.234.175.175
Connecting to cachefly.cachefly.net|205.234.175.175|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: `/dev/null'

100%[=======================================================>] 104,857,600 11.1M/s   in 9.1s

2012-04-19 17:40:09 (11.0 MB/s) - `/dev/null' saved [104857600/104857600]

FINISHED --2012-04-19 17:40:09--
Downloaded: 1 files, 100M in 9.1s (11.0 MB/s)

100Mbps port = 12.5M/s Maximum speed

2. Test 1GB File on the CentOS 6 VPS located at New York City, USA :

# wget -O /dev/null - http://speedtest.nyc.solvps.com/1GB.zip
--2015-03-08 03:43:25--  http://speedtest.nyc.solvps.com/1GB.zip
Resolving speedtest.nyc.solvps.com... 104.128.230.11
Connecting to speedtest.nyc.solvps.com|104.128.230.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1073741824 (1.0G) [application/zip]
Saving to: â/dev/nullâ

100%[====================================>] 1,073,741,824 33.1M/s   in 37s

2015-03-08 03:44:02 (27.8 MB/s) - â/dev/nullâ

FINISHED --2015-03-08 03:44:02--
Downloaded: 1 files, 1.0G in 37s (27.8 MB/s)

1Gigabit port = 125 MB/s Maximum speed

VPS network speed

How to SSH Without Password on Linux

In this post, i will share with you the steps on how to setup and configure linux servers to allow SSH without password. After completely performed the following steps, you can ssh from one system to another without specifying a password. With this, you can automate your tasks such as automatically copy data from server1 to server2. This steps has been tested on CentOS 6.2 and may working on other CentOS versions and Redhat Enterprise linux versions as well.

Notes:
-Client server is server2. This is where ssh session is started via the ssh command.
-Main server is server1. This is where ssh session from server2 will be connects to.
-This steps has been tested using root account on CentOS 6.2.

1. Add and configure /etc/hosts for both servers (ssh client and ssh server) :

[root@server1 ~]# vi /etc/hosts
[root@server2 ~]# vi /etc/hosts

Add this lines to /etc/hosts on both servers (ssh client and ssh server) :

192.168.1.44 server1
192.168.1.48 server2

2. Login as a root to server2 and create hidden directory called ssh under your account. This steps has been tested using root account :

[root@server2 ~]# mkdir -p $HOME/.ssh

Set permission as below :

[root@server2 ~]# chmod 0700 $HOME/.ssh

3. Configure SSH Keys Authentication by typing the following command :

[root@server2 ~]# ssh-keygen

Whatever it appears just press enter until it ends, press enter for passphase as well :

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
83:20:f0:1d:11:db:7e:e9:be:d6:ed:a2:e7:f1:ac:34 root@server2
The key's randomart image is:
+--[ RSA 2048]----+
|.   +o           |
| o . +           |
|  o + .          |
|   . o . .       |
|      o S        |
|       o .       |
|        ..E.     |
|       ...+=.    |
|       .+=o++    |
+-----------------+

4. Check what files that was produced by ssh-keygen command. Normally it’s automatically stored under $HOME/.ssh :

[root@server2 ~]# ls $HOME/.ssh
id_rsa  id_rsa.pub

5. Login as a root to server1 and create hidden directory called ssh under your account :

[root@server1 ~]# mkdir -p $HOME/.ssh

Set permission as below :

[root@server1 ~]# chmod 0700 $HOME/.ssh

6. From server2, copy over the id_rsa.pub (public key) to server1 :

[root@server2 ~]# scp $HOME/.ssh/id_rsa.pub root@server1:$HOME/.ssh
The authenticity of host 'server1 (192.168.1.44)' 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 'server1' (RSA) to the list of known hosts.
root@server1's password:
id_rsa.pub                                                        100%  394    

7. On server1, enter ssh directory and execute these commands :

[root@server1 ~]# cd $HOME/.ssh

Export id_rsa.pub key to authorized_keys

[root@server1 .ssh]# cat id_rsa.pub >> $HOME/.ssh/authorized_keys

Set permission as below :

[root@server1 .ssh]# chmod 0600 $HOME/.ssh/authorized_keys

8. Your have successfully configure and allow ssh without password. From now on you can log into server1 as root from server2 without any password :

[root@server2 ~]# ssh root@server1

How To Disable The IPv6 on CentOS 5.8

By default, IPv6 has been set to enabled on linux CentOS 5.8 minimum installation. If you plan to disable this feature, you can follow these steps to completely disable it. This can avoid accidentally loaded IPv6 module. This steps may working on other CentOS version.

1. Create disable-ipv6.conf on /etc/modprobe.d/ and add the following line :

[root@centos58 ~]# vi /etc/modprobe.d/disable-ipv6.conf

Add the following line :

install ipv6 /bin/true

Whenever the system needs to load the ipv6 kernel module, it is forced to execute the command true instead of actually loading the module.

2. Edit /etc/sysconfig/network and modify as below :

Set NETWORKING_IPV6 value to “no” :

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

3. Do not forget to disable and stop the IPv6 firewall if exist :

Disable auto start at boot :

[root@centos58 ~]# /sbin/chkconfig ip6tables off

Stop ip6tables service if running :

[root@centos58 ~]# service ip6tables stop

4. Add “net.ipv6.conf.all.disable_ipv6 = 1” into /etc/sysctl.conf

[root@centos58 ~]# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf

or

[root@centos58 ~]# vi /etc/sysctl.conf

Add the following line at the bottom of sysctl.conf file :

..
...
net.ipv4.tcp_syncookies = 1
...

5. Reboot the server is required to complete the steps above.