Isolating Your System with Linux Namespaces

With the advent of tools like Docker, Linux Containers, and others, it has become super easy to isolate Linux processes into their own little system environments. This makes it possible to run a whole range of applications on a single real Linux machine and ensure no two of them can interfere with each other, without having to resort to using virtual machines. These tools have been a huge boon to PaaS providers. But what exactly happens under the hood?

These tools rely on a number of features and components of the Linux kernel. Some of these features were introduced fairly recently, while others still require you to patch the kernel itself. But one of the key components, using Linux namespaces, has been a feature of Linux since version 2.6.24 was released in 2008.

Anyone familiar with chroot already has a basic idea of what Linux namespaces can do and how to use namespace generally. Just as chroot allows processes to see any arbitrary directory as the root of the system (independent of the rest of the processes), Linux namespaces allow other aspects of the operating system to be independently modified as well. This includes the process tree, networking interfaces, mount points, inter-process communication resources and more.

Why Use Namespaces for Process Isolation?

In a single-user computer, a single system environment may be fine. But on a server, where you want to run multiple services, it is essential to security and stability that the services are as isolated from each other as possible. Imagine a server running multiple services, one of which gets compromised by an intruder. In such a case, the intruder may be able to exploit that service and work his way to the other services, and may even be able compromise the entire server. Namespace isolation can provide a secure environment to eliminate this risk.

For example, using namespacing, it is possible to safely execute arbitrary or unknown programs on your server. Recently, there has been a growing number of programming contest and “hackathon” platforms, such as HackerRank, TopCoder, Codeforces, and many more. A lot of them utilize automated pipelines to run and validate programs that are submitted by the contestants. It is often impossible to know in advance the true nature of contestants’ programs, and some may even contain malicious elements. By running these programs namespaced in complete isolation from the rest of the system, the software can be tested and validated without putting the rest of the machine at risk. Similarly, online continuous integration services, such asDrone.io, automatically fetch your code repository and execute the test scripts on their own servers. Again, namespace isolation is what makes it possible to provide these services safely.

Namespacing tools like Docker also allow better control over processes’ use of system resources, making such tools extremely popular for use by PaaS providers. Services like Heroku and Google App Engine use such tools to isolate and run multiple web server applications on the same real hardware. These tools allow them to run each application (which may have been deployed by any of a number of different users) without worrying about one of them using too many system resources, or interfering and/or conflicting with other deployed services on the same machine. With such process isolation, it is even possible to have entirely different stacks of dependency softwares (and versions) for each isolated environment!

If you’ve used tools like Docker, you already know that these tools are capable of isolating processes in small “containers”. Running processes in Docker containers is like running them in virtual machines, only these containers are significantly lighter than virtual machines. A virtual machine typically emulates a hardware layer on top of your operating system, and then runs another operating system on top of that. This allows you to run processes inside a virtual machine, in complete isolation from your real operating system. But virtual machines are heavy! Docker containers, on the other hand, use some key features of your real operating system, including namespaces, and ensure a similar level of isolation, but without emulating the hardware and running yet another operating system on the ……continue reading…..

 

 

 

Thank you for reading my blog , the reference is taken from one of the article that was published by  Mahmud Ridwan on Toptal.
Please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

Advertisements

Linux Best Practices and Tips

This resource contains a collection of Linux best practices and Linux tips provided by our Toptal network members. As such, this page will be updated on a regular basis to include additional information and cover emerging Linux techniques. This is a community driven project, so you are encouraged to contribute as well, and we are counting on your feedback.

Linux is powerful, flexible, and can be adapted to a broad range of uses. While best practices for administrating Linux servers are not hard to find due the popularity of the operating system, there is always a need for up-to-date Linux advice, along with the best tips, from our experienced Toptal Linux administrators.

Check out the Toptal resource pages for additional information on Linux .……continue reading…..

 

Thank you for reading my blog , the reference is taken from one of the article that was published by

Rogelio & Zlatko  on Toptal. Please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

 

 

Installing Red Hat Linux 7.0

In this blog I am going to show how we can install Red Hat Linux 7.0 desktop version on Oracle Virtual Box.

