Category: CentOS

In our previous article, we have seen how to configure sudo user in Linux. Here we are going to see some of the situations, and their corresponding ‘sudo‘ line configurations. This will help you to allow the sudo user to run a specific system command. so, lets get started:

1. You have a user ‘andrew which is a Database Administrator. You want to provide him all access on the Database Server (beta.database_server.com) only, and not on any host.

For the above situation, we can write the ‘sudo‘ line as follows:

andrew beta.database_server.com=(ALL) ALL
2. You have a user ‘mark‘ which is supposed to execute system commands as a user other than root on the same Database Server which is explained above.

For this situation, we can write the ‘sudo‘ line as follows:

andrew beta.database_server.com=(mark) ALL
3. You have a sudo user ‘tom‘ which is supposed to run command ‘’cat‘ only.

To implement this situation, we can write ‘sudo’ as:

andrew beta.database_server.com=(tom) dog
4. What if the user needs to be granted several commands?

If the number of commands the user wants to run is under 10, we can place all the commands alongside. We can set these commands with white spaces in between them, as shown below:

andrew beta.database_server.com=(cat) /usr/bin/command1 /usr/sbin/command2 /usr/sbin/command3 ...

If this list of command varies to the range, where it is literally impossible to type each command manually then we need to use aliases. Aliases are a Linux utility where a lengthy command or a list of commands can be referred to as a small and easy keywords.

Following are the few alias examples, which can be used in place of entry in ‘sudo‘ configuration file.

User_Alias ADMINS=tom,jerry,adam
user_Alias WEBMASTER=henry,mark
WEBMASTERS WEBSERVERS=(www) APACHE
Cmnd_Alias PROC=/bin/kill,/bin/killall, /usr/bin/top

We can also specify System Groups, in place of users, which belongs to that group just suffixing ‘%’ as below:

%apacheadmin WEBSERVERS=(www) APACHE
5. How we can execute a ‘sudo‘ command without entering a password?

We can execute a ‘sudo‘ command without entering a password by using ‘NOPASSWD‘ flag as shown in the following sudo line.

kristy ALL=(ALL) NOPASSWD: PROCS

Here the user ‘kristy‘ can execute all the commands aliased under “PROCS”, without entering the password.

However, sudo configuration is easy. Some of the Linux distributions have “sudo” enabled by default while most of the Linux distros of today need you to enable it as a Security Measure.

To add the user (adam) to sudo execute the below command as root.

adduser adam sudo 

In this way, you can maintain your server security by assigning sudo access to other users to whom you want to grant specific system access.

Linux system administrators need to configure networking on their systems. On desktop machines, you can use dynamic IP addresses but on server infrastructure, you will need to set up a static IP address for a stable connection.

IP addresses on Linux systems are mostly assigned automatically by Dynamic Host Configuration Protocol (DHCP) servers. These are referred to as “dynamic addresses” and can change any time the system is rebooted. When a system is on a server or will be remotely administered, it is more convenient for these systems to have static addresses, offering stable and consistent connections with users and applications.

Fortunately, the steps required to setup a Linux system’s IP address from dynamic to static are fairly easy, though they will be a little different for the various distribution you are using. In this post, we’ll look at how this task is managed on RHEL/CentOS/Fedora and Debian/Ubuntu systems.

IP address: 192.168.0.100 Netmask: 255.255.255.0 Hostname: node01.linux-documentation.com Domain name: linux-documentation.com Gateway: 192.168.0.1 DNS Server1: 8.8.8.8 DNS Server2: 4.4.4.4

Configure Static IP Address in RHEL/CentOS/Fedora:

To configure the static IP address in RHEL / CentOS / Fedora, you will need to edit these files:

/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0

Where in the above "ifcfg-eth0" answers to your network interface namedeth0. If your interface is named “eth1" then the file that you have to edit is "ifcfg-eth1".

Let’s start editing the first file:

# vi /etc/sysconfig/network

Open that file and set the following:

NETWORKING=yes HOSTNAME=node01.linux-documentation.com GATEWAY=192.168.0.1 NETWORKING_IPV6=no IPV6INIT=no 

Now open next file as shown below:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Note: Make sure that you have opened the file corresponding to your network interface. You can get your network interface name using command ifconfig -a.

In that file you have to make the following changes:

DEVICE="eth0" BOOTPROTO="static" DNS1="8.8.8.8" DNS2="4.4.4.4" GATEWAY="192.168.0.1" HOSTNAME="node01.linux-documentation.com" HWADDR="00:19:99:A4:46:AB" IPADDR="192.68.0.100" NETMASK="255.255.255.0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="8105c095-799b-4f5a-a445-c6d7c3681f07"

You will only need to edit the settings for i.e enter their respective values and save the file:

  1. DNS1 and DNS2
  2. GATEWAY
  3. HOSTNAME
  4. NETMASK
  5. IPADDR

Other settings should have already been predefined.

Next edit resolve.conf file by opening it with a text editor like nano or vi:

# vi /etc/resolv.conf
  
nameserver 8.8.8.8 # Replace with your nameserver ip
nameserver 4.4.4.4 # Replace with your nameserver ip

Once you have made your changes restart the networking with the following commands:

# /etc/init.d/network restart  [On SysVinit] 
# systemctl restart network [On SystemD]

Set Static IP Address in Debian / Ubuntu

To setup static IP address in DebianUbuntu, you have to open the following file:

# nano /etc/network/interfaces

You will see a line looking like this:

auto eth0
iface eth0 inet dhcp

Change it so it looks like this:

auto eth0
iface eth0 inet static 
  address 192.168.0.100
  netmask 255.255.255.0
  gateway 192.168.0.1
  dns-nameservers 4.4.4.4
  dns-nameservers 8.8.8.8

Save the file and then edit /etc/resolv.conf as follows:

# nano /etc/resolv.conf
nameserver 8.8.8.8 # Replace with your nameserver ip 
nameserver 4.4.4.4 # Replace with your nameserver ip

Restart the networking on your system with the following commands:

# /etc/init.d/network restart  [On SysVinit]
# systemctl restart network [On SystemD]

Your static IP address has been successfully configured.

Now, you know how to configure a static IP address on a Linux distro.

We have gone through certain Linux Shell Commands in our Part I article. Let’s see a few more basic Linux commands here.

The rm command:

This command is used to remove a file or directory. The -rf option is to remove a file or directory recursively. You must use this command carefully i.e if you run this command in the home directory, or any other important directory, it will delete everything there without confirmation. -f stands for force, it will perform the delete action forcefully. So, please be careful while using this command.

root@monitor:/home# ls
ansible ec2-automate-backup.sh ssbackup.py test
dir1 ssbackup.log ssbackup.py-bak ubuntu
root@monitor:/home# rm -rf test
root@monitor:/home# ls
ansible ec2-automate-backup.sh ssbackup.py ubuntu
dir1 ssbackup.log ssbackup.py-bak
The cp command:

The cp command used to copy a file in the Linux shell. To copy a file/directory recursively use the cp command with the -r flag. For example, we are coping test1.txt to test2.txt

root@monitor:/home# cp test1.txt test2.txt
root@monitor:/home# ls -l
-rw-r--r-- 1 root root 0 Jan 23 16:46 test1.txt
-rw-r--r-- 1 root root 0 Jan 23 16:46 test2.txt

In the below example we are copying test dir to /tmp folder :

root@monitor:/home# cp test /tmp/
The mv command:

The mv command is used to rename or move a file or a directory. In following example we are renaming test1.txt to test.txt.

root@monitor:/home# mv test1.txt test.txt
root@monitor:/home# ls -l
-rw-r--r-- 1 root root 0 Jan 23 16:46 test2.txt
-rw-r--r-- 1 root root 0 Jan 23 16:46 test.txt

In the below example we will move file test.txt to /tmp directory.

root@monitor:/home# mv test.txt /tmp/
root@monitor:/home# cd /tmp/
root@monitor:/tmp# ll | grep test.txt
-rw-r--r-- 1 root root 0 Jan 23 16:46 test.txt
The wc command:

wc is a useful command to count newline, word and bytes of a file

root@monitor:/home# cat test.txt
HI that is a file.
This is the second line.
And we also have a third line.
root@monitor:/home# wc -l test.txt
3 test.txt
root@monitor:/home# wc -w test.txt
17 test.txt

The -l flag is to find the number of lines in a file, -w is to count the number of words in the file.

The echo command:

The echo command echoes a given string to the display.

 $ echo "Hello"
Hello
Redirecting the command output

we can redirect the command output to a file, or as input to another command. | is the most common way to do so. Using this we can count the number of directories in the root (/) directory very easily.

$ ls / bin boot dev etc home lib lib64 lost+found media mnt opt proc root run ˓→sbin srv sys tmp usr var 
$ ls / | wc -w
20
Using > to redirect output to a file!

You can use > to redirect the output of one command to a file, if the file exists this will remove the old content and only keep the input. We can use >> to append to a file, means it will keep all the old content, and it will add the new input to the end of the file.

$ ls / > details.txt 
$ cat details.txt
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var $ ls /usr/ > details.txt $ cat details.txt bin games include lib lib64 libexec local sbin share src tmp
$ ls -l /tmp/ >> details.txt
$ cat details.txt
bin games include lib lib64 libexec local sbin share src tmp
total 776
-rwxrwxr-x. 1 fedora fedora 34 Jun 24 07:56 helol.py
-rw-------. 1 fedora fedora 784756 Jun 23 10:49 tmp3lDEho
The man pages.

The man command shows the system’s manual pages. You can use this command to view the help document (manual page) for any command.

Syntax:

man section command. 

Example : man 7 signal.

Linux shell or the terminal is the lifeline of developers to manage their computer systems and data. Things which can be done on the GUI can be done much efficiently on the terminal by using commands. One can not remember all the commands, but with regular usage, one will be familiar with them. The following guide will introduce you to some basic Linux Shell Commands required to use your Linux system efficiently.

Gnome Terminal

Below, you can see a screenshot of the Gnome terminal application. As you can see the command prompt contains the following information:

 [username@hostname directoryname]  

In our case the username is root, hostname is monitor and directory is /root(~).

Gnome- Linux Shell Commands
Gnome Terminal

A terminal and a shell:

Read the articles on Wikipedia to learn about computer terminals and the shell.

Date command:

The date command shows the current date and time.

$ date 
Tue Jan 22 10:13:44 IST 2019

If you want to see the current date and time in UTC you can run the command as follows:

 $ date -u 
Cal command:

The cal command will display calendar in your shell, by default it displays current month.

 $ cal 
January 2019
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

$cal Feb 2019
February 2019
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
The whoami command:

This command will let you know the user account to which you are logged in on the shell.

$whoami
root
The id command:

This command returns user id, group id and groups of the current user.

$ id 
uid=0(root) gid=0(root) groups=0(root)
The pwd command:

The pwd command displays absolute path of current directory.

root@monitor:~# pwd
/root
The cd command:

This command will help you change directory on the shell. In the following example we will move to /etc/ directory.

root@monitor:~# pwd
/root
root@monitor:~# cd /etc/
root@monitor:/etc# pwd
/etc
The . directory and .. directory:

. and .. has special meaning in the Linux. i.e . means current directory and .. means parent directory.

root@monitor:/etc# cd .. 

This command will move us to the parent directory.

The ls command:

The ls command will display the files and directories inside the given directory. If you use the ls command without any argument, then it will return the output for the current directory. Here is the example:

root@monitor:/# ls
bin etc key.txt lost+found opt run srv usr
boot home lib media proc sbin sys var
dev initrd.img lib64 mnt root scripts tmp vmlinuz
root@monitor:/# ls home
ansible ssbackup.log ssbackup.py-bak
ec2-automate-backup.sh ssbackup.py ubuntu

In last command, we provided a path as the argument to the ls command.

The mkdir command:

Using the mkdir command you can create new directory. For example , we are creating test directory in home directory.

root@monitor:/home# mkdir test
root@monitor:/home# ls
ansible ssbackup.log ssbackup.py-bak ubuntu
ec2-automate-backup.sh ssbackup.py test

We can also create directories in a recursive way using -p option:

root@monitor:/home# mkdir -p  dir1/dir2/dir3
root@monitor:/home# ls
ansible ec2-automate-backup.sh ssbackup.py test
dir1 ssbackup.log ssbackup.py-bak ubuntu
root@monitor:/home# ls dir1
dir2
root@monitor:/home# ls dir1 dir1/dir2/
dir1:
dir2
 dir1/dir2/:
dir3

We will learn further basic commands in Part II.

To read about Linux file access permissions please refer our other article here. It will help you understand the Linux files/directories permissions structure.

If you have ownership of a file or directory then you can change access permission of that file for other users. The image given below is showing the permission structure used in Linu.

To change ownership of a file or directory in Linux you have to use chmod command followed by the following attributes.

  • The user for whom you want to change the permission.
  • The type of access permission to add, remove or assign.
  • The list of files and directories for whom you want to change the permissions separated by spaces.

You can change access permission for the users who are in the following categories:

  • the owner of the file (user, u)
  • the group that own the file (group, g)
  • the other users (others, o)

Access permissions refers to read(r),write(w) and execute(x).

As the root user, you can also change the ownership of a file or directory using the chown command.

For example

-rw-r----- 1 jaon users      0 2006-06-23 16:08 checklist.txt
-rw-r--r-- 1 jaon users 53279 2006-06-21 13:16 gnome_quick.xml
-rw-rw---- 1 jaon users 0 2006-06-23 16:08 index.htm
-rw-r--r-- 1 jaon users 70733 2006-06-21 09:35 kde-start.xml
drwxr-xr-x 2 tux users 48 2006-06-23 16:09 local

In the above example, user jaon is the owner of file kde-start.xml and has read, write access to the file but can’t execute it. The users group can read the file and can read this file but can’t write and execute it and the same permissions applied for other users in the next block.

How to modify access permissions for your files?
  • If you want to allow the users group write access to kde-start.xml then use following command:
      chmod g+w kde-start.xml
  • To allow the users group and other users write access to kde-start.xml use following command:
     chmod go+w kde-start.xml
  • To remove write access for all users use this command as follows:
     chmod -w kde-start.xml
  • If you don’t want to allow usersgroup and others to change into the local directory, use following command.
     chmod go-x local
  • To allow write access to other users to two files at same time, use following command:
      chmod o+w  kde_quick.xml gnome_quick.xml

Let’s see the commands used to change ownership of files and directories.

The Root user can change ownership for other user’s data. Login to the server using the root user and its password and run the below command to change the ownership.

chown kristy kde_quick.xml

In above example, we have changed ownership for file kde_quick.xml from user jaon to kristy.

To check if the ownership changed or not, lets list the file using ls -l

ls -l kde_quick.xml
-rw-r--r-- 1 kristy users 47896 2006-06-21 09:46 kde_quick.xml

It is done!

The file system is a logical collection of files on a disk. In Linux, all users including the root user which is also known as the superuser have their own home directories to save their data in.

Linux Directory Structure:

In Linux, you can choose any method to manage files and folders with a file manager or with the command line. The thing you should consider is that you must have good knowledge of the Linux commands to use command line method.

Linux and Unix use a tree-like file system structure with root (/) at the base of the file system. All the other directories spread from there. Each of these directories has a specific purpose. Generally, they hold the same types of information so that you can easily locate files. The following are the common directories found in Linux and Unix:

/

This is the root directory which contains the directories needed at the top level of the file structure.

/bin

This directory contains the executable files. These files are available to all users.

/dev

It holds device files that represent hardware components.

/lib

It contains shared library files and sometimes other kernel-related files.

/tmp

This directory holds temporary files used between system boots.

/boot

It contains files for booting the system.

/etc

This directory host-specific system configuration files.

/home

It contains the home directory for users and other accounts on the server.

/var

Basically, it contains variable-length files such as log and print files and any other type of file that may contain a variable data.

/mnt

This directory used to mount other temporary file systems, such as CD-ROM and floppy for the respective drive.

/proc

This directory contains all processes marked as a file by process number or other information that is dynamic in the system.

/usr

This directory used for miscellaneous purposes and can be used by many users. Additionally, it has administrative commands, shared files, library files, and others

/sbin

It contains binary files, basically for system administration. For example, fdisk and ifconfig utlities.

/kernel

This directory contains kernel files.

Please refer our other file system related articles at following theselinks:

https://linux-documentation.com/linux-file-access-permissions/(opens in a new tab)

https://linux-documentation.com/modifying-file-permissions-in-linux/(opens in a new tab)

I hope these articles will help you understand the Linux File System easily.

We have discussed the most well known Linux distributions such as Ubuntu, Linux Mint, Debian, Fedora in Part I. In this article, we are going to discuss a few more Linux distributions, mainly for Server use.

CentOS

CentOS is another Red hat based community distribution. It is
more standard than Fedora and designed for Server management. It uses the same installer as Fedora and hence it is easy to install. There is a decent selection of applications.

Download Link: https://www.centos.org/download/

openSUSE

openSUSE is a good alternative for Ubuntu and other Linux based distributions. It provides a stable environment for home users along with multiple applications and a decent level of support.

Its installation can be bit tricky for new or inexperienced computer users but once set up you’ll have access to a decent documentation.

Download Link: https://software.opensuse.org/distributions/leap

Arch

Arch distribution provides up-to-date software and drivers but requires more maintenance than other distributions. It requires decent knowledge and willingness to read manuals.

Download Link: https://www.archlinux.org/download/

Lubuntu

Lubuntu is a lightweight version of Ubuntu which is deploying the LXDE desktop environment. It also contains a full set of desktop applications which aren’t as fully featured as the main Ubuntu operating system applications.

Lubuntu provides access to the main Ubuntu repositories which allows you to install any application that you want to use.

Download Link: https://lubuntu.net/tags/download/

Elementary

Elementary has a clean and elegant user interface. It is designed to be lightweight as well as easy to install and use. It is based on Ubuntu and thus provides access to a large repository of applications.

Download Link: https://elementary.io/

Choose the distribution as per your requirements. Once you are familiar with the installed distribution, you will notice that there is no big difference between the common distributions. They share the same kernels and have the same software packages. Furthermore, you can easily install or add any software packages not included in your original installation.

We have already seen some of the famous Linux distributions in our other article. You can check it out here. In this article, we are going to describe the main criteria to choose the perfect Linux distribution.

Linux is based on Unix. Various software developers worked on it and turned it into different ‘distributions’ or ‘distros’. Most of the Linux distros use the Linux kernel (the soul of the operating system). The different desktop environments for these distros are then built around that kernel.

Ubuntu

Ubuntu is a Modern operating system with full hardware integration and a complete set of applications.
If you are worried about the Linux command line, try Ubuntu, because you won’t need the terminal window at all. It is easy to install as well as easy to use with great support.

Download Link: http://www.ubuntu.com/download/desktop

Debian

Debian is one of the oldest and most stable Linux distributions. It is the base for many of the other distributions such as Ubuntu and Linux Mint. It’s community distribution ships with free software and drivers. The Debian repositories offer thousands of applications. There are different versions available for many hardware devices.

Its installation is the easiest because there are various steps you need to go through post-installation to get all of your hardware working.

Download Link: https://www.debian.org/distrib/

Fedora

Fedora is a Red Hat based community distribution. It always comes with up-to-date software and drivers and was one of the first distributions to introduce both Wayland and SystemD. Fedora has a quite regural development update.

