Redirect Site to Maintenance Page using Apache and HTAccess

In this article you will find how to redirect all traffic and all visitors of your site to a maintenance page during site updates.

I’ll show how to create a maintenance page, how to put the site into a maintenance mode and how to bring it back online without restarting Apache.

You’ll learn how to redirect Apache Vhost’s traffic to a maintenance page using either VirtualHost configuration file or using .HTAccess file. (more…)

RegEx: Find Email Addresses in a File using Grep

Here is a best regular expression that will help you to perform a validation and to extract all matched email addresses from a file.

This regular expression matches 99% of the email addresses in use nowadays.

In this article you’ll find a regular expression itself and an example of how to extract matched email addresses from a file with the grep command.

Regular Expression to Match Email Addresses

Use the following regular expression to find and validate the email addresses:

"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b"

Get a List of all Email Addresses with Grep

Execute the following command to extract a list of all email addresses from a given file:

$ grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" file.txt
Option Description
-E, –extended-regexp Use extended regular expression
-o, –only-matching Print email addresses only

Removing First and Last Characters From Strings in Bash

From the following article, you’ll learn how to remove first characters from the beginning of each line in Bash and how to print strings between first and last characters using cut command.

You’ll also learn how to remove last characters of each line using trick with reverse command.

I’ve created a file with the following content and I’ll use it in examples below. So lets say we need to remove first and last characters of each line from the given file.

$ cat file
12345===I Love Bash===54321
12345===I Love Bash===54321
12345===I Love Bash===54321

Remove First N Characters Of Each Line

Use the following command to delete first 5 characters of each line (trim first 5 characters and print each line starting from the 6th character):

$ cat file | cut -c 6-
===I Love Bash===54321
===I Love Bash===54321
===I Love Bash===54321

Print Strings Between First and Last Characters

Use the following command to print strings between 9th and 20th characters of each line in Bash:

$ cat file | cut -c 9-20
I Love Bash
I Love Bash
I Love Bash

Print First N Characters Of Each Line

Use the following command to print first 20 characters of each line in Bash:

$ cat file | cut -c 1-20
12345===I Love Bash
12345===I Love Bash
12345===I Love Bash

Remove Last Character Of Each Line

Using combination of reverse and cut commands we can remove last N characters of each line, as shown below. (source)

Use the following command to delete last character of each line in Bash:

$ rev file | cut -c 2- | rev
12345===I Love Bash===5432
12345===I Love Bash===5432
12345===I Love Bash===5432

Remove Last N Characters Of Each Line

Use the following command to delete last 8 characters of each line in Bash:

$ rev file | cut -c 9- | rev
12345===I Love Bash
12345===I Love Bash
12345===I Love Bash

HowTo: Install and Configure Conky in Linux Mint/Ubuntu/Debian

Conky – is a highly configurable system monitor software.

It is able to monitor many system variables including CPU, memory, swap, disk space, temperature, top, upload, download, system messages.

It has built in IMAP and POP3 support, built in support for many popular music players and much more.

In this article you’ll find how to install and configure Conky in deb-based systems like Linux Mint, Ubuntu or Debian.

I’ll also show how to start, stop, restart Conky and how to setup Conky to start at boot.

Conky Installation

Latest Conky package is included into default Linux Mint, Debian and Ubuntu repositories.

Run the following command to install Conky with all features enabled:

$ sudo apt-get install conky conky-all

I’d also suggest you to install some extra staff that you may need in future:

$ sudo apt-get install curl lm-sensors hddtemp

The following packages will be installed:

Package Description
curl Transfer files through HTTP, HTTPS, FTP and others protocols
lm-sensors Utilities to read temperature/voltage/fan sensors
hddtemp Hard drive temperature monitoring utility

Start | Stop | Restart Conky

Use the following commands to start, stop or restart Conky.

Start Conky

Execute the following command to start Conky in a background:

$ conky -d
Conky: forked to background, pid is 11122

Stop Conky

Execute the following command to stop Conky:

$ pkill conky
Conky: received SIGINT or SIGTERM to terminate. bye!

Restart Conky

Execute the following command to restart Conky:

$ pkill -HUP conky
Conky: received SIGHUP or SIGUSR1. reloading the config file.

It makes Conky reread its configuration file.

Set Conky To Start At Boot

We will set Conky to start at boot by adding it to the “Startup Applications”.

Setup Conky To Run On Startup

Press Alt+F2 to bring up the “Run dialog”.

Type gnome-session-properties if you use GNOME desktop or type mate-session-properties if you use MATE. Press the Run button.

Click the Add button and fill in the fields as follows:

Field Value
Name conky
Command conky -p 15
Comment A system monitor

Reboot.

conky -p 15 command starts Conky with a delay in 15 seconds. We needed it to prevent Conky from starting before the desktop. Change the delay if Conky still appears before the desktop and disappears as soon as wallpaper is loaded.

Conky Configuration

Conky will firstly try to look for a local ~/.conkyrc file and if it doesn’t exist, then it will read the default one – /etc/conky/conky.conf.

Copy the default Conky config to your home directory.

$ cp /etc/conky/conky.conf ~/.conkyrc

Now edit ~/.conkyrc file to make changes to Conky:

$ vi ~/.conkyrc

Additional Information:

HowTo: Grant Root Access to User – Root Privileges – Linux

From this article you’ll learn how to create a user in Linux and grant root access to him or how to grant root privileges to already existent user.

