Tuesday, 18 August 2020

Open source careers: How Mehdi Hamidi became a DevOps Specialist

LPI Tutorial and Materials, LPI Exam Prep, LPI Certification, LPI Exam Prep, LPI Learning

In 2019, Linux Professional Institute (LPI) celebrated 20 years of offering training and tests. The LPI20 Birthday Contest gave us the opportunity to hear from you some amazing stories about your careers in open source and how the LPI certification program helped you. Over the next weeks, we’ll share some of these stories.

We are gratified to start with the story of Mehdi, a SysAdmin and DevOps Engineer from Iran.

Pentium 133, DevOps, and everything in between


LPI Tutorial and Materials, LPI Exam Prep, LPI Certification, LPI Exam Prep, LPI Learning
I’m Mehdi Hamidi, a DevOps Specialist with 5 years of work experience in System Administration and DevOps. I believe my current position grew from of a change in direction I took early in my education. And I think I have been lucky in my life. So, let me tell you my “techie life” story…

In the beginning


When I was 13, my aunt had a Pentium 133 computer and I was curious about how a computer works. I almost immediately started writing code, before having my own computer. I had read a QBasic book and I was writing the code on… paper. My first memorable achievement, which I’m still incredibly proud of, was a Qbasic Code to calculate prime numbers up to 1000.

It was six months before I could visit my aunt again.The code worked fine.

I am very happy to share my story about how LPI has changed my life and helped me in pursuing my goals.

Linux and Open Source: many kernels ago


The first Linux environment that I was involved with was RedHat Linux 7.2 in high school. I loved writing code in C and testing it on Linux. At that time I started learning the Linux commands.

At the university, courses required mostly Microsoft environments and C# language; however, I always kept an eye on Linux.

The path seemed clear: to get my Master of Science, send out CVs, start work. But halfway through my postgrad program, I found out that it wasn’t what I expected. I needed something more practical, something that I could do. I left the university. But I wasn’t quitting the computer field: I was looking for a way to get more involved in something that was not teached in universities, something related to my technical goals, by which I could become a prominent expert.

The Linux Community and me


I immediately started looking for a community of developers and SysAdmins in Iran. I started attending the Tehran LUG meeting and the other events such as the Ubuntu Release Parties.
Then I opened my Twitter account. Twitter had an undeniable impact on allowing me to connect with my technical friends as well as industry experts.

It seemed that It was for a big change. I quit my routine job and went for learning PHP, as I wanted my applications web-based. The problem is: I genuinely hated PHP! It seemed the end of the line. But I was wrong.

I hadn’t realized that having a good knowledge of Linux is a great key for aspiring to System Administrator positions. I heard of LPI for the first time at an Ubuntu Release Party. Meanwhile, a SysAdmin friend told me a small company was developing its private cloud. I wasn’t sure what it was about, but it was something Linux related, and that was enough. ;-)

After two months studying Linux and virtualization, I started the job. Meanwhile, I bought a Raspberry Pi and built up a home server, just to keep me (more) busy. I implemented a Wordpress blog with Apache on that Raspberry Pi with a single core CPU. Just imagine, what would happen with all of the LAMP stack on a single SD Card…

This was the beginning of my learning about web servers, logs, optimization. I implemented an NFS server for home file sharing. I started synching my Phone Contacts with CardDav Server on Raspberry Pi. Thank you, RaspberryPi, for making a junior SysAdmin of me!

The LPI Certification


And then LPI came into play. I wanted to give more consistency to my CV through a worldwide acknowledged certification. That’s why I attended an LPI exam.

I signed up for preparation classes for LPIC-1. The classes were dramatically important to help me navigate through the topics and objectives of the exam.

