Redirect or block traffic based on country geographical location using Apache mod_geoip

In this config you will learn how to block or redirect web traffic based on the visitor’s country geographical location using Apache’s geoip mod.

Apache mod_geoip installation

Assuming that you already have Apache webserver installed and running we start by the installation of mod_geoip:

UBUNTU/DEBIAN
# apt-get install libapache2-mod-geoip
CENTOS/REDHAT/FEDORA ( epel enabled only )
# yum install mod_geoip.x86_64

Read more

An easy way to encrypt and decrypt large files using OpenSSL and Linux

Below is a quick config on how to to encrypt and decrypt large files using OpenSSL and Linux such as Redhat, Ubuntu, Debian, CentOS, Fedora etc. First, what you will need is a some sort of arbitrary file. Let’s create 1GB file now:

$ fallocate -l 1G large_file.img
$ ls -lh large_file.img
-rw-r--r--. 1 lrendek lrendek 1.0G Jan  2 16:40 large_file.img

Read more

How to transfer data over the network with nc (netcat) command on Linux

The nc ( netcat ) command can be used to transfer arbitrary data over the network. It represents a quick way for Linux administrators to transfer data without the need for an additional data transfer services such as FTP, HTTP, SCP etc. This config will show you an example on how to transfer data between to network hosts. We will be transferring data myfile.txt file from a localhost to a destination host with an IP address 10.1.1.2.

Destination host

The nc command first needs to be started on the network host to which we need to transfer data. We will instruct nc to listen for an incoming request on user defined port number and once the client request comes receive the desired data. Pick the port number of your choice to ensure that it is not blocked by firewall and it is accessible from the source host.

$ nc -l -p 7555 > myfile.txt

Read more

How to obtain a laptop battery information and charging state on Linux

The following linux commands will help you to obtain the information about your laptop battery such as manufacturer, part type, capacity, voltage etc. First, tool which can be used for this job is dmidecode command. If you currently do not have dmidecode available on your Linux system you can install it by:

UBUNTU/DEBIAN
# apt-get install dmidecode
CENTOS/FEDORA
# yum install dmidecode

next, using dmidecode we can obtain some hardware information about our battery:

# dmidecode -t 22
# dmidecode 2.12
SMBIOS 2.6 present.

Handle 0x002E, DMI type 22, 26 bytes
Portable Battery
        Location: Rear
        Manufacturer: LGC
        Name: 42T4942
        Design Capacity: 93240 mWh
        Design Voltage: 11100 mV
        SBDS Version: 03.01
        Maximum Error: Unknown
        SBDS Serial Number: 073C
        SBDS Manufacture Date: 2012-03-23
        SBDS Chemistry: LION
        OEM-specific Information: 0x00000000

Read more

How to convert documents between LibreOffice and Microsoft Office file formats on Linux

In this config you can learn how to convert documents format between LibreOffice and Microsoft Office file formats on Linux. The preferred tool to use for a file format conversion between LibreOffice and Microsoft Office is unoconv. Let’s start with the installation of unoconv package:

FEDORA/REDHAT/CENTOS
# yum install unoconv
DEBIAN/UBUNTU
# apt-get install unoconv

and create some LibreOffice document document.odt and spreadsheet spreadsheet.ods to play with:

$ file document.odt 
document.odt: OpenDocument Text
$ file spreadsheet.ods 
spreadsheet.ods: OpenDocument Spreadsheet

Read more

Remove all containners based on docker image name

Questions:
How can I remove all docker containers based on a docker image name. I do not wish to remove all available containers, only the those which are based on particular image. For example I would like to remove all containers based on image centos:7.

Answer:
To remove all docker containers based on centos:7 run the following linux command:

# docker ps -a | awk '{ print $1,$2 }' | grep centos:7 | awk '{print $1 }' | xargs -I {} docker rm {}

Read more

convert ebook to amazon kindle mobi using calibre - linux

How to convert various eBook formats for Amazon Kindle on Linux

Amazon currently accepts limited number of ebook formats that you can directly send to your Amazon Kindle. In this config we are going to show few Linux tools which may assist you with the conversion between various Document and eBook formats.

