Introduction to Linux - A Hands on Guide | Linux Bible | Linux From Scratch | A Newbie's Getting Started Guide to Linux | Linux Command Line Cheat Sheet | More Linux eBooks



Monday, 31 August 2015

How To: Install/Upgrade to Linux Kernel 4.2.0 in Ubuntu/Linux Mint Systems

The Linux Kernel 4.2.0 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.2.0 in your Ubuntu or Linux Mint system.



Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-unstable/linux-headers-4.2.0-040200_4.2.0-040200.201508301530_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-unstable/linux-headers-4.2.0-040200-generic_4.2.0-040200.201508301530_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-unstable/linux-image-4.2.0-040200-generic_4.2.0-040200.201508301530_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.2.0*.deb linux-image-4.2.0*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-unstable/linux-headers-4.2.0-040200_4.2.0-040200.201508301530_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-unstable/linux-headers-4.2.0-040200-generic_4.2.0-040200.201508301530_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-unstable/linux-image-4.2.0-040200-generic_4.2.0-040200.201508301530_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.2.0*.deb linux-image-4.2.0*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.2.0*' 'linux-image-4.2.0*'

Monday, 17 August 2015

How To : Install/Upgrade to Linux Kernel 4.2-RC7 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.2-RC7 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.2-RC7 in your Ubuntu or Linux Mint system.


Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc7-unstable/linux-headers-4.2.0-040200rc7_4.2.0-040200rc7.201508162030_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc7-unstable/linux-headers-4.2.0-040200rc7-generic_4.2.0-040200rc7.201508162030_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc7-unstable/linux-image-4.2.0-040200rc7-generic_4.2.0-040200rc7.201508162030_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc7-unstable/linux-headers-4.2.0-040200rc7_4.2.0-040200rc7.201508162030_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc7-unstable/linux-headers-4.2.0-040200rc7-generic_4.2.0-040200rc7.201508162030_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc7-unstable/linux-image-4.2.0-040200rc7-generic_4.2.0-040200rc7.201508162030_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.2*' 'linux-image-4.2*'

How To: Install/Upgrade to Linux Kernel 4.1.6 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.1.6 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.1.6 in your Ubuntu or Linux Mint system.


Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.6-unstable/linux-headers-4.1.6-040106_4.1.6-040106.201508170230_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.6-unstable/linux-headers-4.1.6-040106-generic_4.1.6-040106.201508170230_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.6-unstable/linux-image-4.1.6-040106-generic_4.1.6-040106.201508170230_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.1.6*.deb linux-image-4.1.6*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.6-unstable/linux-headers-4.1.6-040106_4.1.6-040106.201508170230_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.6-unstable/linux-headers-4.1.6-040106-generic_4.1.6-040106.201508170230_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.6-unstable/linux-image-4.1.6-040106-generic_4.1.6-040106.201508170230_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.1.6*.deb linux-image-4.1.6*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.1.6*' 'linux-image-4.1.6*'

Thursday, 13 August 2015

How To: Install/Upgrade to Linux Kernel 4.1.5 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.1.5 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.1.5 in your Ubuntu or Linux Mint system.


Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-headers-4.1.5-040105_4.1.5-040105.201508101730_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-headers-4.1.5-040105-generic_4.1.5-040105.201508101730_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-image-4.1.5-040105-generic_4.1.5-040105.201508101730_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.1.5*.deb linux-image-4.1.5*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-headers-4.1.5-040105_4.1.5-040105.201508101730_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-headers-4.1.5-040105-generic_4.1.5-040105.201508101730_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-image-4.1.5-040105-generic_4.1.5-040105.201508101730_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.1.5*.deb linux-image-4.1.5*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.1.5*' 'linux-image-4.1.5*'

Monday, 10 August 2015

How To : Install/Upgrade to Linux Kernel 4.2-RC6 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.2-RC6 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.2-RC6 in your Ubuntu or Linux Mint system.



Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc6-unstable/linux-headers-4.2.0-040200rc6_4.2.0-040200rc6.201508092028_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc6-unstable/linux-headers-4.2.0-040200rc6-generic_4.2.0-040200rc6.201508092028_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc6-unstable/linux-image-4.2.0-040200rc6-generic_4.2.0-040200rc6.201508092028_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc6-unstable/linux-headers-4.2.0-040200rc6_4.2.0-040200rc6.201508092028_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc6-unstable/linux-headers-4.2.0-040200rc6-generic_4.2.0-040200rc6.201508092028_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc6-unstable/linux-image-4.2.0-040200rc6-generic_4.2.0-040200rc6.201508092028_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.2*' 'linux-image-4.2*'

Tuesday, 4 August 2015