I started to read the reference books, which contain the majority of exam objectives, and took notes from the most important parts, which I referred to on the next iteration of studying. The most significant insight I got during the studying phase, when I was involved in many important details, was the many gaps in my knowledge. Study made me aware of my weaknesses and lack of knowledge, which I wouldn’t have found out otherwise. The details matter, because they distinguish between a beginner and experienced system administrator. LPIC-1 made me involved in the details, and that is the most significant effect it had on my techie life.

Although the exam was tougher than I expected, I passed and I became an LPIC-1 certified professional.

Me, a DevOps, today


My approach to my career involves continuous learning. I implemented Zabbix monitoring for the company I was working in. The need for agile development and integration made me go in Docker and Jenkins direction. Nginx. SaltStack. And then microservices and Kubernetes.

I applied for LPIC-2 preparation classes, two years ago, in order to apply for more professional work positions. I want to dare: again, and more. It’s time to prove myself going for LPIC-2!

Source: lpi.org

Thursday, 13 August 2020

Linux mv command examples

Linux mv Command, Linux Study Material, Linux Exam Prep, Linux Tutorial and Material

The Linux mv command lets you move one or more files or directories. Since it's very similar to the cp command, I'll move through this post quickly.

Basic Linux mv examples


To rename a file currently named "foo" to a new file named "bar" just type:

mv foo bar

Although it's called the Linux mv command, it's commonly used to rename files.

To move a file named "foo" to the /tmp directory type:

mv foo /tmp

To move a file named "foo" to a new file named "bar" in the /tmp directory type:

mv foo /tmp/bar

Conversely, if the file "foo" is in the /tmp directory, and you want to move it to the current directory you'd type this:

mv /tmp/foo .

No matter where you are in the filesystem, if you want to move the same file to your home directory you can type this:

mv /tmp/foo ~

The ~ character is a shortcut character that refers to your home directory (and works with all shell commands, not just the mv command). To move the same file to a directory named "dir1" in your home directory you could type this:

mv /tmp/foo ~/dir1

More complicated mv examples


To move several files named "foo1", "foo2", and "foo3" into a directory named "dir1", use a mv command like this:

mv foo1 foo2 foo3 dir1

That's the long way to type it out. This command does this same thing:

mv foo[123] dir1

And if you don't have any other file beginning with the string "foo" you can just take this shortcut:

mv foo* dir1

How to move directories


Assuming that you have a directory named "dir1" that you want to rename to "dir2" you can use a command like this:

mv dir1 dir2

Don't clobber existing files


The mv command has several options to keep you from clobbering existing files during copy operations. The -i option prompts you before performing a move operation that would overwrite an existing file. Assuming that "bar" is a file that already exists, the interaction looks something like this:

/Users/al/yada> mv -i foo bar 
overwrite bar? (y/n [n]) n
not overwritten

In this example the system prompted me with the overwrite bar? (y/n) prompt, and I responded with n.

Instead of using -i you can use -n, which just doesn't allow this to happen at all. Unfortunately it doesn't give you any output, unless you also use the -v option, like this:

/Users/al/yada> mv -nv foo bar
bar not overwritten

mv aliases


Because of the potential danger of clobbering existing files a lot of people create an alias for the mv command, like this:

alias mv="mv -i"

As with the cp command I don't see any harm in doing this, and you can always undo it, so I highly recommend it.

Tuesday, 11 August 2020

Configure User Password Aging / Expiry Policy in Linux

In this post, you’ll learn to configure password aging and expiry policy for Linux users, as well as manually lock and unlock user accounts. The password aging and expiration features were implemented to ensure better security of user accounts.

Linux Study Materials, LPI Tutorial and Material, Linux Exam Prep, Linux Prep, Linux Tutorial and Material

How Password Verification works


When a user tries to log in, the system looks up the entry for the user in the /etc/shadow file, combines the salt for the user with the unencrypted password that was typed in, and encrypts them using the hashing algorithm specified. If the result matches the encrypted hash, the user typed in the right password. If the result does not match the encrypted hash, the user typed in the wrong password and the login attempt fails.

Read More: LPIC-OT 701: DevOps Tools Engineer

You’ll learn to:

◉ Force a password change on the first time login.
◉ Force a password change every X number of days.
◉ Set a user account to expire X days from the current day.

Before we get started, I’ll create a user account for this exercise.

sudo useradd user1
sudo passwd  user1

You’ll learn about other user operations with examples.

Exercise 1: Force a password change on the first login


To force a password change for the user on first login, use the command:

sudo chage -d 0 user1

If you log in as user1, you’ll be prompted to change the password.

$ ssh user1@localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
user1@localhost's password:
You are required to change your password immediately (administrator enforced)
Last login: Wed Feb 12 06:48:43 2020 from ::1
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user user1.
Current password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Connection to localhost closed.

You can now login with updated password.

ssh user1@localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
user1@localhost's password:
Last login: Wed Feb 12 06:48:53 2020 from ::1
[user1@localhost ~]$ exit
logout
Connection to localhost closed.

Exercise 2: Change the password policy for user


Let’s now set a password policy to require a new password every 90 days.

sudo chage -M 90 user1

Confirm that the password policy is successfully set.

$ sudo chage -l user1
Last password change : Feb 12, 2020
Password expires : May 12, 2020
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7

Exercise 3: Set user account to expire after X number of days


We’ll set the user1 account to expire 120 days from the current day.

Get the date and time 120 days from the current:

$ date -d "+120 days" +%F
2020-06-11

Now set the account to expire on the date displayed above.

sudo chage -E 2020-06-11 user1

Verify that the account expiry date is successfully set:

$ sudo chage -l user1
Last password change : Feb 12, 2020
Password expires : May 12, 2020
Password inactive : never
Account expires : Jun 11, 2020
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7

Exercise 4: Lock & Unlock user account


Locking the account prevents the user from authenticating with a password to the system. The usermod command can be used to lock an account with the -L option.

sudo usermod -L user1

Confirm:

$ su - user1
Password: 
su: Authentication failure

The account can later be unlocked with usermod -U command option.

sudo usermod -U user1

As a System administrator, you may lock and expire an account with a single usermod command. This is ideal for exited employees.

sudo usermod -L -e 2020-02-20 user1

The date must be given as the number of days since 1970-01-01, or in the YYYY-MM-DD format.

Exercise 5: Set password policy for all users


Set the password for all users to expire 90 days from the current date. Administrative rights are required to edit the file /etc/login.defs.

sudo vim /etc/login.defs

Set PASS_MAX_DAYS to 90.

PASS_MAX_DAYS   90

It should look like this:

Linux Study Materials, LPI Tutorial and Material, Linux Exam Prep, Linux Prep, Linux Tutorial and Material

All password aging parameters you can configure are:

◉ PASS_MAX_DAYS Maximum number of days a password may be used.
◉ PASS_MIN_DAYS Minimum number of days allowed between password changes.
◉ PASS_MIN_LEN Minimum acceptable password length.
◉ PASS_WARN_AGE Number of days warning given before a password expires.

When you edit the file /etc/login.defs, the default password and account expiry settings will be effective for new users but not for existing users.

Saturday, 8 August 2020

How To Create Hard and Soft (Symbolic) Links in Linux

LPI Exam Prep, LPI Tutorial and Materials, LPI Learning, LPI Certifications

How can I create Symbolic Links in Linux?. In this tutorial, you’ll learn how to make multiple file names reference the same file using hard links and symbolic, also called “soft” links. The two common ways of creating multiple names that point to the same file in Linux are:

◉ Creating a soft link (symbolic link) to the file
◉ Creating a hard link to the file.

Working with Soft link (Symbolic link)


A soft link is a special type of file that points to an existing file or directory. It can be used to link two files on different file systems. A soft link can point to a special file as well.

The ln -s command is used to create a soft link. Let’s consider an example:

In the following example, the ln -s command is used to create a new soft link for the existing file /tmp/file1.txt that will be named to /tmp/file2.txt:

$ echo "Hello from file1" > /tmp/file1.txt
$ ln -s /tmp/file1.txt /tmp/file2.txt

Confirm by listing the files:

$ ls -l /tmp/file1.txt /tmp/file2.txt
-rw-------. 1 jkmutai jkmutai 17 Feb  4 22:37 /tmp/file1.txt
lrwxrwxrwx. 1 jkmutai jkmutai 14 Feb  4 22:38 /tmp/file2.txt -> /tmp/file1.txt

You can see the first character of the long listing for /tmp/file2.txt is l instead of -. This indicates that the file is a soft link and not a regular file. (A d would indicate that the file is a directory.)

Check the contents of the symbolic link file.

$ cat /tmp/file2.txt
Hello from file1

For directory, use:

ln -s /dir /dir2

If you delete the original regular file, the soft link will still point to missing file – a “dangling soft link.”

Working with Hard Links


Every file in Linux starts with a single hard link. By creating a new hard link to a file, you are creating another name that points to that same data.

The new hard link acts exactly like the original file name. It is hard to tell the difference between the new hard link and the original name of the file. You use the ln command to create a hard link – Another name that points to an existing file.

$ echo "Hello World from Hard Link" >/tmp/hello1.txt
$ ln /tmp/hello1.txt  /tmp/hello2.txt

Where:

◉ /tmp/hello1.txt is a path to the existing file
◉ /tmp/hello2.txt is the hard link that you want to create.

Use the ls -i option to ls list the files’ inode number. If the inode numbers are the same, the files are hard links pointing to the same data.

$ ls -li /tmp/hello1.txt  /tmp/hello2.txt
2591191 -rw-------. 2 jkmutai jkmutai 27 Feb  5 08:16 /tmp/hello1.txt
2591191 -rw-------. 2 jkmutai jkmutai 27 Feb  5 08:16 /tmp/hello2.txt

--- Let's add third file and recheck ---
$ ln /tmp/hello1.txt  /tmp/hello3.txt
$ ls -li /tmp/hello1.txt  /tmp/hello2.txt /tmp/hello3.txt
2591191 -rw-------. 3 jkmutai jkmutai 27 Feb  5 08:16 /tmp/hello1.txt
2591191 -rw-------. 3 jkmutai jkmutai 27 Feb  5 08:16 /tmp/hello2.txt
2591191 -rw-------. 3 jkmutai jkmutai 27 Feb  5 08:16 /tmp/hello3.txt

All hard links referencing the same file have the same:

◉ link count
◉ access permissions
◉ user and group ownerships
◉ time stamps
◉ file content

Compare with ones for Soft link:

$ ls -li /tmp/file1.txt /tmp/file2.txt /tmp/file3.txt
2442008 -rw-------. 1 jkmutai jkmutai 17 Feb  4 22:37 /tmp/file1.txt
2442949 lrwxrwxrwx. 1 jkmutai jkmutai 14 Feb  4 22:38 /tmp/file2.txt -> /tmp/file1.txt
2601927 lrwxrwxrwx. 1 jkmutai jkmutai 14 Feb  5 08:24 /tmp/file3.txt -> /tmp/file1.txt

Key difference between Soft link and Hard link


◉ A hard link points a name to data on a storage device
◉ A soft link points a name to another name, that points to data on a storage device

Thursday, 6 August 2020

The .lpi command

.lpi command, LPI Tutorial and Materials, LPI Exam Prep, LPI Learning, LPI Prep

The .lpi command sets the number of lines per inch for output. If the printer does not support the specified number of lines per inch, this command has no affect.

Note: 

It may be necessary to change the term setting to get the required number of lines to print on a page.

Syntax


.lpi number.lines

Parameter(s)


number.lines - Specifies the number of lines per inch. The default is 6.

Learn More


Linux Professional


