Showing posts with label LPI LPIC-2 Primer. Show all posts
Showing posts with label LPI LPIC-2 Primer. Show all posts

Saturday, 20 February 2021

LPIC-2 Exams Can Now Be Taken Online

201-450 LPIC-2, 202-450 LPIC-2, LPIC-2 Certifications, LPI LPIC-2 Certification, LPI LPIC-2 Primer, LPIC-2 Linux Engineer, LPIC-2 Practice Test

For several months, the Linux Essentials and LPIC-1 exams from Linux Professional Institute (LPI) have been offered online through Pearson VUE’s online testing platform, OnVUE. We are proud to announce that the LPIC-2 exams, 201 and 202, are also now available. The online offerings address the latest global challenge caused by the COVID-19 pandemic, while also making tests available to candidates who live in remote areas without a nearby Pearson VUE test center.

What candidates should know

LPIC-2 exams are currently available in English. Participation in the OnVUE online tests is only possible with Windows or Macintosh computers. LPI has been in discussion with Pearson VUE to make exams available on Linux computers, because we know that many of our applicants prefer the system they have been studying and working with. We are also continuously working to expand the languages in which our exams are offered. Please return to this channel regularly to see our announcements in these areas.

Also Read:

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

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

Source: lpi.org

Sunday, 8 March 2020

LPI Exam 201 Prep: System maintenance

LPI Exam 201 Prep, LPIC-2 Exam Prep, LPIC-2 Learning

Prerequisites

To get the most from this tutorial, you should already have a basic knowledge of Linux and a working Linux system on which you can practice the commands covered in this tutorial.

System logging


About logging

Many processes and servers under a Linux system append changing status information to "log files." These log files often live in the /var/log/ directory and often begin with a time stamp indicating when the described event occurred. But for better or worse, there is no real consistency in the precise format of log files. The one feature you can pretty much count on is that Linux log files are plain ASCII files, and contain one "event" per line of the file. Often (but not always) log files contain a (relatively) consistent set of space- or tab-delimited data fields.

