Archive for the ‘Linux / Redhat’ Category

Here is a docker cheatsheet and quick reference. Want to contribute? Leave a comment down below.

Install docker (one liner):

curl -sSL https://get.docker.com/ | sh

Install docker: (Alternative)

curl -sSL get.docker.com -o get-docker.sh
sh get-docker.sh

Make sure you add your current user to group docker and verify if it is added succesfully.

sudo usermod -aG docker anoop
id anoop

Search for docker images:

docker search ubuntu
docker search mysql

Download a docker image:

docker pull ubuntu

[This will pull the ubuntu image from the docker repo]

Download specific version of an image:

docker pull ubuntu:14.04

Note: By default containers will be having ephimeral storage. Which means if its shutdown, all the data in it would be lost.

Start a container and go inside the container:

anoop@h0n3yp0t ~ $ docker run -ti ubuntu:12.10 /bin/bash
root@668a52b2c701:/#

-t => attach a terminal to get console
-I => interactive
668a52b2c701 => unique ID

[Note: When you run a container you would get a container ID. You would need these to interact or mess with the container.]

To exit out of container without stopping it:
Press CTRL+P+Q

To view running containers:

anoop@h0n3yp0t ~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
668a52b2c701 ubuntu:12.10 “/bin/bash” 4 minutes ago Up 4 minutes keen_heyrovsky

-Docker generates random name to container if a custom name is not specific.

Here 668a52b2c701 -> Container ID

keen_heyrovsky – > Random container name generated for this docker container.

To attach to a container:

docker attach keen_heyrovsky OR docker attach 668a52b2c701

[Here we can give the container name or the container name]

To view all running and non-running containers:

anoop@h0n3yp0t~ $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
668a52b2c701 ubuntu:12.10 “/bin/bash” 7 minutes ago Exited (0) 16 seconds ago keen_heyrovsky

Start a stopped container:

docker start 668a52b2c701
668a52b2c701

View running process of a docker container:

docker top 668a52b2c701
or
docker top keen_heyrovsky

Stop a container:

docker stop 668a52b2c701

Get details about container location:

-Docker containers are stored in /var/lib/docker/containers

[Note: login as root to check the folders]

If Ubuntu 12.04 is not present locally and we need to download the image & start it:

docker run -ti ubuntu:12.04 /bin/bash

Start container in detached mode:

docker run -d -ti ubuntu:12.04 /bin/bash

Add custom name for docker container:

docker run -d -ti –name=anoop ubuntu:12.04 /bin/bash

[Do not give flags after /bin/sh. –name=anoop is given before /bin/bash]

Create docker container with persistent storage:

docker -ti -v /data –name=storage ubuntu:12.04 /bin/bash

-This will create /data inside the container.

-Once you are in the container, we can change to /data and create a file.

cd /data
touch test-file

-We can also see this file under folders under /var/lib/docker/volumes/ in local host pc. The folder would be displayed with an underscore “_data”

cd /var/lib/docker/volumes/
find . | grep test-file

-Add custom local directory for persistent storage to docker container:

In local PC, make a folder /docker-disks/

mkdir /docker-disks/ubuntu1

-Then map this location to folder when creating a docker container.

docker run -ti -v /docker-disks/ubuntu1:/data –name=d1 ubuntu:12.04 /bin/bash

Inside the container, run

cd /data
touch custom-file

-Exit out of the container and in your local PC, go to /docker-disks/ubuntu1/ and list the contents and we will see the file created in the container here:

cd /docker-disks/ubunt1/
ls
custom

Create docker image with an open port:

docker run -d -p 3306 -ti mysql /bin/bash

-Lets check if port 3306 is open in docker.

anoop@h0n3yp0t ~ $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26225f771013 mysql “docker-entrypoint.s…” 4 seconds ago Up 3 seconds 0.0.0.0:32769->3306/tcp practical_raman

In local PC, we can check the NAT tables:

iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DOCKER all — anywhere anywhere ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DOCKER all — anywhere !127.0.0.0/8 ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all — 172.17.0.0/16 anywhere
MASQUERADE tcp — 172.17.0.2 172.17.0.2 tcp dpt:mysql

Chain DOCKER (2 references)
target prot opt source destination
RETURN all — anywhere anywhere
DNAT tcp — anywhere anywhere tcp dpt:32769 to:172.17.0.2:3306

-Here the local port: 32769 will be forwarded to port: 3306 (mysql) with IP 172.17.0.2 (container IP for mysql IP)

-To port forward host PC port 32769 to docker mysql’s IP: 3306 we do the following:

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26225f771013 mysql “docker-entrypoint.s…” 2 hours ago Up 2 hours 0.0.0.0:32769->3306/tcp practical_raman

Host PC IP: 192.168.102.128
container IP:
nmap 192.168.102.128

Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-15 15:27 IST
Nmap scan report for 192.168.102.128
Host is up (0.000086s latency).
Not shown: 994 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
445/tcp open microsoft-ds
3128/tcp open squid-http

-From the nmap outputs, we can see that mysql is not open

-Here, we first stop the docker application.

docker stop practical_raman

-Then map a local port to mysql port on docker:

docker run -d -p 3306:3306 -ti mysql /bin/bash

Run docker by specifying dns:

docker run –dns 10.192.3.10 -it –name ubuntu-old -p 801:801 ubuntu:12.04 /bin/bash

(The above is useful if you running docker inside a VM where the host’s resolv.conf has 127.0.0.1 set the resolver).

Stop and remove all containers:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

I will be updating this post with more cheats in the future. Do subscribe to my blog to get latest updates. If you have any cheats or tricks, do leave a comment down below. I will update this post with the same and will give you the credits. 🙂

 

References: DuckAcademy

Advertisements

I have just installed CentOS 6.5 (minimal)  in Virtual Box on my Windows 8.1 pc. This is how I installed CentOS. Hope this helps.

[Update: The updated version of this article with screenshots for CentOS 6.7 can be found here.]

Requirements:

  1. CentOS 6.5 32-bit ISO : Download Link (~330 MB)
  2. Virtual Box : Download Link (~110 MB)
  3. Atleast 8 GB of free disk space.

Installation Procedure:

First, thing you need to  do is to set up your Virtual Box. Go ahead download and install Virtual Box (the download link is given above in the requirements).

Press “New“, Type Name as “CentOS 6.5 32 bit” or anything you want. Set the type as “Linux“, Version as “Red Hat 32 bit“. And press “Next”.

create vm

name and type of OS pic

Allocate RAM to 512 MB RAM or higher , then click “Next“.

select ram size pic

Then select the option “Create a virtual hard drive now “, then click on “Create“.

create hd pic

Select hard drive file type as the first option “VDI” , then click on “Next“.

hard disk type: vdi pic

Select type as “Dynamically allocated“. Choose the amount of hard disk space you want to allocate for your CentOS system. Select atleast 8Gb-10GB or higher and then click on “Create“.

VM HD size pic

Now, you would see the home screen of the Oracle Virtual box, Click on the CentOS VM you have created and then click “Start“.

start vm

Then click on the yellow folder icon and select the ISO file that you have downloaded.

Select ISO location

Then click on “Start“.

start boot

Wait for a few seconds and you will see the CentOS boot menu. Now, select the first option “Install or upgrade an existing system“.

Boot menu picture

 

[Note: To scroll through different options, you can either use the Arrow keys in your keyboard or the TAB key to move through different options . You may also use SPACE bar in your keyboard or ENTER key to make selections]

Now, you will probably get a message box saying “Disk Found” and if you want to verify the contents in the CD. Press “Skip”. If you need, you can press “OK” and verify the contents but it might take a while.

Using your arrow keys, select “Skip” and then hit “Enter“.

Disk check pic

loading screen