Here is the basic setting I have used to install and taken the ISO version of Red Hat Linux 7.0 workstation.

 

image 

Memory setting as below:

image

Network as Bridge Adapter , follow as below:

image

 

Once all the setting is completed click on the PLAY button from the option as shown below , once your VM start to load the installer we will see the same button changes to “Show” :

 

image

 

Now go to the other window and follow the below instruction:

image

 

Click on Continue. After that we will see the below screen, set the installation destination to begin our installation.

 

image

 

 

image

I want to use the default setting as of now , so will click on “Done” option and proceed further.

 

image

Finally we will see the above screen , now let us click on “Begin Installation” button and proceed further.

image

At this stage we have to create a user for the system and need to set the root password. Will first set the root password and then create a user as shown below:

image

This must be strong but as I used a very simple one to proceed further.

 

image

 

As the root password is set now , let us create a user and proceed:

image

Click on Done , you can use the user as admin account or a normal user. But here I am using it as Admin user.

 

image

image

 

image

Now click on “Reboot” .

clip_image001

 

Click on License Information and accept it.

 

clip_image002

clip_image003

clip_image004

 

Finally click on “Finish Configuration”

 

clip_image001[6]

 

Keep default and proceed further.

clip_image002[7]

 

At this point of time I don’t need any subscription so selected the preference as “No” and clicked on Finished.

 

image

 

Now login to the system:

 

image

 

image

Click on Next keep English and proceed further if you want to change the language preference then you can select other option too.

 

image

 

We are almost done here , so click on highlighted option now “ Start suing Red Hat…. ”.

 

image

 

Now you are ready to use your Red Hat Linux 7.0 version .

 

Thank you for reading my blog . Please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

Conditional statements in Python

Reference taken from one of my article that was published on experts exchange. The purpose of this article is to demonstrate how we can use conditional statements using Python.

Conditional statements for testing using Python is similar to any other programming language in that we write if and else statements to get the desired results based on certain conditions before acting on any decision.
To show how to use conditional statements with example in Python I am using Mint operating system which has Python version 2.7.6 and also Python version 3.4.0 but the conditional statements are not operating system dependent , so we can use any OS. This conditional statements works on earlier Python versions too.

Using username "sloba".
sloba@***.***.*.*'s password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-38-generic x86_64)

Welcome to Linux Mint
 * Documentation:  http://www.linuxmint.com
Last login: Sun Oct 11 18:25:32 2015 from ***.***.*.*
sloba@sloba-VirtualBox ~ $ 
loba@sloba-VirtualBox ~ $ python2.7
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
sloba@sloba-VirtualBox ~ $ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Normally we use some basic operators to check the conditional statements in Python such as “<”,”<=”,”>”,”>=”,”=”, “! =”,<> . Let’s check how we can use these operators starting with a very simple example. We are going to set some variables to check the min and max conditions.

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a =2
>>> b =5
>>>

We can assign the variables as above or we can also assign them just using a comma separator just like below:

sloba@sloba-VirtualBox ~/Desktop/myscripts $ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a =2
>>> b =5
>>>
>>> a,b = 2,5
>>>
>>> print a
2
>>> print b
5
>>>

Now you can see that the values assigned to the variables are as what we assigned earlier.  So let us check if min is less than print the value assigned to min.

>>>
>>> if a < b:
...     print a, " is cannot be more than ",b
...
2  is cannot be more than  5
>>>

In Python we don’t have to end the if statements by ending with another if like we do in other programming languages, so I have only written the below lines and after three dots used TAB for my right indentation. Hit enter to check conditional statements with less than operators:

>>> if a < b:
...     print a, " is cannot be more than ",b
...

Let us try with a false statements using the same variables and values from the above test. We know the variable “a” is less than variable “b” and cannot be greater, so now we will just change the “<” and place “>” and some text changed:

>>> if a>b:
...     print a," is greater than ",b
...
>>>

From the above condition we see that the false statement is false where we only message would have printed for the TRUE statements. To check the else statement we can use the same variables.

 >>> if a>b:
...     print a," is greater than ",b
... else:
...     print a," is not greater than ",b
...
2  is not greater than  5
>>>