How To: Install/Upgrade to Linux Kernel 4.1.4 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.1.4 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.1.4 in your Ubuntu or Linux Mint system.


Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.4-unstable/linux-headers-4.1.4-040104_4.1.4-040104.201508031330_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.4-unstable/linux-headers-4.1.4-040104-generic_4.1.4-040104.201508031330_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.4-unstable/linux-image-4.1.4-040104-generic_4.1.4-040104.201508031330_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.1.4*.deb linux-image-4.1.4*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.4-unstable/linux-headers-4.1.4-040104_4.1.4-040104.201508031330_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.4-unstable/linux-headers-4.1.4-040104-generic_4.1.4-040104.201508031330_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.4-unstable/linux-image-4.1.4-040104-generic_4.1.4-040104.201508031330_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.1.4*.deb linux-image-4.1.4*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.1.4*' 'linux-image-4.1.4*'

How To : Install/Upgrade to Linux Kernel 4.2-RC5 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.2-RC5 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.2-RC5 in your Ubuntu or Linux Mint system.



Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc5-unstable/linux-headers-4.2.0-040200rc5_4.2.0-040200rc5.201508030228_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc5-unstable/linux-headers-4.2.0-040200rc5-generic_4.2.0-040200rc5.201508030228_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc5-unstable/linux-image-4.2.0-040200rc5-generic_4.2.0-040200rc5.201508030228_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc5-unstable/linux-headers-4.2.0-040200rc5_4.2.0-040200rc5.201508030228_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc5-unstable/linux-headers-4.2.0-040200rc5-generic_4.2.0-040200rc5.201508030228_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc5-unstable/linux-image-4.2.0-040200rc5-generic_4.2.0-040200rc5.201508030228_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.2*' 'linux-image-4.2*'

Sunday, 2 August 2015

How To : Install/Upgrade to Linux Kernel 4.2-RC4 in Ubuntu/Linux Mint Systems

    The Linux Kernel 4.2-RC4 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. This article will guide you to install or upgrade to Linux Kernel 4.2-RC4 in your Ubuntu or Linux Mint system.



Installation

For 32-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc4-unstable/linux-headers-4.2.0-040200rc4_4.2.0-040200rc4.201507271733_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc4-unstable/linux-headers-4.2.0-040200rc4-generic_4.2.0-040200rc4.201507271733_i386.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc4-unstable/linux-image-4.2.0-040200rc4-generic_4.2.0-040200rc4.201507271733_i386.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

For 64-Bit Systems

Download the .deb packages.

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc4-unstable/linux-headers-4.2.0-040200rc4_4.2.0-040200rc4.201507271733_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc4-unstable/linux-headers-4.2.0-040200rc4-generic_4.2.0-040200rc4.201507271733_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.2-rc4-unstable/linux-image-4.2.0-040200rc4-generic_4.2.0-040200rc4.201507271733_amd64.deb
Install them.

$ sudo dpkg -i linux-headers-4.2*.deb linux-image-4.2*.deb
Reboot the system.

sudo reboot

To uninstall,

sudo apt-get remove 'linux-headers-4.2*' 'linux-image-4.2*'

How To: Check if Username and Password are Valid using Bash Script

It's time to create a bash script that will take inputs - Username and Password, from the user and validate if the username-password combination is correct. There will be two essential steps involved in this script- check if username is valid and in case username is valid, check if password associated with that username is valid.



Let's start scripting!

1. Check if username is valid

This, surely, is the easier part of the script. Validating a user is very straight-forward, as you can use id command with option -u or read /etc/passwd (using 'grep' command) file to do so (Read about /etc/passwd file format here). If the exit status is "0", then it's a valid user, else it's not. For those who are new to bash scripting- Exit status can be checked using echo $?.

Let's check the validity of the user 'mandar'

MyLinuxBox root ~ > grep mandar /etc/passwd
mandar:x:500:500:Mandar Shinde:/home/mandar:/bin/bash

MyLinuxBox root ~ > id -u mandar
500
MyLinuxBox root ~ > echo $?
0

MyLinuxBox root ~ > grep -w mandar /etc/passwd
mandar:x:500:500:Mandar Shinde:/home/mandar:/bin/bash
MyLinuxBox root ~ > echo $?
0
In the first command, we made sure whether user 'mandar' exists and the same is assured by checking the exit status of the id -u mandar and grep -w "mandar" /etc/passwd command.