Hit “OK“.

CentOS Welcome

Now, select the language and then use the TAB key and then select “Ok” and hit ENTER.

select language

Now, select the model of the keyboardand then select “OK“.

keyboard selection pic

If you get a “Warning Message” such as the one below, just chooseRe-initialize all“.

Re-initialize all picture

Now, select your time zone and then hit “OK“. Then select a password for your “root” (or admin account), you can use TAB keys to reach the next box, and finally select “OK” and hit ENTER.

create root password

Now, select the option “Use entire drive“, and select “OK”.

allocate hard drive picture

Now, select “Write changes to disk” and the installer should start right up.

installation picture

installation progress pic

After, it is done installing , you will see a message saying “Congratulations, your CentOS installation is complete“. Select “Reboot” and hit ENTER.

installation complete -Reboot

Now, it should boot right up.

centos bootup picture

now, type login as: root , Then hit ENTER. Then type the password and hit ENTER. You should see now be able to see the terminal window with the # symbol.

root login pic

 

And voilà ! You have successfully installed CentOS 6.5 in Virtual Box.

This is a minimal mode CentOS and so many application packages are not installed. You will also have to configure the network to access the internet.

[UPDATE: To configure network in CentOS 6.5 (which is the same as configuring centos 6.3), I have made a detailed guide with screenshots, you can find it here.]

If you have any sort of queries on regarding this installation, just leave a comment and will get back at you. Don’t forget to follow my blog to get future updates! :D

Regards
ΞXΤЯ3МΞ

This is a guide on how to install Zorin OS 7 (64-bit) in Virtual Box. Hope this helps!

Requirements:

  1. Zorin OS Core ISO : Download Link (~1.5GB)
  2. Virtual Box : Download Link  (~96 MB)
  3. Atleast 8 GB of free hard disk space.

Installation Procedure:

First, download and install Virtual Box in your computer using the download link mentioned above. Also, download the Zorin OS ISO to any location of your choice.

Open Virtual Box, click on “New“:

1

Now, enter “Name” anything as you wish, Type asLinux” and Version asUbuntu (64-bit)“. Then, click on “Next“.

Name and Operating system

Now, select the amount of RAM you want to allocate for your Zorin OS Virtual machine. I would recommend a minimum of 512MB-1024MB. I have allocated 1024 MB (i.e. 1 GB of RAM) for my Zorin OS VM.

Memory Size

We need to create a virtual hard drive. Click on “Create a virtual hard drive now” and click on “Create“.

Create Hard Drive

Now, select the option ” VDI(Virtual disk Image) ” and click on “Next”.

Hard Disk Type

Now, select “Dynamically allocated“. {NOTE: You can also go with fixed size if you want but it will take longer time to create but is faster to use }

Storage Type

Now , you can select the size of your virtual hard disk by dragging the slider across. You can also choose a custom location where you want to save your Zorin OS by clicking on the red box that I have highlighted. Make sure you allocate a minimum of 8 GB. After selecting the appropriate options, click on “Create“.

7

Now, Click on the Virtual machine, you created and click on “Start“.

9

Now, click on the small folder icon which I have highlighted in red and browse to the ZorinOS ISO file you have downloaded earlier.

10

11

Now, click on “Start” once you have selected the ISO file.

12

To start the installation, select the option “Start the installer directly“.

13

Wait a few moments for the installer to load.

14

Select the Language of your choice and click on “Continue“.

15

Click on “Continue“.

16

Select “Erase disk and install Zorin“.

17

After this step, you would be prompted to select your location. You can click on the map to select your location and click on “Continue“. Then select the keyboard layout of your choice and click on “Continue“.

19

Now, you can enter “Your Name” , “Your computer’s name” , “username” and a “password” of your choice and click on “Continue“.

20a

Now, it will copy the nessasry files and install the Zorin OS.

21

This may take a while depending on your computer configuration.

23