The above example is shown how to use if and else statements using operators.
To make the conditional statements I am going to use one mathematical game just to make use of conditional statements. To calculate simple interest we need to know the principal which is the starting amount that we are going to use, the interest rate for the amount, and the time. The formula to calculate is i = prt .

  • I means interest earned
  • P means principal amount
  • R is the rate of interest
  • T is time

Now let us build a simple script to do use this. Say Sloba has 40,000 in rupees in his savings account where he has earned interest of 4% annually which is not compounded.  So the question would be how much he will save in one year. The answer is:

The interest earned by Sloba is 1,600 in rupees and the total amount including the principal is 41,600.00.

Let’s make this in a script named “simple_interest.py”.

#!/usr/bin/python

#Author: Swadhin
# Date: 11 - Oct - 2015
# Purpose: Simple interest game in Python

print "--------------Simple interest game--------------"
print "------------------------------------------------"
#Below are the variables used to calculate the formula
principle = 40000
# rate 4 % taken as per the question
rate = 4
# time in year
time = 1
name = raw_input("What is your name:")
print "Welcome ", name
print "Here is the question: "
print "Say Sloba has 40,000 in rupees in his savings account where he has earned interest of 4% annually which is not compounded."
answer = input("So the question would be how much he will save in 1 years. ")
si = (principle * rate * time) / 100
if answer == si:
    print name, "you have given the correct answer, the total saving Sloba would save in rupees is 40000 plus 1600 i.e.41,600 in one year "
else :
    print name, "your answer is not correct"

 

Now if we execute this as like below:

sloba@sloba-VirtualBox ~/Desktop/myscripts $ ls
simple_interest.py
sloba@sloba-VirtualBox ~/Desktop/myscripts $ python simple_interest.py
--------------Simple interest game--------------
------------------------------------------------
What is your name: Ray
Welcome   Ray
Here is the question:
Say Sloba has 40,000 in rupees in his savings account where he has earned interest of 4% annually which is not compounded.
So the question would be how much he will save in 1 years. 1400
 Ray your answer is not correct
sloba@sloba-VirtualBox ~/Desktop/myscripts $

 

Thank you for reading my blog , the reference is taken from one of my article that was published by Experts-Exchange. Please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

Sending Email from Linux

 

Here is the simple way to write an email script which can be utilized to send emails to recipients.

Login to your Linux box , I am using a virtual machine with Linux Mint operating system installed running on Oracle Virtual Box.

login as: sloba
sloba@**********'s password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-38-generic i686)

Welcome to Linux Mint
 * Documentation:  http://www.linuxmint.com
Last login: Fri Jul 24 12:52:24 2015 from msi-l1028.metricstream.com
sloba@sloba-VirtualBox ~ $ 

Below is a very basic and simple script which can be used to send email :

 

##################################################################
# Email notification
##################################################################
SUBJECT="TEST EMAIL FROM UNIX"
# use form to send from whom the email address has sent
FROM="automail@slobaexpert.wordpress.com"
DESCRIPTION="THIS IS AN AUTO-GENERATED MESSAGE"
#Put the email address of the person to whom you want to send with comma seperator
EMAIL="<<to email address>> @<<hostname >>.com"
EMAILMESSAGE=/tmp/emailmessage

 echo "From: $FROM" > $EMAILMESSAGE
 echo "To: $EMAIL" >> $EMAILMESSAGE
 echo "Subject: $SUBJECT " >> $EMAILMESSAGE
 echo "************************************************************************" >> $EMAILMESSAGE
 echo "$DESCRIPTION : DO NOT REPLY TO THIS EMAIL MESSAGE. " >> $EMAILMESSAGE
 echo "************************************************************************" >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo "Test file email " >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo "Thanks, " >> $EMAILMESSAGE
 echo "$FROM" >> $EMAILMESSAGE
 cat $EMAILMESSAGE | /usr/sbin/sendmail -t

 

You can change the TO address from the above script and test it. But we need to make sure “sendmail ” is already installed on your server to use this , if not then you can install using the below command.

sudo apt-get install sendmail

Enable SSH server in Linux Mint

Normally we do connect to any server from WinScp or Putty tool from Windows platform to connect any Linux environment to do various activities. 