Some processes, especially Internet services, handle log file writes within their own process. At heart, writing to a log file is just an append to an open file handle. But many programs (especially daemons and cron'd jobs) use the standard syslog API to let the syslogd or klogd daemons handle the specific logging process.

Parsing log files

Exactly how you go about parsing a log file depends greatly on the specific format it takes. For log files with regular table format, tools like cut, split, head, and tail are likely to be useful. For all log files, grep is a great tool for finding and filtering contents of interest. For more complex processing tasks, you are likely to think of sed, awk, perl, or python as tools of choice.

For a good introduction to many of the text processing tools you are most likely to use in processing and analyzing log files, see David's IBM developerWorks tutorial on the GNU text processing utilities. A number of good higher-level tools also exist for working with log files, but these tools are usually distribution-specific and/or non-standard (but often Free Software) utilities.

Logging with syslogd and klogd

The daemon klogd intercepts and logs Linux kernel messages. As a rule, klogd will utilize the more general syslogd capabilities, but in special cases it may log messages directly to a file.

The general daemon syslogd provides logging for many programs. Every logged message contains at least a time and a hostname field and usually a program name field. The specific behavior of syslogd is controlled by the configuration file /etc/syslog.conf. Application (including kernel) messages may be logged to files, usually living under /var/log/ or remotely over a network socket.

Configuring /etc/syslog.conf

The file /etc/syslog.conf contains a set of rules, one per line. Empty lines and lines starting with a "#" are ignored. Each rule consists of two whitespace-separated fields, a selector field, and an action field. The selector, in turn, contains one of more dot-separated facility/priority pairs. A facility is a subsystem that wishes to log messages and can have the (case-insensitive) values: auth, authpriv, cron, daemon, ftp, kern, lpr, mail, mark, news, security, syslog, user, uucp, and local0 through local7.

Priorities have a specific order and matching a given priority means "this one or higher" unless an initial "=" (or "!=") is used. Priorities are, in ascending order: debug, info, notice, warning or warn, err or error, crit, alert, emerg or panic (several names have synonyms). none means that no priority is indicated.

Both facilities and priorities may accept the "*" wildcard. Multiple facilities may be comma-separated and multiple selectors may be semi-colon separated. For example:

# from /etc/syslog.conf
# all kernel mesages
kern.*                    -/var/log/kern.log
# `catch-all' logfile
*.=info;*.=notice;*.=warn;\
  auth,authpriv.none;\
  cron,daemon.none;\
  mail,news.none          -/var/log/messages
# Emergencies are sent to everybody logged in
*.emerg                   *

Configuring remote logging

To enable remote logging of syslogd messages (really application messages, but handled by syslogd), you must first enable the "syslog" service on both the listening and the sending machines. To do this, you need to add a line to each /etc/services configuration file containing something like:

syslog    514/UDP

To configure the local (sending) syslogd to send messages to a remote host, you specify a regular facility and priority but give an action beginning with an "@" symbol for the destination host. A host may be configured in the usual fashion, either /etc/hosts or via DNS (it need not be resolved already when syslogd first launches). For example:

# from /etc/syslog.conf
# log all critical messages to master.example.com
*.crit                @master.example.com
# log all mail messages except info level to mail.example.com
mail.*;mail.!=info    @mail.example.com

Rotating log files

Often you will not want to let particular log files grow unboundedly. The utility logrotate may be used to archive older logged information. Usually logrotate is run as a cron job, generally daily. logrotate allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or only when it grows too large.

The behavior of logrotate is controlled by the configuration file /etc/logrotate.conf (or some other file, if specified). The configuration file may contain both global options and file-specific options. Generally, archived logs are saved for a finite time period and are given sequential backup names. For example, one system of mine contains the following files due to its rotation schedule.

-rw-r-----  1 root adm 4135 2005-08-10 04:00 /var/log/syslog
-rw-r-----  1 root adm 6022 2005-08-09 07:36 /var/log/syslog.0
-rw-r-----  1 root adm  883 2005-08-08 07:35 /var/log/syslog.1.gz
-rw-r-----  1 root adm  931 2005-08-07 07:35 /var/log/syslog.2.gz
-rw-r-----  1 root adm  888 2005-08-06 07:35 /var/log/syslog.3.gz
-rw-r-----  1 root adm 9494 2005-08-05 07:35 /var/log/syslog.4.gz
-rw-r-----  1 root adm 8931 2005-08-04 07:35 /var/log/syslog.5.gz


Packaging software


In the beginning was the tarball

For custom software distribution on Linux, there is actually much less needed than you might think. Linux has a fairly clean standard about where files of various types should reside and installing custom software, at its heart, need not involve much more than putting the right files in the right places.

The Linux tool tar (for "tape archive," though it need not, and usually does not, utilize tapes) is perfectly adequate to create an archive of files with specified filesystem locations. For distribution, you generally want to compress a tar archive with gzip (or bzip2). See the final section of this tutorial on backup for more information on these utilities. A compressed tar archive is generally named with the extensions .tar.gz or .tgz (or .tar.bz2).

Early Linux distributions -- and some current ones like Slackware -- use simple tarballs as their distribution mechanism. For a custom distribution of in-house software to centrally maintained Linux systems, this continues to be the simplest approach.

Custom archive formats

Many programming languages and other tools come with custom distribution systems that are neutral between Linux distributions and usually between altogether different operating systems. Python has its distutils tools and archive format; Perl has CPAN archives; Java has .jar files; Ruby has gems. Many non-language applications have a standard system for distributing plug-ins or other enhancements to a base application as well.

While you can perfectly well use an package format like DEB or RPM to distribute a Python package for example, it often makes more sense to follow the packaging standard of the tool the package is created for. Of course, for system-level utilities and applications or for most compiled userland applications, that standard is the Linux distribution packaging standards. But for custom tools written in specific programming languages, something different might promote easier reuse of your tools across distributions and platforms (whether in-house or external users are the intended target).

The "big two" package formats

There are two main package formats used by Linux distributions: Redhat Package Manager (RPM) and Debian (DEB). Both are similar in purpose but different in details. In general, either one is a format for an "enhanced" archive of files. The enhancements provided by these package formats include annotations for version numbers, dependencies of one application upon other applications or libraries, human-readable descriptions of packaged tools, and a general mechanism for managing the installation, upgrade, and de-installation of packaged tools.

Under DEB files, the nested configuration file control contains most of the package metadata. For RPM files, the file spec plays this role. The full details of creating good packages in either format is beyond this tutorial, but we will outline the basics here.

What is in a .deb file?

A DEB package is created with the archive tool and cousin of tar, ar (or by some higher-level tool that utilizes ar). Therefore we can use ar to see just what is really inside a .deb file. Normally we would use higher-level tools like dpkg, dpkg-deb, or apt-get to actually work with a DEB package. For example:

% ar tv unzip_5.51-2ubuntu1.1_i386.deb
rw-r--r-- 0/0      4 Aug  1 07:23 2005 debian-binary
rw-r--r-- 0/0   1007 Aug  1 07:23 2005 control.tar.gz
rw-r--r-- 0/0 133475 Aug  1 07:23 2005 data.tar.gz

The file debian-binary simply contains the DEB version (currently 2.0). The tarball data.tar.gz contains the actually application files -- executables, documentation, manual pages, configuration files, and so on.

The tarball control.tar.gz is the most interesting from a packaging perspective. Let us look at the example DEB package we chose:

% tar tvfz control.tar.gz
drwxr-xr-x root/root         0 2005-08-01 07:23:43 ./
-rw-r--r-- root/root       970 2005-08-01 07:23:43 ./md5sums
-rw-r--r-- root/root       593 2005-08-01 07:23:43 ./control

As you might expect, md5sums contains cryptographic hashes of all the distributed files for verification purposes. The file control is where the metadata lives. In some cases you might also find or wish to include scripts called postinst and prerm in control.tar.gz to take special steps after installation or before removal, respectively.

Creating a DEB control file

The installation scripts can do anything a shell script might. (Look at some examples in existing packages to get an idea.) But those scripts are optional and often not needed or included. Required for a .deb package is its control file. The format of this file contains various metadata fields and is best illustrated by showing an example:

% cat control
Package: unzip
Version: 5.51-2ubuntu1.1
Section: utils
Priority: optional
Architecture: i386
Depends: libc6 (>= 2.3.2.ds1-4)
Suggests: zip
Conflicts: unzip-crypt (<< 5.41)
Replaces: unzip-crypt (<< 5.41)
Installed-Size: 308
Maintainer: Santiago Vila <sanvila@debian.org>
Description: De-archiver for .zip files
 InfoZIP's unzip program. With the exception of multi-volume archives
 (ie, .ZIP files that are split across several disks using PKZIP's /& option),
 this can handle any file produced either by PKZIP, or the corresponding
 InfoZIP zip program.
 .
 This version supports encryption.

Basically, except the custom data values, you should make your control file look just like this one. For non-CPU specific packages -- either scripts, pure documentation, or source code -- use Architecture: all.

Making a DEB package

Creating a DEB package is performed with the tool dpkg-deb. We cannot cover all the intricacies of good packaging, but the basic idea is to create a working directory, ./debian/, and put the necessary contents into it before running dpkg-deb. You will also want to set permissions on your files to match their intended state when installed. For example:

% mkdir -p ./debian/usr/bin/
% cp foo-util ./debian/usr/bin                # copy executable/script
% mkdir -p ./debian/usr/share/man/man1
% cp foo-util.1 ./debian/usr/share/man/man1   # copy the manpage
% gzip --best ./debian/usr/share/man/man1/foo-util.1
% find ./debian -type d | xarg chmod 755      # set dir permissions
% mkdir -p ./debian/DEBIAN
% cp control ./debian/DEBIAN   # first create a matching 'control'
% dpkg-deb --build debian      # create the archive
% mv debian.deb foo-util_1.3-1all.deb  # rename to final package name

More on DEB package creation

In the previous panel you can see that our local directory structure underneath ./debian/ is meant to match the intended installation structure. A few more points on creating a good package are worth observing.

◉ Generally you should create a file as part of your distribution called ./debian/usr/share/doc/foo-util/copyright (adjust for package name).

◉ It is also good practice to create the files ./debian/usr/share/doc/foo-util/changelog.gz and ./debian/usr/share/doc/foo-utils/changelog.Debian.gz.

◉ The tool lintian will check for questionable features in a DEB package. Not everything lintian complains about is strictly necessary to fix; but if you intend wider distribution, it is a good idea to fix all issues it raises.

◉ The tool fakeroot is helpful for packaging with the right owner. Usually a destination wants tools installed as root, not as the individual user who happened to generate the package (lintian will warn about this). You can accomplish this with:

% fakeroot dpkg-deb --build debian

What is in an .rpm file?

RPM takes a slightly different strategy than DEB does in creating packages. Its configuration file is called spec rather than control, but the spec file also does more work than a control file does. All the details of steps needed for pre-installation, post-installation, pre-removal, and installation itself, are contained as embedded script files in a spec configuration. In fact, the spec format even comes with macros for common actions.

Once you create an RPM package, you do so with the rpm -b utility. For example:

% rpm -ba foo-util-1.3.spec  # perform all build steps

This package build process does not rely on specific named directories as with DEB, but rather on directives in the more complex spec file.

Creating RPM metadata

The basic metadata in an RPM is much like that in a DEB. For example, foo-util-1.3.spec might contain something like:

# spec file for foo-util 1.3
Summary: A utility that fully foos
Name: foo-util
Version: 1.3
Release: 1
Copyright: GPL
Group: Application/Misc
Source: ftp://example.com/foo-util.tgz
URL: http://example.com/about-foo.html
Distribution: MyLinux
Vendor: Acme Systems
Packager: John Doe <jdoe@acme.example.com>

%description
The foo-util program is an advanced fooer that combines the
capabilities of OneTwo's foo-tool and those in the GPL bar-util.

Scripting in an RPM

Several sections of an RPM spec file may contain mini shell scripts. These include:

◉ %prep: Steps to perform to get the build ready such as clean out earlier (partial) builds. Often the following macro is helpful and sufficient:

%prep
%setup

◉ %build: Steps to actually build the tool. If you use the make facility, this might amount to:

%build
make

◉ %install: Steps to install the tool. Again, if you use make this might mean:

%install
make install

◉ %files: You must include a list of files that are part of the package. Even though your Makefile might use these files, the package manager program (rpm) will not know about them unless you include them here:

%files
%doc README
/usr/bin/foo-util
/usr/share/man/man1/foo-util.1


Backup operations


About backup

LPI Exam 201 Prep, LPIC-2 Exam Prep, LPIC-2 Learning, LPI Tutorial and Material
The first rule about making backups is: Do it! It is all too easy in server administration -- or even just with Linux on the desktop -- to neglect backing up on a schedule suited to your requirements.

The easiest way to carry out backups in a systematic and schedules way is to perform them on a cron job. See the Topic 213 tutorial for a discussion of configuring crontab. In part, the choice of backup schedule depends on the backup tool and media you choose to use.

Backup to tape is a traditional technique and tape drives continue to offer the largest capacity of relatively inexpensive media. But recently, writeable or rewriteable CDs and DVD have become ubiquitous and will often make reasonable removable media for backups.

What to back up

A nice thing about Linux is that it uses a predicable and hierarchical arrangement of files. As a consequence, you rarely need to backup an entire filesystem hierarchy; most of a Linux filesystem hierarchy can be reinstalled from distribution media easily enough. In large environments, a master server image might be used to create a basic Linux system which can be customized by restoring a few selected files that were backed up elsewhere.

Basically, what you want backed up is /home/, /etc/, /usr/local/, and maybe /root/ and /boot/. Often you will also want to backup some parts of /var/, such as /var/log/ and /var/mail/.

Backup with cp and scp

Perhaps the simplest way to perform a backup is with cp or scp and the -r (recurse) switch. The former copies to "local" media (but including NFS mounts), the latter can copy to remote servers in a securely encrypted fashion. For either, you need a mounted drive with sufficient space to accommodate the files you want to backup, of course. To gain any real hardware protection, you want the partition you copy to to be a different physical device than the drive(s) you are backing up from.

Copying with cp or scp can be part of an incremental backup schedule. The trick here is to use the utility find to figure out which files have been modified recently. Here is a simple example where we copy all the files in /home/ that have been modified in the lst day:

#!/bin/bash
# File: backup-daily.sh
# ++ Run this on a daily cron job ++
#-- first make sure the target directories exist
for d in `find /home -type d` ; do mkdir -p /mnt/backup$d ; done
#-- then copy all the recently modified files (one day)
for f in `find /home -mtime -1` ; do cp $f /mnt/backup$f  ; done

The cp -u flag is somewhat similar, but it depends on the continuity of the target filesystem between backup events. The find approach works fine if you change the mount point of /mnt/backup to a different NFS location. And the find system works equally well with scp once you specify the necessary login information to the remote site.

Backup with tar

Although cp and scp are workable for backup, generally tar sees wider use, being designed specifically for creating tape archives. Despite the origin of the name, tar is equally capable of creating a simple .tar file as raw data on a tape drive. For example, you might backup to a tape drive using a command like:

% tar -cvf /dev/rmt0 /home    # Archive /home to tape

To direct the output to a file is hardly any different:

% tar -cvf /mnt/backup/2005-08-12.tar /home

In fact, since gzip is streamable, you can easily compress an archive during creation:

% tar -cv /home | gzip - > /mnt/backup/2005-08-12.tgz

You can combine tar with find in the same ways shown for cp or scp. To list the files on a tape drive, you might use:

% tar -tvf /dev/rmt0

To retrieve a particular file:

% tar -xvf /dev/rmt0 file.name

Backup with cpio

The utility cpio is a superset of tar. It handles tar archives, but will also work with several other formats and has many more options built in. cpio comes with a huge wealth of switches to filter which files are backed up and even supports remote backup internally (rather than needing to pipe through scp or the like). The main advantage cpio has over tar is that you can both add files to archives and remove files back out.

Here are some quick examples of cpio:

◉ Create a file archive on a tape device: % find /home -print |cpio -ocBv /dev/rmt0.
◉ List the entries in a file archive on a tape device: % cpio -itcvB < /dev/rmt0.
◉ Retrieve a file from a tape drive: % cpio -icvdBum file.name < /dev/rmt0.

Backup with dump and restore

A set of tools named dump and restore (or with related names) are sometimes used to backup whole filesystems. Unfortunately, these tools are specific to filesystem types and are not uniformly available. For example, the original dump and restore are ext2/3-specific while the tools xfsdump and xfsrestore are used for XFS filesystems. Not every filesystem type has the equivalent tools and even if they do, switches are not necessarily uniform.

It is good to be aware of these utilities, but they are not very uniform across Linux systems. For some purposes -- like if you only use XFS partitions -- the performance of dump and restore can be a great boost over a simple tar or cpio.

Incremental backup with rsync

rsync is utility that provides fast incremental file transfer. For automated remote backups, rsync is often the best tool for the job. A nice feature of rsync over other tools is that it can optionally enforce two-way synchronization. That is, rather than simply backing up newer or changed files, it can also automatically remove locally deleted files from the remote backup.

To get a sense of the options, this moderately complex script (located at the rsync Web pages) is useful to look at:

#!/bin/sh
# This script does personal backups to a rsync backup server. You will
# end up with a 7 day rotating incremental backup. The incrementals will
# go into subdirs named after the day of the week, and the current
# full backup goes into a directory called "current"
# tridge@linuxcare.com
# directory to backup
BDIR=/home/$USER
# excludes file - this contains a wildcard pats of files to exclude
EXCLUDES=$HOME/cron/excludes
# the name of the backup machine
BSERVER=owl
# your password on the backup server
export RSYNC_PASSWORD=XXXXXX
BACKUPDIR=`date +%A`
OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES
  --delete --backup --backup-dir=/$BACKUPDIR -a"
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# the following line clears the last weeks incremental directory
[ -d $HOME/emptydir ] || mkdir $HOME/emptydir
rsync --delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
rmdir $HOME/emptydir
# now the actual transfer
rsync $OPTS $BDIR $BSERVER::$USER/current

Thursday, 5 March 2020

LPI Exam 201 Prep: System Customization and Automation

LPI Exam 201 Prep, LPI Study Materials, LPI Exam Prep, LPI Guides, LPI Learning

Prerequisites

To get the most from this tutorial, you should have a basic knowledge of Linux and a working Linux system on which you can practice the commands covered in this tutorial.

Automating periodic tasks


Configuring cron

The daemon cron is used to run commands periodically. You can use cron for a wide variety of scheduled system housekeeping and administration tasks. If there's an event or task that needs to regularly occur, it should be controlled by cron. Cron wakes up every minute to check whether it needs to do anything, but it cannot perform tasks more than once per minute. (If you need to do that, you probably want a daemon, not a "cron job.") Cron logs its action to the syslog facility.

Cron searches several places for configuration files that indicate environment settings and commands to run. The first is in /etc/crontab, which contains system tasks. The /etc/cron.d/ directory can contain multiple configuration files that are treated as supplements to /etc/crontab. Special packages can add files (matching the package name) to /etc/cron.d/, but system administrators should use /etc/crontab.

User-level cron configurations are stored in /var/spool/cron/crontabs/$USER. However, these should always be configured using the crontab tool. Using crontab, users can schedule their own recurrent tasks.

Scheduling daily, weekly, and monthly jobs

Jobs that should run on a simple daily, weekly, or monthly schedule -- which are the most commonly used schedules -- follow a special convention. Directories called /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly/ are created to include collections of scripts to run on those respective schedules. Adding or removing scripts from these directories is a simple way to schedule system tasks. For example, a system I maintain rotates its logs daily with a script file using:

Listing 1. Sample daily script file

$ cat /etc/cron.daily/logrotate
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

Cron and anacron

You can use anacron to execute commands periodically with a frequency specified in days. Unlike cron, anacron checks whether each job has been executed in the last n days (where n is the period specified for that job, as opposed to whether the current time matches the scheduled execution). If not, anacron runs the job's command after waiting for the number of minutes specified as the delay parameter. Therefore, on machines that are not running continuously, periodic jobs are executed once the machine is actually running (obviously, the exact timing can vary, but the task will not be forgotten).

Anacron reads a list of jobs from the configuration file /etc/anacrontab. Each job entry specifies a period in days, a delay in minutes, a unique job identifier, and a shell command. For example, on one Linux system I maintain, anacron is used to run daily, weekly, and monthly jobs even if the machine is not running at the scheduled time of day:

Listing 2. Sample anacron configuration file

$ cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# These replace cron's entries
1         5  cron.daily    nice run-parts --report /etc/cron.daily
7        10  cron.weekly   nice run-parts --report /etc/cron.weekly
@monthly 15  cron.monthly  nice run-parts --report /etc/cron.monthly

The contents of a crontab

The format of /etc/crontab (or the contents of /etc/cron.d/ files) is slightly different from that of user crontab files. Basically, this just amounts to an extra field in /etc/crontab that indicates the user a command runs as. This is not needed for user crontab files since they are already stored in a file matching username (/var/spool/cron/crontabs/$USER).

Each line of /etc/crontab either sets an environment variable or configures a recurring job. Comment and blank lines are ignored. For cron jobs, the first five fields specify times to run (where each zero-based field may have a list and/or a range). The fields are minute, hour, day of month, month, day of week (space- or tab-separated). An asterisk (*) in any position indicates any. For example, to run a task at midnight on Tuesdays and Thursdays during August through October, you could use:

# line in /etc/crontab
0 0 * 7-9 2,5 root /usr/local/bin/the-task -opt1 -opt2

Using special scheduling values

Some common scheduling patterns have shortcut names you can use in place of the first five fields:

@reboot
Run once, at startup.

@yearly
Run once a year, "0 0 1 1 *".

@annually
Same as @yearly.

@monthly
Run once a month, "0 0 1 * *".

@weekly
Run once a week, "0 0 * * 0".

@daily
Run once a day, "0 0 * * *".

@midnight
Same as @daily.

@hourly
Run once an hour, "0 * * * *".

For example, you could have a configuration containing:

@hourly root /usr/local/bin/hourly-task
0,29 * * * * root /usr/local/bin/twice-hourly-task

Using crontab

To set up a user-level scheduled task, use the crontab command (as opposed to the /etc/crontab file). Specifically, crontab -e launches an editor to modify a file. You can list current jobs with crontab -l and remove the file with crontab -r. Or you can specify crontab -u user to schedule tasks for a given user, but the default is to do so for yourself (permission limits apply).

The /etc/cron.allow file, if present, must contain the names of all users allowed to schedule jobs. Alternately, if there is no /etc/cron.allow, then a user must not be in the /etc/cron.deny file if allowed to schedule tasks. If neither file exists, everyone can use crontab.

Automating one-time tasks


Using the at command

If you need to schedule a task to run in the future, you can use the at command, which takes a command from STDIN or from a file (using the -f option), and accepts time descriptions in a flexible collection of formats.

A family of commands is used in association with the at command: atq lists pending tasks; atrm removes a task from the pending queue; and batch works much like at, except it defers running a job until the system load is low.

Permissions

Similar to /etc/cron.allow and /etc/cron.deny, the at command has /etc/at.allow and /etc/at.deny files to configure permissions. The /etc/at.allow file, if present, must contain all users allowed to schedule jobs. Alternately, if there is no /etc/at.allow, then a user must not be in /etc/at.deny if allowed to schedule tasks. If neither file exists, everyone may use at.

Time specifications

See the manpage on your at version for full details. You can specify a particular time as HH:MM, which schedules an event to happen when that time next occurs. (If the time has already passed today, it means tomorrow.) If you use 12-hour time, you can also add a.m. or p.m. You can give a date as MMDDYY, MM/DD/YY, DD.MM.YY, or month-name-day. You can also increment from the current time with now + N units, in which N is a number and units are minutes, hours, days, or weeks. The words today and tomorrow keep their obvious meaning, as do midnight and noon (teatime is 4 p.m.). Some examples:

% at -f ./foo.sh 10am Jul 31 % echo 'bar -opt' | at 1:30 tomorrow

The exact definition of the time specification is in /usr/share/doc/at/timespec.

Tips for scripts


Outside resources

Many excellent books are available on awk, Perl, bash, and Python. The coauthor of this tutorial (naturally) recommends his own title, Text Processing in Python, as a good starting point for scripting in Python.

Most scripts you write for system administration focus on text manipulation such as extracting values from logs and configuration files and generating reports and summaries. It also means cleaning up system cruft and sending notifications of tasks performed.

The most common scripts in Linux system administration are written in bash. bash itself has relatively few built-in capabilities, but bash makes it particularly easy to utilize external tools (including basic file utilities such as ls, find, rm, and cd) and text tools (like those found in the GNU text utilities).

Bash tips

One particularly helpful setting to include in bash scripts that run on a schedule is the set -x switch, which echoes the commands run to STDERR. This is helpful in debugging scripts when they don't produce the desired effect. Another useful option during testing is set -n, which causes a script to look for syntax problems, but not actually to run. Obviously, you don't want a -n version scheduled in cron or at, but to get it up and running, it can help.

Listing 3. Sample cron job that runs a bash script

#!/bin/bash
exec 2>/tmp/my_stderr
set -x
# functional commands here

This redirects STDERR to a file and outputs the commands run to STDERR. Examining that file later can be useful.

The manpage for bash is good, though quite long. You may find all the options that the built-in set can accept particularly interesting.

A common task in a system administration script is to process a collection of files, often with the files of interest identified using the find command. However, a problem can arise when file names contain white space or newline characters. Much of the looping and processing of file names you are likely to do can be confused by these internal white space characters. For example, these two commands are different:

% rm foo bar baz bam
% rm 'foo bar' 'baz bam'

The first command unlinks four files (assuming they exist to start with); the second removes just two files, each with an internal space in the name. File names with spaces are particularly common in multimedia content.

Fortunately, the GNU version of the find command has a -print0 option to NULL terminate each result; and the xargs command has a corresponding -0 command to treat arguments as NULL separated. Putting these together, you can clean up stray files that might contain white space in their names using:

Listing 4. Cleaning up file names with spaces

#!/bin/bash
# Cleanup some old files
set -x
find /home/dqm \( -name '*.core' -o -name '#*' \) -print0 \
 | xargs -0 rm -f

Perl taint mode

Perl has a handy switch -T to enable taint mode. In this mode, Perl takes a variety of extra security precautions, but primarily it limits execution of commands arising from external input. If you use sudo execution, taint mode might be enabled automatically, but the safest thing is to start your administration scripts with:

#!/usr/local/bin/perl -T

Once you do this, all command line arguments, environment variables, locale information (see perllocale), results of certain system calls (readdir(), readlink(), the variable of shmread(), the messages returned by msgrcv(), the password, gcos and shell fields returned by the getpwxxx() calls), and all file inputs are marked as "tainted." Tainted data cannot be used directly or indirectly in any command that invokes a sub-shell nor in any command that modifies files, directories, or processes, with a few exceptions.

It's possible to untaint particular external values by carefully checking them for expected patterns:

Listing 5. Untainting external values

if ($data =~ /^([-\@\w.]+)$/) {
   $data = $1;                     # $data now untainted
} else {
   die "Bad data in $data";      # log this somewhere
}

Perl CPAN packages

One of the handy things about Perl is that it comes with a convenient mechanism for installing extra support packages; it's called Comprehensive Perl Archive Network (CPAN). RubyGems is similar in function. Python, unfortunately, does not yet have an automated installation mechanism, but it comes with more in the default installation. Simpler languages like bash and awk do not really have many add-ons to install in an analogous sense.

The manpage on the cpan command is a good place to get started, especially if you have a task to perform for which you think someone might have done most of the work already. Look for candidate modules at CPAN.

cpan has both an interactive shell and a command-line operation. Once configured (run the interactive shell once to be prompted for configuration options), cpan handles dependencies and download locations in an automated manner. For example, suppose you discover you have a system administration task that involves processing configuration files in YAML (yaml Ain't Markup Language) format. Installing support for YAML is as simple as:

% cpan -i YAML # maybe with 'sudo' first

Once installed, your scripts can contain use YAML; at the top. This goes for any capabilities for which someone has created a package.

Saturday, 10 August 2019

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

LPI Certification, LPIC-2 Linux Engineer, 201-450 LPIC-2, 201-450 Online Test, 201-450 Questions, 201-450 Quiz, 201-450, LPIC-2 Certification Mock Test, LPI LPIC-2 Certification, LPIC-2 Practice Test, LPI LPIC-2 Primer, LPIC-2 Study Guide, LPI 201-450 Question Bank, LPIC-2 201, LPIC-2 201 Simulator, LPIC-2 201 Mock Exam, LPI LPIC-2 201 Questions, LPI LPIC-2 201 Practice Test

LPIC-2 is the second certification in LPI’s multi-level professional certification program. The LPIC-2 will validate the candidate's ability to administer small to medium–sized mixed networks. The candidate must have an active LPIC-1 certification to receive LPIC-2 certification, but the LPIC-1 and LPIC-2 exams may be taken in any order.

Current Version: 4.5 (Exam codes 201-450 and 202-450)

Objectives: 201-450, 202-450

Prerequisites: The candidate must have an active LPIC-1 certification to receive LPIC-2 certification, but the LPIC-1 and LPIC-2 exams may be taken in any order

Requirements: Passing exams 201 and 202

Validity Period: 5 years

Languages: English, German, Japanese


To become LPIC-2 certified the candidate must be able to:

◈ perform advanced system administration, including common tasks regarding the Linux kernel, system startup and maintenance;
◈ perform advanced Management of block storage and file systems as well as advanced networking and authentication and system security, including firewall and VPN;
◈ install and configure fundamental network services, including DHCP, DNS,  SSH, Web servers, file servers using FTP, NFS and Samba, email delivery; and
◈ supervise assistants and advise management on automation and purchases.

LPI Certification, LPIC-2 Linux Engineer, 201-450 LPIC-2, 201-450 Online Test, 201-450 Questions, 201-450 Quiz, 201-450, LPIC-2 Certification Mock Test, LPI LPIC-2 Certification, LPIC-2 Practice Test, LPI LPIC-2 Primer, LPIC-2 Study Guide, LPI 201-450 Question Bank, LPIC-2 201, LPIC-2 201 Simulator, LPIC-2 201 Mock Exam, LPI LPIC-2 201 Questions, LPI LPIC-2 201 Practice Test

LPIC-2 Exam 202


Exam Objectives Version: 4.5 (Exam code 202-450).

About Objective Weights: Each objective is assigned a weighting value. The weights indicate the relative importance of each objective on the exam. Objectives with higher weights will be covered in the exam with more questions.

Topic 207: Domain Name Server


207.1 Basic DNS server configuration

Weight: 3

Description: Candidates should be able to configure BIND to function as a caching-only DNS server. This objective includes the ability to manage a running server and configuring logging.

Key Knowledge Areas:

◈ BIND 9.x configuration files, terms and utilities
◈ Defining the location of the BIND zone files in BIND configuration files
◈ Reloading modified configuration and zone files
◈ Awareness of dnsmasq, djbdns and PowerDNS as alternate name servers

The following is a partial list of the used files, terms and utilities:

◈ /etc/named.conf
◈ /var/named/
◈ /usr/sbin/rndc
◈ kill
◈ host
◈ dig

207.2 Create and maintain DNS zones

Weight: 3

Description: Candidates should be able to create a zone file for a forward or reverse zone and hints for root level servers. This objective includes setting appropriate values for records, adding hosts in zones and adding zones to the DNS. A candidate should also be able to delegate zones to another DNS server.

Key Knowledge Areas:

◈ BIND 9 configuration files, terms and utilities
◈ Utilities to request information from the DNS server
◈ Layout, content and file location of the BIND zone files
◈ Various methods to add a new host in the zone files, including reverse zones

Terms and Utilities:

◈ /var/named/
◈ zone file syntax
◈ resource record formats
◈ named-checkzone
◈ named-compilezone
◈ masterfile-format
◈ dig
◈ nslookup
◈ host

207.3 Securing a DNS server

Weight: 2

Description: Candidates should be able to configure a DNS server to run as a non-root user and run in a chroot jail. This objective includes secure exchange of data between DNS servers.

Key Knowledge Areas:

◈ BIND 9 configuration files
◈ Configuring BIND to run in a chroot jail
◈ Split configuration of BIND using the forwarders statement
◈ Configuring and using transaction signatures (TSIG)
◈ Awareness of DNSSEC and basic tools
◈ Awareness of DANE and related records

Terms and Utilities:

◈ /etc/named.conf
◈ /etc/passwd
◈ DNSSEC
◈ dnssec-keygen
◈ dnssec-signzone

Topic 208: Web Services


208.1 Implementing a web server

Weight: 4

Description: Candidates should be able to install and configure a web server. This objective includes monitoring the server’s load and performance, restricting client user access, configuring support for scripting languages as modules and setting up client user authentication. Also included is configuring server options to restrict usage of resources. Candidates should be able to configure a web server to use virtual hosts and customize file access.

Key Knowledge Areas:

◈ Apache 2.4 configuration files, terms and utilities
◈ Apache log files configuration and content
◈ Access restriction methods and files
◈ mod_perl and PHP configuration
◈ Client user authentication files and utilities
◈ Configuration of maximum requests, minimum and maximum servers and clients
◈ Apache 2.4 virtual host implementation (with and without dedicated IP addresses)
◈ Using redirect statements in Apache’s configuration files to customize file access

Terms and Utilities:

◈ access logs and error logs
◈ .htaccess
◈ httpd.conf
◈ mod_auth_basic, mod_authz_host and mod_access_compat
◈ htpasswd
◈ AuthUserFile, AuthGroupFile
◈ apachectl, apache2ctl
◈ httpd, apache2

208.2 Apache configuration for HTTPS

Weight: 3

Description: Candidates should be able to configure a web server to provide HTTPS.

Key Knowledge Areas:

◈ SSL configuration files, tools and utilities
◈ Generate a server private key and CSR for a commercial CA
◈ Generate a self-signed Certificate
◈ Install the key and certificate, including intermediate CAs
◈ Configure Virtual Hosting using SNI
◈ Awareness of the issues with Virtual Hosting and use of SSL
◈ Security issues in SSL use, disable insecure protocols and ciphers

Terms and Utilities:

◈ Apache2 configuration files
◈ /etc/ssl/, /etc/pki/
◈ openssl, CA.pl
◈ SSLEngine, SSLCertificateKeyFile, SSLCertificateFile
◈ SSLCACertificateFile, SSLCACertificatePath
◈ SSLProtocol, SSLCipherSuite, ServerTokens, ServerSignature, TraceEnable

208.3 Implementing a proxy server

Weight: 2

Description: Candidates should be able to install and configure a proxy server, including access policies, authentication and resource usage.

Key Knowledge Areas:

◈ Squid 3.x configuration files, terms and utilities
◈ Access restriction methods
◈ Client user authentication methods
◈ Layout and content of ACL in the Squid configuration files

Terms and Utilities:

◈ squid.conf
◈ acl
◈ http_access

208.4 Implementing Nginx as a web server and a reverse proxy

Weight: 2

Description: Candidates should be able to install and configure a reverse proxy server, Nginx. Basic configuration of Nginx as a HTTP server is included.

Key Knowledge Areas:

◈ Nginx
◈ Reverse Proxy
◈ Basic Web Server

Terms and Utilities:

◈ /etc/nginx/
◈ nginx

Topic 209: File Sharing


209.1 SAMBA Server Configuration

Weight: 5

Description: Candidates should be able to set up a Samba server for various clients. This objective includes setting up Samba as a standalone server as well as integrating Samba as a member in an Active Directory. Furthermore, the configuration of simple CIFS and printer shares is covered. Also covered is a configuring a Linux client to use a Samba server. Troubleshooting installations is also tested.

Key Knowledge Areas:

◈ Samba 4 documentation
◈ Samba 4 configuration files
◈ Samba 4 tools and utilities and daemons
◈ Mounting CIFS shares on Linux
◈ Mapping Windows user names to Linux user names
◈ User-Level, Share-Level and AD security

Terms and Utilities:

◈ smbd, nmbd, winbindd
◈ smbcontrol, smbstatus, testparm, smbpasswd, nmblookup
◈ samba-tool
◈ net
◈ smbclient
◈ mount.cifs
◈ /etc/samba/
◈ /var/log/samba/

209.2 NFS Server Configuration

Weight: 3

Description: Candidates should be able to export filesystems using NFS. This objective includes access restrictions, mounting an NFS filesystem on a client and securing NFS.

Key Knowledge Areas:

◈ NFS version 3 configuration files
◈ NFS tools and utilities
◈ Access restrictions to certain hosts and/or subnets
◈ Mount options on server and client
◈ TCP Wrappers
◈ Awareness of NFSv4

Terms and Utilities:

◈ /etc/exports
◈ exportfs
◈ showmount
◈ nfsstat
◈ /proc/mounts
◈ /etc/fstab
◈ rpcinfo
◈ mountd
◈ portmapper

Topic 210: Network Client Management


210.1 DHCP configuration

Weight: 2

Description: Candidates should be able to configure a DHCP server. This objective includes setting default and per client options, adding static hosts and BOOTP hosts. Also included is configuring a DHCP relay agent and maintaining the DHCP server.

Key Knowledge Areas:

◈ DHCP configuration files, terms and utilities
◈ Subnet and dynamically-allocated range setup
◈ Awareness of DHCPv6 and IPv6 Router Advertisements

Terms and Utilities:

◈ dhcpd.conf
◈ dhcpd.leases
◈ DHCP Log messages in syslog or systemd journal
◈ arp
◈ dhcpd
◈ radvd
◈ radvd.conf

210.2 PAM authentication

Weight: 3

Description: The candidate should be able to configure PAM to support authentication using various available methods. This includes basic SSSD functionality.

Key Knowledge Areas:

◈ PAM configuration files, terms and utilities
◈ passwd and shadow passwords
◈ Use sssd for LDAP authentication

Terms and Utilities:

◈ /etc/pam.d/
◈ pam.conf
◈ nsswitch.conf
◈ pam_unix, pam_cracklib, pam_limits, pam_listfile, pam_sss
◈ sssd.conf

210.3 LDAP client usage

Weight: 2

Description: Candidates should be able to perform queries and updates to an LDAP server. Also included is importing and adding items, as well as adding and managing users.

Key Knowledge Areas:

◈ LDAP utilities for data management and queries
◈ Change user passwords
◈ Querying the LDAP directory

Terms and Utilities:

◈ ldapsearch
◈ ldappasswd
◈ ldapadd
◈ ldapdelete

210.4 Configuring an OpenLDAP server

Weight: 4

Description: Candidates should be able to configure a basic OpenLDAP server including knowledge of LDIF format and essential access controls.

Key Knowledge Areas:

◈ OpenLDAP
◈ Directory based configuration
◈ Access Control
◈ Distinguished Names
◈ Changetype Operations
◈ Schemas and Whitepages
◈ Directories
◈ Object IDs, Attributes and Classes

Terms and Utilities:

◈ slapd
◈ slapd-config
◈ LDIF
◈ slapadd
◈ slapcat
◈ slapindex
◈ /var/lib/ldap/
◈ loglevel

Topic 211: E-Mail Services


211.1 Using e-mail servers

Weight: 4

Description: Candidates should be able to manage an e-mail server, including the configuration of e-mail aliases, e-mail quotas and virtual e-mail domains. This objective includes configuring internal e-mail relays and monitoring e-mail servers.

Key Knowledge Areas:

◈ Configuration files for postfix
◈ Basic TLS configuration for postfix
◈ Basic knowledge of the SMTP protocol
◈ Awareness of sendmail and exim

Terms and Utilities:

◈ Configuration files and commands for postfix
◈ /etc/postfix/
◈ /var/spool/postfix/
◈ sendmail emulation layer commands
◈ /etc/aliases
◈ mail-related logs in /var/log/

211.2 Managing E-Mail Delivery

Weight: 2

Description: Candidates should be able to implement client e-mail management software to filter, sort and monitor incoming user e-mail.

Key Knowledge Areas:

◈ Understanding of Sieve functionality, syntax and operators
◈ Use Sieve to filter and sort mail with respect to sender, recipient(s), headers and size
◈ Awareness of procmail

Terms and Utilities:

◈ Conditions and comparison operators
◈ keep, fileinto, redirect, reject, discard, stop
◈ Dovecot vacation extension

211.3 Managing Remote E-Mail Delivery

Weight: 2

Description: Candidates should be able to install and configure POP and IMAP daemons.

Key Knowledge Areas:

◈ Dovecot IMAP and POP3 configuration and administration
◈ Basic TLS configuration for Dovecot
◈ Awareness of Courier

Terms and Utilities:

◈ /etc/dovecot/
◈ dovecot.conf
◈ doveconf
◈ doveadm

Topic 212: System Security


212.1 Configuring a router

Weight: 3

Description: Candidates should be able to configure a system to forward IP packet and perform network address translation (NAT, IP masquerading) and state its significance in protecting a network. This objective includes configuring port redirection, managing filter rules and averting attacks.

Key Knowledge Areas:

◈ iptables and ip6tables configuration files, tools and utilities
◈ Tools, commands and utilities to manage routing tables.
◈ Private address ranges (IPv4) and Unique Local Addresses as well as Link Local Addresses (IPv6)
◈ Port redirection and IP forwarding
◈ List and write filtering and rules that accept or block IP packets based on source or destination protocol, port and address
◈ Save and reload filtering configurations

Terms and Utilities:

◈ /proc/sys/net/ipv4/
◈ /proc/sys/net/ipv6/
◈ /etc/services
◈ iptables
◈ ip6tables

212.2 Securing FTP servers

Weight: 2

Description: Candidates should be able to configure an FTP server for anonymous downloads and uploads. This objective includes precautions to be taken if anonymous uploads are permitted and configuring user access.

Key Knowledge Areas:

◈ Configuration files, tools and utilities for Pure-FTPd and vsftpd
◈ Awareness of ProFTPd
◈ Understanding of passive vs. active FTP connections

Terms and Utilities:

◈ vsftpd.conf
◈ important Pure-FTPd command line options

212.3 Secure shell (SSH)

Weight: 4

Description: Candidates should be able to configure and secure an SSH daemon. This objective includes managing keys and configuring SSH for users. Candidates should also be able to forward an application protocol over SSH and manage the SSH login.

Key Knowledge Areas:

◈ OpenSSH configuration files, tools and utilities
◈ Login restrictions for the superuser and the normal users
◈ Managing and using server and client keys to login with and without password
◈ Usage of multiple connections from multiple hosts to guard against loss of connection to remote host following configuration changes

Terms and Utilities:

◈ ssh
◈ sshd
◈ /etc/ssh/sshd_config
◈ /etc/ssh/
◈ Private and public key files
◈ PermitRootLogin, PubKeyAuthentication, AllowUsers, PasswordAuthentication, Protocol

212.4 Security tasks

Weight: 3

Description: Candidates should be able to receive security alerts from various sources, install, configure and run intrusion detection systems and apply security patches and bugfixes.

Key Knowledge Areas:

◈ ​Tools and utilities to scan and test ports on a server
◈ Locations and organizations that report security alerts as Bugtraq, CERT or other sources
◈ Tools and utilities to implement an intrusion detection system (IDS)
◈ Awareness of OpenVAS and Snort

Terms and Utilities:

◈ telnet
◈ nmap
◈ fail2ban
◈ nc
◈ iptables

212.5 OpenVPN

Weight: 2

Description: Candidates should be able to configure a VPN (Virtual Private Network) and create secure point-to-point or site-to-site connections.

Key Knowledge Areas:

◈ OpenVPN

Terms and Utilities:

◈ /etc/openvpn/
◈ openvpn