Press "Enter" to skip to content

Tux’s Favorite Recipes: Enticing Snippets from the New ‘Linux Cookbook, 2nd Edition’

The recipes that Carla Shroder shares here only begin to scratch the surface of what’s to be found in the Second Edition of her classic guide to Linux. If it was up to us, however, we would have called it “The Joy of Linux”, after our favorite all-purpose cookbook.

Linux Cookbook Second Edition cover

In Why I Wrote the Linux Cookbook, 2nd Edition, I discussed how much Linux has changed in a short time, and how I updated the Linux Cookbook to include some of these changes. Now I will share some snippets from the new book, so you can get a taste of how fabulous it is, and inspire you to dash out and buy many copies.

Or not, at any rate let the snippets commence.

Resetting a Windows Password with SystemRescue

I adore SystemRescue, the excellent bootable rescue Linux designed for rescuing damaged systems. You can use most any live Linux for rescue operations, but I like SystemRescue for its default bundle of useful applications, and it is light on CPU and memory.

19.10 Resetting a Windows Password


You lost your Windows password, and you don’t want to jump through the usual Windows hoops to reset it.


No worries, for SystemRescue will have you back in action in a jiffy. Boot up SystemRescue on your Windows machine, then mount your Windows system directory:

# mkdir /mnt/windows
# mount /dev/sda2

Navigate to the /mnt/windows/Windows/System32/config directory, then use the chntpw (change NT password) command to list users:

# cd /mnt/windows/Windows/System32/config
# chntpw -l SAM

chntpw version 1.00 140201, (c) Petter N Hagen
Hive name (from header): <\SystemRoot\System32\Config\SAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c
File size 65536 [10000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 318/31864 blocks/bytes, unused: 29/12968 blocks/bytes.

RID Username Admin? Lock?
01f4 Administrator ADMIN Lock?
03e9 duchess ADMIN
01f7 DefaultAccount dis/lock
01f5 Guest dis/lock
01f8 WDAGUtilityAccount dis/lock

Examine the information on the user you want to change:

# chntpw -u Administrator SAM
chntpw version 1.00 140201, (c) Petter N Hagen
Hive name (from header): <\SystemRoot\System32\Config\SAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c
File size 65536 [10000] bytes, containing 9 pages (+ 1 headerpage)
Used for data: 321/33816 blocks/bytes, unused: 34/27336 blocks/bytes.

================= USER EDIT ====================

RID : 0500 [01f4]
Username: Administrator
comment : Built-in account for administering the computer/domain
homedir :

00000220 = Administrators (which has 2 members)

Account bits: 0x0210 =

[ ] Disabled [ ] Homedir req. [ ] Passwd not req.
[ ] Temp. duplicate [X] Normal account [ ] NMS account
[ ] Domain trust ac [ ] Wks trust act. [ ] Srv trust act
[X] Pwd don’t expir [ ] Auto lockout [ ] (unknown 0x08)
[ ] (unknown 0x10) [ ] (unknown 0x20) [ ] (unknown 0x40)

Failed login count: 0, while max tries is: 0
Total login count: 5

– – – – User Edit Menu:
1 – Clear (blank) user password
2 – Unlock and enable user account [probably locked now]
3 – Promote user (make user an administrator)
4 – Add user to a group
5 – Remove user from a group
q – Quit editing user, back to user select
Select: [q] ^

Enter 1 to remove the existing password:

Select: [q] ^ 1
Password cleared!

Press q to quit, and y to “write hive files,” which saves your changes.

Now the Administrator, or whatever user you selected, must log in and set a new password.


You cannot create a new password or recover the old one with chntpw, but only delete it. Then you log in without a password and create a new password, or, if your user is present, let them do it.

See Also

man 8 chntpw

Are You Using systemd or Not?

I like systemd, but some users still prefer the old SysV init. The excellent MX Linux provides both, and you choose the init you want to use at boot time. This recipe tells how to find out if your system is running systemd.

4.1 Learning if Your Linux Uses systemd


You need to know if your Linux distribution uses systemd or something else.


Look for the /run/systemd/system/ directory. If this exists, then your init system is systemd.


The /run/systemd/ directory may be present on your system if your distribution supports multiple init systems. But systemd is not the active init unless you see /run/systemd/system/.

There are several other ways to learn which init system your system is using. Try querying /sbin/init. Originally this was the SysV executable, and now most Linux distributions preserve the name and symlink it to the systemd executable. This example confirms that the init is systemd:

$ stat /sbin/init
File: /sbin/init -> /lib/systemd/systemd

On a system using SysV init, it has no symlink:

$ stat /sbin/init
File: /sbin/init

The /proc pseudo-filesystem is an interface to your Linux kernel, and contains the current state of a running system. It is called a pseudo-filesystem because it exists only in memory and not on disk. In this example, /proc/1/exe is symlinked to the systemd executable:

$ sudo stat /proc/1/exe
File: /proc/1/exe -> /lib/systemd/systemd

On a SysV system, it links to init:

$ sudo stat /proc/1/exe
File: /proc/1/exe -> /sbin/init

The /proc/1/comm file reports your active init system:

$ cat /proc/1/comm

On a SysV system, it reports init:

$ cat /proc/1/comm

The command attached to process ID (PID) 1 is your init. PID 1 is the first process launched at startup, which then starts all other processes. You can see this with the ps command:

$ ps -p 1
1 ? 00:00:00 systemd

When the init is SysV, it looks like this:

$ ps -p 1
1 ?               00:00:00 init

See Recipe 4.2 for more information on PID 1.

Linux support for systemd varies. Most of the major Linux distributions have adoped systemd, including Fedora, Red Hat, CentOS, openSUSE, SUSE Linux Enterprise, Debian, Ubuntu, Linux Mint, Arch, Manjaro, Elementary, and Mageia Linux.

Some popular distributions that do not support systemd, or include it but not as the default init, are Slackware, PCLinuxOS, Gentoo Linux, MX Linux, and antiX.

See Also

Distrowatch for information on hundreds of Linux distributions

man 5 proc

man 1 pstree

man 1 ps

The Best Way to Save a Web Page

Let’s do one more. Did you know you can save files from any source, even web pages, by using your CUPS printer dialogue to export them to PDF?

15.10 Saving Documents by Printing to a PDF File


You want to save a web page, or any document, to a PDF file instead of sending it to a printer.


Look at the File → Print dialog in any application, and you will see an option to print to a PDF file (Figure 15-14).

select printer screen in Linux
Figure 15-14. Printing to a PDF file (from Linux Cookbook).

You have all the usual options, such as filename and location, margins, print quality, color or monochrome, and page orientation. The printer dialogs look different in different apps; for example, the Firefox web browser printer dialog includes a document preview. In other apps the preview is usually a separate button.


Print to file is great for saving web confirmation forms and receipts, and creating PDFs from any type of documents.

See Also

CUPS documentation

Thank you for reading, buy early! Buy often! Available at O’Reilly, Amazon, Powell’s, and practically everywhere else fine books are sold.

Breaking News: