Showing posts with label Certification. Show all posts
Showing posts with label Certification. Show all posts

RHCSA Howto ... Tips and Tricks - Episode 2

Introduction

In this episode of my journey to the desired certification (RHCSA), we are going to provide some information about one of the topic of the chapter "Understand and use essential tools":
  • access a shell prompt and issue commands with correct syntax
There is no "official" list of commands which Red Hat suggest you to know to pass the certification as it does not really matter how you solve the question; so every command or option you use, which is available in the distribution ISO and you are familiar with, will be good.
Penguin alla console

Feel free to add your comments and recommendation; we will be happy to reply and or update the post!
Let's get started !

access a shell prompt and issue commands with correct syntax

There are 3 type of commands in Linux:
  • internal
  • external
  • aliases
An internal command is part of the shell itself. An example of internal command is echo which print to the standard output whatever is the argument.
An external command is an executable file located somewhere in the fylesystem. An example of external command is /bin/hostname which print the name of your system.
To know if you are calling an internal or external command you can use the command type, while with which you will know the exact command the shell will use:

$ type ls
ls is aliased to `ls --color=auto'

$ which ls
alias ls='ls --color=auto'
        /usr/bin/ls

The output shows that there is an alias called ls and an executable file called /usr/bin/ls. Aliases have precedence on both internal and external commands so Bash will use the alias when we will use the ls command (see below for more info on the aliases).

If you want to create a custom command, you can use an alias. If for example you frequently use a specific command with some option (like ls -al or df -h) you can use the Bash command alias to create a "custom command" (alias). There are some useful aliases available by default in most distribution. To check which are available for your user just type alias at the Bash prompt:

# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .*'
alias ll='ls -l'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

To create a new alias you just have to type "alias" followed by the command name you want to use, equal the command that it will execute (as you can see in the output of the raw alias command). Let's look at an alias example:

# df
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root 385867688 58806536 327061152  16% /
devtmpfs                  3885068        0   3885068   0% /dev
tmpfs                     3901000      320   3900680   1% /dev/shm
tmpfs                     3901000    42304   3858696   2% /run
tmpfs                     3901000        0   3901000   0% /sys/fs/cgroup
/dev/sda2                84907480 30177444  50393860  38% /home
/dev/sda1                  508588   363028    145560  72% /boot
tmpfs                      780204       16    780188   1% /run/user/1001
tmpfs                      780204       24    780180   1% /run/user/1000

# alias df='df -h'

# df
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  368G   57G  312G  16% /
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.8G  320K  3.8G   1% /dev/shm
tmpfs                    3.8G   42M  3.7G   2% /run
tmpfs                    3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/sda2                 81G   29G   49G  38% /home
/dev/sda1                497M  355M  143M  72% /boot
tmpfs                    762M   16K  762M   1% /run/user/1001
tmpfs                    762M   24K  762M   1% /run/user/1000

As you can see from now on, typing df I will get the output of "df -h" which is much more easy to read (human readable format) than the raw command.

The issue here is that whenever you close the shell or restart your server, the alias you manually enforced will disappear. To make the change persistend and customize many other shell behaviour there are 4 files to consider:

  • ~/.bashrc    -   user specific config, read by a non-login shell
  • ~/.bash_profile   -   user specific config, read by a login shell
  • /etc/bashrc   -   system config, read by a non-login shell
  • /etc/profile   -   system config, read by a login shell

I suggest you to have a look at the content of each of the mentioned files to discover which configuration are applied in each of the situation. Be aware that: when you open a login shell, Bash read the /etc/profile file first and then the ~/.bash_profile. The user specific settings have priority and override the system settings. The same for the "non login" shell.

Some more alias-stuff ! If you just created an alias for the current session, you can remove it by typing unalias followed by the command name (unalias df). You can also force Bash to use the internal or external command instead of the alias by unticipating the command with a backslash (\df).

Other interensting topic about the shell is the environment variables. A variable is a way to assign a value (which can be a string or a number) to a label (i.e. a name) which can only start with a letter. As a style rule it is better to use capital letters for variable names. Variables that are "available" within a working shell are called environmental variable. You can get a list executing the command env.
When you create a Bash script and you need to use multiple times the same value, it is a good idea to create a variable and call it within the script. As the variable has been created in the script, it will be available just within it (you need to export it to make it available within the running shell, outside the scope of the script).
You can permanently define environment variable by adding or modifying them within the Bash script we have been reviewing above. You can create or assign a value to a variable for the current session in the following way:

$ TEST="This is a test"
$ echo $TEST
This is a test

As you can see, you can use echo to print to the value of a variable to the standard output (just precede the variable name with a $).

To make your life easier you can recall commands that you have executed before by using the Bash internal command history. The command history is stored in RAM until the session is closed; at that point the list is appended to the ~/.bash_history text file.
So typing history you can get the list printed in your shell. Each entry start with a number to make it easy for you to execute the same command again:

$ history
   .........
   88  su
   89  df
   90  su
   91  alias
   92  su
   93  env
   94  TEST="This is a test"
   95  echo $TEST
   96  which ls
   97  type ls
   98  type /usr/bin/ls
   99  type ls
  100  history

$ !99
type ls
ls is aliased to `ls --color=auto'

You can scroll backward the list using CTRL-R. With CTRL-R you enter into an interactive session... type part of a command you already entered and see what happen!!
You can also call a command by typing ! followed by part of the command.
A good security measure is to clear the root history when closing the session. In this way, if an cracker succeed to compromise your system, there will be no traces of any possible "clear" password you typed within your commands (in example when you login to a database by providing the password while starting the CLI ... dangerous!!). It is also something crackers do to remove their footprints. Clearing the history is a 2 steps process: you need to clear the commands in memory (history -c) and you need to clear the content of the file ~/.bash_history (history -w).

RHCSA Howto ... Tips and Tricks - Episode 1

Introduction

As I recently started to study to improve my knowledge in Red Hat Enterprise Linux (RHEL), I thought it was a good idea to use the Blog like a notepad where I will write information on the topics of the certification, links to external websites which provide tutorials and whatever matters with the topic!

The RHCSA certification is the introductory Red Hat System Administrator certification and a mandatory step for the Red Hat Certified Engineer (RHCE) certification.

As the topic are subject to change by Red Hat, if you want to take my same journey, I suggest you to check the following link and print-out the "Study Point".

At the moment of writing this post (July 2017), the topics are divided into the following chapters:
  • Understand and use essential tools
  • Operate running systems
  • Configure local storage
  • Create and configure file systems
  • Deploy, configure, and maintain systems
  • Manage users and groups
  • Manage security
As written at the end of the webpage of the mentioned Red Hat link, quote "Red Hat reserves the right to add, modify, and remove objectives. Such changes will be made public in advance through revisions to this document" ... unfortunately there is no "revision number" in the document itself so ... check the document multiple times during the preparation.

I would not suggest to take this certification journey if you don't already have a couple of year of experience with Linux! You will possibly waste time and money and this certification is not cheap... currently the exam cost around 470£ + VAT ... quite expensive!

Training Material

After downloading the topic list you need to figure out where to get information, which training material to study, which books, videos ...
I love Linux for many reasons, one is that you can find so many information for free. Perhaps when it comes to a certification, in my opinion you need to have an official certification guide: this will help you to divide and conquer each topic, have a set of exercises and labs and have one or more exam simulation to verify if what you learnt is enough to pass the exam or if you need to review any topic.

I have been able to review several books (thanks to some friends) and the one I found perfect for my study-style is:
Cert Guide - Red Hat RHCSA/RHCE 7 - by Sander Van Vugt

As I like to read the same topic from different authors I am using these other books as well:

The Linux Bible - Ninth Edition - by Christopher Negus
which is a good "comprehensive" book full of tutorials and resources.

How Linux works, what every superuser should know - by Brian Ward
more about troubleshooting but with interesting information even for a System Admin

Note: I don't have any interest/profit by mentioning the above books but I found good to suggest them and promote the authors work.

As you will read on all the books, for any command you will come across during your journey, you should have a proper look to the man page and to the info page (if any): these resources will be the only one available to you during the exam ... so better to know how to use it to your advantage!!

Lab and first experiences

That's the first step! What Sander suggest is to create 3 virtual environments:
  • server with CLI
  • server with GUI
  • server for LDAP authentication and other shared services
You can create an account and download the official Red Hat 7 image and then create the 3 VMs or, more simply, download CentOS 7. At the moment of writing (July 2017) it seems like the exam will focus on versions 7.1 and 7.2 of Red Hat Enterprise Linux. You can use CentOS with the same version number as basically CentOS is a Red Hat Enterprise "stripped of the Red Hat" logo.
So what is the difference between Red Hat and CentOS and why companies are paying for Red Hat? When it comes to the ISO, the same versions of the 2 distribution has the same packages version and pretty similar configurations; they are basically interchangeable.
When it comes to apply patches, CentOS provides free access to its repositories while to get access to Red Hat you need to pay an annual fee. The fee does not entitle you only to get access to the repository but also to get free high quality, 24H 7/7 365 support! That's the main difference ... an enterprise level support which will take care of providing you quick and expert answer to your queries.
So, setup your VMs and start to play around with the basics! If you already have a Linux machine running CentOS you may find useful to read my post about deployment of VM using KVM.

In my next post I will focus on the objective of the first chapter "Understand and use essential tools":
  • access a shell prompt and issue commands with correct syntax
  • use input-output redirection
  • use grep and regular expression to analyze text
  • access remote system using ssh
  • log in and switch users in multiuser targets
  • archive, compress, unpack, and uncompress files using tar, star, gzip and bzip2
  • create and edit text files
  • create, delete, copy, and move files and directories
  • create hard and soft links
  • list, set, and change standard ugo/rwx permissions
  • locate, read and use system documentation including man, info and files in /usr/share/doc
In the post I will introduce the commands that you need to know focusing on the tasks which maybe required in the exam.

Recommendations

If you decide to take a journey into a certification the most common recommendation is to schedule your study activities and have a target day for the exam! There is no better recommendation. I know that sometimes life and work does not help to keep you on track but without any target milestone you will never meet the desired result!
Please feel free to add comments; they may be helpful for other geek who would like to learn the topic! I hope you enjoyed reading this post.
Stay tuned!