.lpi command, LPI Tutorial and Materials, LPI Exam Prep, LPI Learning, LPI Prep
Linux Professional Institute‘s Linux Professional Track is designed to evaluate the knowledge and skills of Linux systems administrators. To keep pace with evolving technology, the exam objectives are updated on average every three years and Linux Professional Institute certifications are valid for five years before you must recertify or certify at a higher level.

Linux Professional Institute LPIC-1 tests ability to perform maintenance tasks with the command line, install and configure a computer running Linux and be able to configure basic networking.

Prerequisites: There are no prerequisites for this certification.
Requirements: Passing the 101 and 102 exams. Each 90-minute exam is 60 multiple-choice and fill-in-the-blank questions.
Validity period: 5 years unless retaken or higher level is achieved.

101-500: Linux Administrator - 101 (LPIC-1 101)
102-500: Linux Administrator - 102 (LPIC-1 102)

Linux Professional Institute LPIC-2 tests ability to administer small to medium–sized mixed networks.

Prerequisites: An active LPIC-1 certification.
Requirements: Passing exams 201 and 202. Each 90-minute exam is 60 multiple-choice and fill-in-the-blank questions.
Validity period: 5​ years unless retaken or higher level is achieved.

201-450: Linux Engineer - 201 (LPIC-2 201)
202-450: Linux Engineer - 202 (LPIC-2 202)

Linux Professional Institute LPIC-3 Enterprise Mixed Environment tests ability to integrate Linux services in an enterprise-wide mixed environment.

Prerequisites: An active LPIC-2 certification.
Requirements: Passing the 300 exam. The 90-minute exam is 60 multiple-choice and fill-in-the-blank questions.
Validity period: 5 years

LPIC-3 300: Linux Enterprise Professional Mixed Environment

Linux Professional Institute LPIC-3 Enterprise Security tests ability to secure and harden Linux-based servers, services and networks enterprise-wide.

Prerequisites: An active LPIC-2 certification.
Requirements: Passing the 303 exam. The 90-minute exam is 60 multiple-choice and fill in the blank questions.
Validity period: 5 years

LPIC-3 303: Linux Enterprise Professional Security

Linux Professional Institute LPIC-3 Enterprise Virtualization and High Availability tests ability to plan and implement enterprise-wide virtualization and high availability setups using Linux-based technologies.

Prerequisites: An active LPIC-2 certification.
Requirements: Passing the 304 exam. The 90-minute exam is 60 multiple-choice and fill in the blank questions.
Validity period: 5 years

LPIC-3 304: Linux Enterprise Professional Virtualization and High Availability

Tuesday, 4 August 2020

Unix TimeStamp Command

Unix TimeStamp Command, LPI Tutorial and Material, LPI Certification, LPI Exam Prep

What is Unix Timestamp


Unix timestamp is the representation of time as the running total of number of seconds since the unix epoch time on January 1st, 1970. Simply the Unix timestamp is the number of seconds between the particular date and the Unix Epoch.

The unix timestamp become standard in computer systems for tracking the information especially in distributed processing system like hadoop, cloud computing etc.

Here we will see how to convert the unix date to timestamp and unix timestamp to date. We will also see how to generate the unix current timestamp. Let see each one:

1. Unix Current Timestamp


To find the unix current timestamp use the %s option in the date command. The %s option calculates unix timestamp by finding the number of seconds between the current date and unix epoch.

date '+%s'
1327312578

You will get a different output if you run the above date command.

2. Convert Unix Timestamp to Date


You can use the -d option to the date command for converting the unix timestamp to date. Here you have to specify the unix epoch and the timestamp in seconds.

date -d "1970-01-01 956684800 sec GMT"
Tue Apr 25 10:46:40 PDT 2000

3. Convert Unix Date to Timestamp


You have to combine the -d option and the %s option for converting the unix date to timestamp.

date -d "2000-01-01 GMT" '+%s'
946684800