Based on your amazon Kindle type the supported formats may include:

  • Microsoft Word (.doc, .docx)
  • Rich Text Format (.rtf)
  • HTML (.htm, .html)
  • Text (.txt) documents
  • Archived documents (zip , x-zip) and compressed archived documents
  • Mobi book
  • Portable Document Format PDF
  • JPEGs (.jpg)
  • GIFs (.gif)
  • Bitmaps (.bmp)
  • PNG images (.png)

ebook-convert

The first tool you might consider is ebook-convert. This tool is available on Fedora , CentOS, Redhat Linux under the package named ebook-tools. To install ebook-tools package run the command below:

# yum install ebook-tools

Read more

How to use a command line random password generator PWGEN on Linux

This article will provide you with some hints on how to generate random password using shell. Among many other tools which can be used on the Linux command line to generate random passwords such as openssl, mktemp, od or /dev/urandom the specific and easiest tool designed for this purpose is pwgen.

Installation

DEBIAN/UBUNTU
# apt-get install -y pwgen
FEDORA
# dnf install -y pwgen
CENTOS
# yum install -y pwgen

Usage examples

Let’s start by generating bunch of passwords by simple executing pwgen command. If no options are used pwgen will simply spit out 160 passwords with 8 characters each:

# pwgen 
AeD7Amiv Reech6ie dei7aiPe yoogh1Ch Quoh0zae shu2Eepa aoquu3Xa aiR4Raiv
eeWah9Ro uPhe9pif uZiegh2h xie6Mail wa2xaHai saeLoh4O Yai8be7u aGhue7fe
unieB3du yaiK7She ooh0ohGe Go5zuKai Aeseeph1 UJ3Moo5i xaeg6ohG aJ8oogah
suFo3ohr jaTee0mi eeK9zuoh tho5xieP Ec6uob9j iyap1eNo at1Hahqu viebei2O
zeeg9cuX iP9pooW6 ohS1nahl zaese9Vu dee1Tooh aS2Bahyu aeH5shoh hichooW6
Aishie2v phee8Ahp ce2Peith Ez0thoos oot0Aibo aizepe8J reeC6she aihaeSh6
EVaaroh1 apuviCh2 Ui2aec5t Yoh8jong eo2zaeWo queiTo7i aebai4Oe jahj5ieN
Co5aije5 ooSh1oon taeJe5ae Kah3quie eeXae6Ma wu6ohp8U Eil4sha4 iiSohc4a
eeNg0ied HaeH3ohl Shie9aih ohC5phoi boos6euG uadai3Oo Cohpai9I thuogh8E
thie7Zai aem6sooN ieFu7uif tiewoh4U Kaes1bai Aox4zah0 OoH5utoh uo4aWied
eew7baeV Iej7piel ohMa4iet Oi2aephi Yailov9t oaTheiz2 lexea9Ie iez0The2
et3Phaey hee2Oa7u Pee1Ibee ohbae1iZ thoo9eiZ eiCh3aiw Veiqu1ph quohF2oh
xoh2Iwo3 aiQuai8i aeKae5Hi owaiz3Ve oJa2ret8 yie4baiK iex3Chug ruPie2ig
Ahv7ciev kiemok7U veiX5cae thuL0Pho AiyeuB5t ooX4igeb bi0sohBu Ohl0hoaf
Wooy1ja9 ue8ooj3B iik5yeP5 Ieboo1oi neeNiu7E aeV8aimu oojeiW6x Thoh6Eix
zoaPh1au aiCh3eem quevoo8T Iey0soRo ceiC3Do4 Dae9ua4f pieyie2U noXu5ooK
Zuexe5du oNeu8eef heu7iTah kahpa8Um thoSa7sh Lai4Keik oit7Dahc aiy5iaZo
siv2Ut3a Tha8eePh eb6ieM2c DeVie1ee Cocofo7E Rihee6ya thi1Iigi iBi6quar
Adeeh6Us Eicho5so siTho2Pu Dahcho5I kowe7Iev gee9IeNu Ohso2jae Aegha1oo
Oomil4Ee Ahghoot3 Izai3oov yegeey6C ea8uG1ai Ahsh4Aeb quie5aeR paWaiqu4

Read more