Easy to install and contains a good range of software. Not all of the packages are stable.

Download Link: https://getfedora.org/en/workstation/download/

Linux Mint

Linux Mint is a strong option for those who are new to Linux. It is the best starter OS for those who want to switch from Windows/Mac. It provides an impressive amount of customization options with good media support. It is based on Ubuntu, Debian Linux distros.

It is easy to install, contains all the applications you need for general home computing.

Download Link: https://www.linuxmint.com/download.php

Please refer to our other article regarding an Introduction to Linux Operating Systems.

In this article, we are going to see what are the Linux features which makes it the first choice of developers as well as the best option for Server Management and Web Hosting.

Graphical User Interface:

Basically, Linux is a command line based OS that allows converting to a GUI based OS by installing packages. It also supports Graphical Customization.
GNU/Linux is an OS allowing you to choose the GUI you like, for example from Arch Linux and install it on your system. You can change this GUI pattern any time you want.

Control Over the Entire Base System:

GNU/Linux is great when it comes to fixing errors related to any system package or tool. As the system is built with modular pieces, if any package breaks, you can either uninstall then re-install the problematic package via the Command Line or the graphical interface. Also, you can find a different tool as a replacement.

Packages:

Linux has its own software repository which allows users to download and install many applications. In Debian, there is the apt-get command that installs a program without compiling. The exact command is “apt-get install programname“. You can even use APT to install Chromium (a graphical application) if you wish. Similerly, Red Hat has yum, Arch Linux has pacman, etc.).

Multiuser capability:

More than one user can access the same system resources like memory, hard disk, etc. from different terminals.

Multitasking:

More than one function can be performed concurrently by dividing the CPU time intelligently.

Security:

It provides security in three ways i.e authentication, by giving user id with the username, authorization by giving permission to read, write and execute and encryption by converting files to an unreadable format.

Live CD/USB:

Almost all Linux distros provide live CD/USB so that users can run it without installing it.

Portability:

It supports different types of hardware.

File System: 

Files and directories are arranged in a hierarchical structure which is easy to understand by users.

Programmer-friendly: 

Linux comes with everything you need to compile both C and C++ programs out of the box, regardless of distribution. It supports different languages as well.

Linux is a free and open source operating system released in 1991 for computers. But today, it works on computers, servers, mainframes, mobile devices, and embedded devices. Linux is one of the most popular versions of the UNIX Operating System. It was designed considering UNIX compatibility and thus it’s quite similar to Unix.

Linux-based operating systems are mostly used by developers to get their work done and develop something new. They are choosing a Linux distro for development because it’s easy to use as well as compatible with most of the programming languages i.e Java, PHP, HTML etc. Today, Linux is ideal for commercial network devices and enterprises who want to use it to customize their own network and data center infrastructure.

The following is a list of best Linux distributions for Development and Server Management:
  • Debian
  • Ubuntu
  • Fedora
  • CentOS/REDHAT
  • Raspbian
  • And more

Please check out our other article to get more information about these Linux distributions here.

Primary Components of Linux

These are the three primary components of this operating system:

Kernel

The kernel is a core part of the operating system. It performs all major activities. It consists of various modules and interacts directly with the internal hardware. The Main function of the kernel is to send instructions to the CPU, peripherals, and memory.

System Library

System libraries are the programs that allow application programs or system utilities to access the Kernel’s features. These libraries are responsible for executing most of the OS programs. They don’t have the kernel module’s code access rights.

System Utility

System Utility programs are responsible to perform specialized, individual level tasks. Beyond tthe operating system it has two modes such as Kernel Mode and User Mode. The system runs programs under one of these modes.

Kernel Mode vs User Mode

Kernel Mode has full access to all resources of the system. In kernel mode programs represent a single process. It executes in single address space and does not require any context switch. Because of which this mode is very efficient and fast.

User programs and other system programs run in User Mode. It has no access to system hardware and kernel code. User programs use system libraries to access kernel functions to get the system’s low-level tasks done.