You will get a prompt stating that the Installation is complete. Click on “Restart Now“.

24

Hit on the “ENTER” key when prompted.

25

Select the first option “Zorin” and hit “ENTER” in your keyboard.

26

This should boot up your installed Zorin OS.

27

Enter your login credentials that you created earlier during the installation phase.

28

You should be able to see your home screen and the Z button which is similar to the start button in Windows based systems in the lower left corner. Clicking that should bring up the menu which is very classy in my opinion and easy for newbies who are migrating from Windows to Linux.

30

You can open up the terminal by simply searching terminal in the search box and it should bring up the terminal.

31

And here is the terminal!

32a

So Hurrayy!! You have successfully installed Zorin OS in Virtual Box !!

I just installed ZorinOS a few days back, and felt that it is a great OS especially for users who are migrating from Windows to Linux. I am still playing around with it and so far I must say it looks interesting. So go ahead, try it out and let me  know what you think. Feel free to leave a comment about it in the comments section below.

If you have any sort of queries on regarding this installation, just leave a comment below and will get back to you. Don’t forget to follow my blog to get future updates! :D

 
ΞXΤЯ3МΞ

Kali Linux  is the all new Backtrack Linux which is used mainly for penetration testing and digital forensics purposes which is going to be released soon by Offensive Security. They haven’t announced the release date so far but said that the work is on the way to completion.

They have released a teaser video on their upcoming release. Be sure to check the teaser video below, it looks pretty daam impressive!

 
You can find the official post by Offensive Security team here.

ΞXΤЯ3МΞ

To change host name in Linux from command line, type:

vi /etc/sysconfig/network

Now, you will see a file such as the one shown below:

2

To change the hostname , you can change the highlighted to any thing you want. Press ‘i‘ or INSERT to edit the file. After making necessary changes, you can save the file by pressing ESC followed by :wq and hit ENTER.

Now, restart to make necessary changes. You can reboot by typing the following in the command line:

reboot

After reboot, login and check your hostname by typing the following in the terminal / command line :

hostname

 

Hope this helps!  🙂

ΞXΤЯ3МΞ

I have just installed CentOS 6.3 64-bit (minimal)  in Virtual Box. This is how I installed CentOS in Virtual Box. Hope this helps.

[Update: The updated version of this article with screenshots for CentOS 6.7 can be found here.]

Requirements:

  1. CentOS 64-bit ISO : Download Link (~330 MB)
  2. Virtual Box : Download Link (~90 MB)
  3. Atleast 8 GB -of free disk space

Installation Procedure:

First, thing you need to  do is to set up your Virtual Box. Go ahead download and install Virtual Box (the download link is given above in the requirements).

Press “New“, Type as “CentOS 64 bit” or anything you want. Set the type as “Linux“, Version as “Red Hat 64 bit“. And press “Next”.

Create VM

Allocate “Memory ” to 512 Mb or 1024 MB . You can increase this value according to requirements. And Press”Next“.

RAM

Then select “Create a virtual Hardisk Now” and press “Create“.

HD

Then choose “VDI” which is the first option, and press “Next“.

Hard Disk Type

Then choose “Dynamically allocated

Storage Type

Choose the amount of hard disk space you want to allocate for your CentOS system. Select atleast 8Gb-10GB . I have allocated 20 GB. And press “Create“.

Hard Disk Size

You would see the Virtual Box Home Screen. Now Press on “Start“.

start

Then press the small folder icon and choose the CentOS ISO file you have downloaded  earlier. And then press “Start“.

Select ISO

selected iso

Wait for a few seconds and you will see the CentOS boot menu. Now, select the first option “Install or upgrade an existing system“. And press “Enter” in your keyboard.

Boot menu

Now , it will take a few seconds to load.

loading

[Note: To scroll through different options, you can either use the Arrow keys in your keyboard or the TAB key to move through different options . You may also use SPACE bar in your keyboard or ENTER key to make selections]