Here I am going to show how we can enable SSH on Linux Mint operating system. I am using a virtual machine was built on Oracle Virtual Box. 

image

The above image show my virtual machine running on Oracle VM virtual box. Now let me open my putty and try connect to my virtual machine. To know the hostname of the VM you can open the terminal and type “hostname” as shown like below:]

image

Open Putty :

image

Click on Open.

image

After this I get the above error. Now let try to enable SSH on our Linux machine we need to first install “OpenSSH” .  

There are two options that we can do to install “OpenSSH” :

Option 1:

  • Open the main menu, select the Software Manager
  • Search for “Openssh ” on the search box
  • Click on the package openssh-server, then select install.
  • Once the installation is completed then start SSH by executing “/etc/init.d/ ssh start”  command.

image

image

image

image

Click on “install”

Option 2: 

As Linux Mint Operating system is based on Ubuntu , so we can install “openssh” from terminal or console.

 

image

image

image

image

Check if port 22 is enabled or not under “sshd_config” file , we can also modify the port in this file to access SSH on another port but I am using the default setup i.e. port 22.

image

Now let’s try connecting through putty from my local system to the VM .

image

 

image

 

image

Now we can see that I am able to connect to my Linux machine using Putty after enabling SSH on VM server.

Upgrade Python 2.7.6 to Python-2.7.10 on Linux Mint OS

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once you download and install Linux Mint 17.2, Python software is installed by default. But the latest releases from Python are Python 2.7.10 and Python 3.4.3. I am using a 32 bit operating system as my host is 32 bit but you can still go ahead with 64 bit version which is preferred.Log into the Mint operating system, and open terminal. Type “python” and hit enter or you can type “python –version” to check the existing version.
swadhin.ray-000036.png

To download the latest version of Python, open https://www.python.org/downloads/ and click on “Download Python-2.7.10” as shown in below image.
swadhin.ray-000037.png

Open the folder where the file is downloaded. In my system it’s defaulted to “Downloads” folder.
swadhin.ray-000038.png
swadhin.ray-000039.png

If you open the tar file from the archive manager you can see the files that were downloaded.
swadhin.ray-000040.pngNow extract all the files under the same folder or you can choose a specific directory. Click on Extract button as shown below.
swadhin.ray-000041.pngswadhin.ray-000042.pngWait till the file get extracted.
swadhin.ray-000043.pngNow from the above image we can we can see that file is successfully extracted.
swadhin.ray-000044.pngNow open terminal and locate the extracted installation files.

sloba@sloba-VirtualBox ~ $ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
sloba@sloba-VirtualBox ~ $ cd Downloads/
sloba@sloba-VirtualBox ~/Downloads $ ls
Python-2.7.10  Python-2.7.10.tar.xz
sloba@sloba-VirtualBox ~/Downloads $ cd Python-2.7.10/
sloba@sloba-VirtualBox ~/Downloads/Python-2.7.10 $ ls
aclocal.m4     Demo            Mac              PC              README
build          Doc             Makefile         PCbuild         RISCOS
config.guess   Grammar         Makefile.pre     pybuilddir.txt  setup.py
config.log     Include         Makefile.pre.in  pyconfig.h      Tools
config.status  install-sh      Misc             pyconfig.h.in
config.sub     Lib             Modules          python
configure      libpython2.7.a  Objects          Python
configure.ac   LICENSE         Parser           python-gdb.py
sloba@sloba-VirtualBox ~/Downloads/Python-2.7.10 $ 

Select all Open in new window

Now execute “./configure” on the same path to configure. Wait until it is completed. The execution should be completed without any errors.

swadhin.ray-000046.pngswadhin.ray-000047.pngswadhin.ray-000048.pngOnce the script is executed then type “make install” to proceed further.

swadhin.ray-000049.pngIf you get any errors then use the root user to execute as like above.

swadhin.ray-000050.pngThis will take some time to complete. Wait till this get completed.
swadhin.ray-000051.pngNow the installation is completed. Now let’s check the Python verison to see if the latest version is installed or not by typing “python” or “python –version” as shown in below image.
swadhin.ray-000053.pngPython-2.7.10 is successfully installed on Linux Mint OS and ready to use.
swadhin.ray-000054.png