This can be easily done by changing UID (user id) and GID (group id) in /etc/passwd file.

Also you will learn how to just add user to root group and i will explain how to delete user with root privileges.

Actually it is not a good idea to give all the privileges of root to a non-root user and outside the test environment i would not recommend to have multiply superusers. (more…)

CentOS – Disable Iptables Firewall – Linux

The iptables is a built in firewall in the most Linux distributions, including CentOS.

Sometimes it is required to stop the iptables for troubleshooting of the network related problems.

Also, if there are some troubles with the recently installed application – you may see on the related forums a suggestion to stop the firewall temporary in order to check if the application works fine without it.

From this article you’ll learn how to check the current status of the iptables firewall, and how to disable or enable it in CentOS. (more…)

HowTo: Disable SELinux

SELinux is an access control tool that is installed and activated by default in such Linux distributions like RHEL (Red Hat Enterprise Linux), CentOS and Fedora.

If you’ve setup a new system, or installed some new application and it is not working, then you have to check SELinux, because it may be the cause of the problem.

In this article you’ll learn how to check the current status of SELinux, how to disable or enable SELinux temporarily or permanently.

Check the Status of SELinux

Run the following command to check if SELinux is running:

# getenforce

getenforce reports whether SELinux is Enforcing, Permissive, or Disabled.

Disable SELinux Temporarily

The following modifications are temporary and they will be gone after reboot.

Turn OFF SELinux Temporarily

Use the following command to disable SElinux temporarily.

# setenforce 0

Turn ON SELinux Temporarily

Use the following command to enable SElinux temporarily.

# setenforce 1

Disable SELinux Permanently

From the command line, edit the /etc/selinux/config file.

$ cat /etc/selinux/config
# 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=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Turn OFF SELinux Permanently

Change the SELINUX= line in /etc/selinux/config file to:

SELINUX=disabled

Turn ON SELinux Permanently

Change the SELINUX= line in /etc/selinux/config file to:

SELINUX=enforcing

HowTo: Remount /etc/fstab Without Reboot in Linux

The configuration file /etc/fstab contains the necessary information to automate the process of mounting partitions.

You would normally have to reboot your Linux system, after editing this file.

There is a simple way which will remount all the partitions from your /etc/fstab file without restarting the system.

Run the following command as root:

# mount -a

This simple command causes all filesystems mentioned in /etc/fstab to be remounted, except the partitions with noauto option.

SSH: Execute Remote Command or Script – Linux

This is quite a common task for Linux system administrators, when it is needed to execute some command or a local Bash script from a one Linux workstation or a server on another remote Linux machine over SSH.

In this article you will find the examples of how to execute a remote command, multiple commands or a Bash script over SSH between remote Linux hosts and get back the output (result).

This information will be especially useful for ones, who want to create a Bash script that will be hosted locally on a one Linux machine but would be executed remotely on the other hosts over SSH. (more…)

HowTo: Install Tor on Linux – Ubuntu/Debian/Mint etc.

This guide describes how to install Tor Client on the Debian based systems like Linux Mint, Ubuntu etc.

Tor or The Onion Router – is an encrypted network that can route your traffic through relays, making the traffic appear to come from exit nodes.

Unlike with proxies, the exit node itself doesn’t know your IP address or where you are.

To redirect connections through the Tor network we will use ProxyChains utility.

Set Up an Official Tor Repository

Edit /etc/apt/sources.list file.

$ sudo vi /etc/apt/sources.list

Append the following line:

deb http://deb.torproject.org/torproject.org <RELEASE NAME> main

e.g.

deb http://deb.torproject.org/torproject.org jessie main

Do you know the RELEASE NAME of your distribution?

If you don’t know the release name of your distribution, you can find it out by running the following command:

$ cat /etc/*[-_]{release,version}

e.g.

$ cat /etc/*[-_]{release,version}
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=17.1
DISTRIB_CODENAME=rebecca
DISTRIB_DESCRIPTION="Linux Mint 17.1 Rebecca"
NAME="Ubuntu"
VERSION="14.04.1 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.1 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
jessie/sid

Tor Installation

Add the GPG key used to sign the packages by running the following commands:

$ gpg --keyserver keys.gnupg.net --recv 886DDD89
$ gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89|sudo apt-key add -

Refresh your sources:

$ sudo apt-get update

Install the following package to keep the signing key up to date:

$ sudo apt-get install deb.torproject.org-keyring

Install the Tor and ProxyChains by running the following command:

$ sudo apt-get install tor proxychains

The following basic packages will be installed:

Package Description
tor Anonymizing overlay network for TCP
proxychains Redirect connections through proxy servers

The ProxyChains is already configured to use Tor by default.

You can verify this by looking up /etc/proxychains.conf.

The last lines should be like these:

[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks4 127.0.0.1 9050

Verify Tor

You can test the Tor by checking your public IP address from the command line.

$ wget -q -O - ip.appspot.com
83.***.***.***
$ proxychains wget -q -O - ip.appspot.com
ProxyChains-3.1 (http://proxychains.sf.net)
|DNS-request| ip.appspot.com 
|S-chain|-<>-127.0.0.1:9050-<><>-4.2.2.2:53-<><>-OK
|DNS-response| ip.appspot.com is 74.125.193.141
|S-chain|-<>-127.0.0.1:9050-<><>-74.125.193.141:80-<><>-OK
154.35.132.83