Now, you will probably get a message box saying “Disk Found” and if you want to verify the contents in the CD. Press “Skip” as you are installing from an ISO file. If you need, you can press “OK” and verify the contents but it might take a while.

Verify Or Not

You would see a message “Welcome to CentOS” and then press “OK“.

Welcome Screen

Select the language and press “OK“.

Language selection

Select the model of the keyboard or just leave it to the default value. then press “OK“.

keyboard model

If you get a “Warning Message” such as the one below, just chooseRe-initialize all“.

Warning Message

Then select your time zone and (Press TAB) and then  “OK“.

time

Now, you will need to enter a password. This will be the password for the root user (or Administrator password). Then select “OK“. {Remember you can use the arrow keys or TAB to move through different fields or options in the screen}.

set root password

Now, select “Use entire drive” and then press “OK“.

Erase Disk

Now, press “Write changes to disk“.

write changes

Now, it will begin installing CentOS. It might take a while for it to complete.

dependencies check

installing screen

After, it is done installing , you will see a message saying “Congratulations, your CentOS installation is complete“. Select “Reboot” and hit ENTER.

Reboot

It will reboot now, and you will see the CentOS booting screen.

booting

CentOS booting

Now, you will see the login prompt as shown in the picture below. Now, Type the login as “root” and password as the password you entered during the setup.

login screen

After successful login  you will see a prompt as shown below with  # symbol at the end.

Succesful login and root prompt

And voilà ! You have successfully installed CentOS in your Virtual Box.

This is a minimal mode CentOS and so many application packages are not installed. You will also have to configure the network to access the internet.

[UPDATE: To configure network in CentOS, I have made a detailed guide with screenshots, you can find it here.]

If you have any sort of queries on regarding this installation, just leave a comment and will get back at you. Don’t forget to follow my blog to get future updates! :D

ΞXΤЯ3МΞ

Conky:

Conky is a free, light-weight system monitor for X, that displays any information on your desktop. Conky is licensed under the GPL and runs on Linux and BSD.

Step 1: Installing Conky in Xubuntu 12.04

Open up the “Terminal” and type the following commands:

$ sudo add-apt-repository ppa:conkyhardcore/ppa

$ sudo apt-get update

$ sudo apt-get install conky-all

Step 2: Create config file

Create a file named “.conkyrc” in your home folder. This will be your config file where you will insert your configuration details later. To do this, use the following command in the terminal :

$ sudo touch ~/.conkyrc

$ sudo chmod +x ~/.conkyrc

Now you can either search in Google for sample conkyrc config files and copy them to your ~/.conkyrc file or you can download the following sample :

Sample Conky Config : Download Link

Now, open the ~/.conkyrc file and paste the contents of the above sample conky to it and save the ~/.conky file.

You can use gedit to open the ~/.conkyrc file using the following command:

$ sudo gedit ~/.conkyrc

 
Step 3: Start Conky

To start conky, open your terminal and type :

$ sudo conky

You should now see the conky window on the your desktop screen.

Step 4 : Add conky to startup

Create a file named say “conkystartup.sh” in home folder and make it executable by using the commands:

$ sudo touch ~/conkystartup.sh

$ sudo chmod +x ~/conkystartup.sh

Now, open “conkystartup.sh” file using the following command:

$ sudo gedit ~/conkystart.sh

 
Now, paste the following code into the “conkystart.sh” file:

#!/bin/bash
sleep 30 && conky ;

Save the file and exit.

To add to startup, Go to Menu>Settings>Session & Startup

Press “Add” , set name as “Conky” and set “Location” as the location of “conkystart.sh“.

This will make conky to run at startup after a delay of 30 seconds (so that conky gets loaded after the desktop is loaded).

Screenshot of My Xubuntu + Conky :

If you have any sort of queries on regarding this installation, just leave a comment and will get back at you. Don’t forget to follow my blog to get future updates! 😀

ΞXΤЯ3МΞ