Lets check if there is any user 'shinde' (there isn't any).

MyLinuxBox root ~ > id -u shinde
id: shinde: No such user
MyLinuxBox root ~ > echo $?
1

MyLinuxBox root ~ > grep -w shinde /etc/passwd
MyLinuxBox root ~ > echo $?
1
And, exit status of those commands say the same.

2. Check if Password is valid

Now, let's suppose that, the username is valid and next step will be verifying the password. If you had read our article on /etc/shadow file format, you would have understood what I will be explaining here.

This file stores the passwords in encrypted format, for every user, on a separate line. Besides the hashed passwords, it stores other details also, from which we need to extract the password for comparison. /etc/shadow stores these details delimited with a colon (:) as below:

mandar:$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.:16431:0:99999:7:::
mysql:!!:16550::::::
nagios:$6$P9zn0KwR$tgfvvFWJJ5FKmoXiP5rXWOjwoEBOEoAuBi3EphRbJqqjWYvhEM2wa67L9XgQ7W591FxUNklkDIQsk4kijuhE50:16632:0:99999:7:::
So, in order to extract the password from the line, we'll have to use cut command, combining with 'grep' command as below:

MyLinuxBox root ~ > grep -w mandar /etc/shadow | cut -d: -f2
$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.
This is the original hashed password stored in /etc/shadow file. Read /etc/shadow file format for more details on how encrypted passwords are stored in this file.

The Encrypted Password

The field #2 in each line entry is the encrypted password. But, how this password is generated, we'll learn in this portion of the article. Let's just rewrite the encrypted password here-

$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.

Let's break this encrypted password in some parts, across the dollar ($) sign, to understand it better.

$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.
|1|-------2--------|-----------------------------------------3--------------------------------------------|
1. Hash Algorithm: This field denotes the hashing algorithm used to create the hashed password. The digit 6 describes that, SHA-512 algorithm is used, in this case. Some more of them are enlisted below:

--------------------
| 1  | MD5         |
--------------------
| 2  | Blowfish    |
--------------------
| 2a | eksBlowfish |
--------------------
| 5  | SHA-256     |
--------------------
| 6  | SHA-512     |
--------------------
2. Salt Value: Salt values are used to make the hash value stronger. These are the random type of data that is used to combine with the original password and then the hashed version of that is used as the encrypted password.
3. Password: This field stores the hashed version of the combination of original password and salt value.

Considering that user has provided the password, say mandar, we will try to create hashed value using the password entered by the user, the salt value (6) and the hashing algorithm (SHA-512) as below:

Syntax of the command is as follows:

perl -e 'print crypt("<PASSWORD>","\$<HASH-ALGO>\$<SALT-VALUE>\$") . "\n"'
In our case,
<HASH-ALGO> = 6
<PASSWORD> = mandar
<SALT-VALUE> = 5H0QpwprRiJQR19Y
Lets run the command now.

MyLinuxBox root ~ > perl -e 'print crypt("mandar","\$6\$5H0QpwprRiJQR19Y\$") . "\n"'
$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.
This is the password that we've generated. If it matches with the password stored in /etc/shadow file, then we can confirm that the password entered by the user is correct.

Bash Script:

#!/bin/bash

read -p "Enter the Username: " USERNAME

id -u $USERNAME > /dev/null
if [ $? -ne 0 ]
then
        echo "User $USERNAME is not valid"
        exit 1
else
        echo "Enter the Password:"
        read -s PASSWD
        export PASSWD
        ORIGPASS=`grep -w "$USERNAME" /etc/shadow | cut -d: -f2`
        export ALGO=`echo $ORIGPASS | cut -d'$' -f2`
        export SALT=`echo $ORIGPASS | cut -d'$' -f3`
        GENPASS=$(perl -le 'print crypt("$ENV{PASSWD}","\$$ENV{ALGO}\$$ENV{SALT}\$")')
        if [ "$GENPASS" == "$ORIGPASS" ]
        then
                echo "Valid Username-Password Combination"
                exit 0
        else
                echo "Invalid Username-Password Combination"
                exit 1
        fi
fi
Successful Check:

MyLinuxBox root ~ > ./usrpasschk.sh
Enter the Username: mandar
Enter the Password:
Valid Username-Password Combination
Unsuccessful Check-1:

MyLinuxBox root ~ > ./usrpasschk.sh
Enter the Username: mandar
Enter the Password:
Invalid Username-Password Combination
Unsuccessful Check-2:

MyLinuxBox root ~ > ./usrpasschk.sh
Enter the Username: shinde
id: shinde: No such user
User shinde is not valid
For any suggestions, please write in the comments section below.

Saturday, 1 August 2015

/etc/shadow file format in Linux Explained

In one of the recent articles we've published, we've learned the file format of /etc/passwd file, which stores one line entry for each user that can access the system. As one of the fields in each line of the /etc/passwd denotes whether the password for that user is stored in /etc/shadow file or not, it can easily be depicted that the actual passwords (of course, in the encrypted form) are stored in the /etc/shadow file. This article will help you learn more about /etc/shadow file format in more detail.


/etc/shadow File Permission

To begin with, let us observe and compare the file permissions on both /etc/passwd and /etc/shadow files:

MyLinuxBox root ~ > ll /etc/passwd
-rw-r--r--. 1 root root 1725 Jul 31 23:02 /etc/passwd

MyLinuxBox root ~ > ll /etc/shadow
-rw-------. 1 root root 1187 Jul 16 09:10 /etc/shadow
Things are pretty clear- /etc/passwd is world readable and /etc/shadow can only be read by the root user. This is because, had the password were stored in /etc/passwd file, even in encrypted format, anyone could see, decrypt and use them pretty easily. Thus, passwords are actually stored in /etc/shadow file which can only be accessed by root or superuser and not made open to the entire world, as there is a huge risk factor involved in it.

/etc/shadow File Contents

/etc/shadow file is the text file that holds the information about User password, the hash algorithm used to create hash, the salt value used to create hash and some details related to password expiry. Each line in this file is used to store the information about one user, delimited with a colon (:), and the file looks like:

root:$6$Ke02nYgo.9v0SF4p$hjztYvo/M4buqO4oBX8KZTftjCn6fE4cV5o/I95QPekeQpITwFTRbDUBYBLIUx2mhorQoj9bLN8v.w6btE9xy1:16431:0:99999:7:::
...
...
...
mandar:$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.:16431:0:99999:7:::
mysql:!!:16550::::::
nagios:$6$P9zn0KwR$tgfvvFWJJ5FKmoXiP5rXWOjwoEBOEoAuBi3EphRbJqqjWYvhEM2wa67L9XgQ7W591FxUNklkDIQsk4kijuhE50:16632:0:99999:7:::
To study the file in more detail, let us consider the entry for the user 'mandar' as below:

mandar  :  $6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.  :  16431  :  0  :  99999  :  7  :   :   :
|---1---|---------------------------------------------------2----------------------------------------------------------|----3----|--4--|----5----|--6--|-7-|-8-|
For better understanding, I've divided the line entry across each colon(:) to create 8 fields, which are explained as below:
  1. Username field: This field denotes the username (or the user account name), that should be used while logging in to the system.
  2. Password field: This field stores the password in encrypted format (explained in detail below).
  3. Last Password Change: This field denotes the number of days, since UNIX time (1-Jan-1970), the last password change happened.
  4. Minimum days between password changes: This field denotes the minimum number of days after which a user can change his password.
  5. Password validity: This field denoted the maximum number of days for which password is valid. After that, the password will expire and the user will have to change the password.
  6. Warning threshold: This field denotes the number of days before which the user will receive a warning notification about the password expiry.
  7. Account inactive: This field denotes the number of days after which the account will be disabled, when the password is expired.
  8. Time since account is disabled: This field denotes the number of days, from UNIX time, since which the account is disabled.

The Encrypted Password

The field #2 in each line entry is the encrypted password, as we just learned. But, how this password is generated, we'll learn in this portion of the article. Let's just rewrite the encrypted password here-

$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.

Let's break this encrypted password in some parts, across the dollar ($) sign, to understand it better.

$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.
|1|-------2--------|-----------------------------------------3--------------------------------------------|
1. Hash Algorithm: This field denotes the hashing algorithm used to create the hashed password. The digit 6 describes that, SHA-512 algorithm is used, in this case. Some more of them are enlisted below:

--------------------
| 1  | MD5         |
--------------------
| 2  | Blowfish    |
--------------------
| 2a | eksBlowfish |
--------------------
| 5  | SHA-256     |
--------------------
| 6  | SHA-512     |
--------------------
2. Salt Value: Salt values are used to make the hash value stronger. These are the random type of data that is used to combine with the original password and then the hashed version of that is used as the encrypted password.
3. Password: This field stores the hashed version of the combination of original password and salt value.

To verify this, we would try to generate the hash value using SHA-512 algorithm along with the salt value (5H0QpwprRiJQR19Y) and the original password (mandar) and match it with the hash value mentioned in the /etc/shadow file.

Syntax of the command is as below:

perl -e 'print crypt("<PASSWORD>","\$<HASH-ALGO>\$<SALT-VALUE>\$") . "\n"'
In our case,
<HASH-ALGO> = 6
<PASSWORD> = mandar
<SALT-VALUE> = 5H0QpwprRiJQR19Y
Expected Output = $6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZOPsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.

Lets run the command now.

MyLinuxBox root ~ > perl -e 'print crypt("mandar","\$6\$5H0QpwprRiJQR19Y\$") . "\n"'
$6$5H0QpwprRiJQR19Y$bXGOh7dIfOWpUb/Tuqr7yQVCqL3UkrJns9.7msfvMg4ZO/PsFC5Tbt32PXAw9qRFEBs1254aLimFeNM8YsYOv.
Both the hash values match. That's why, this file is not world-readable and passwords are not saved in /etc/passwd (it being world-readable).

That's all for this article, stay tuned for more of them.

    Total Pageviews