Linux Magazine Special Editions - 101 Cool Linux Hacks 2020 US
Linux Magazine Special Editions - 101 Cool Linux Hacks 2020 US
This Linux Magazine special edition promises you “101 Linux hacks,” and we’ll
certainly deliver – check the table of contents on the following page for a list
of all the gems we present inside. But what exactly is a “hack”?
In today’s world where Windows is the dominant desktop operating system,
the decision to use Linux is the first and most important hack. In addition
to that:
Q If I can use it to solve a problem or get some work done faster than
before, then it’s a hack.
Q If the way it works is unexpected, it’s very certainly a hack.
Q If it teaches me a new and interesting way to use my Linux machine,
it’s a hack.
Q When it makes me grin, because it’s so obvious that only a geeky
Unix person would ever think of doing things this way, I add it to my
list of anecdotes (and yes, it’s a hack).
The definition of a hack is a matter of taste, and so is our choice of hacks
for this collection: Many authors have contributed, and together we have
assembled a mix of new tools, new configuration options for old tools, and
new ways to use familiar software. We’ve organized our hacks into
10 categories so that you’ll find them quickly when you go
back to search for them.
We call the final category “Having Fun,” because we
hope that, in addition to profiting from these clever
new hacks, you’ll also enjoy yourself while you
browse this issue.
Hans-Georg Eßer
Editor-in-Chief
Keep It Running Q
26
HACK 19 Clone It with Clonezilla 27 HACK 25 Repair the Debian Package Database 34
HACK 20 Write ISOs to USB Sticks 28 HACK 26 Learn the vi Editor Basics 36
HACK 21 Get a Quick Machine Configuration Overview 29 HACK 27 Follow File Updates 37
with inxi HACK 28 Monitor Your System in a Terminal 37
HACK 22 Repair Your Bootloader 30 HACK 29 Visualize ddrescue’s Progress 38
HACK 23 Clean House with Stacer 32 HACK 30 Run dmesg with the Right Options 38
HACK 24 Reset Your Debian-Based Distribution 33 HACK 31 Where Did You Mount That Disk? 39
Shell Hacks Q
58
HACK 53 Configure Your Shell History 59 HACK 60 Command References at cheat.sh 64
HACK 54 Progress Bars for Standard Tools 60 HACK 61 Highlighting Instead of Grepping 65
HACK 55 Replace top with htop 60 HACK 62 Add File Type Icons to Your File Listing 66
HACK 56 Super-Fast Terminal Emulator 61 HACK 63 Upterm, a Terminal with 67
HACK 57 Universal Unpacker 61 Built-In Shell
HACK 58 List Files with Style 62 HACK 64 The fish Shell 67
HACK 59 ASCII Browsing with Browsh 63 HACK 65 Use a Sub-Shell 68
HACK 66 Start the Right App 68
Publish or Perish Q
70
HACK 67 Install the draw.io Diagram Editor Locally 71
HACK 68 Record Screencasts with Peek 72
HACK 69 Edit Your Videos with VidCutter 73
HACK 70 Create Long Documents with Styles 73 Deep Hacks Q
77
HACK 71 Edit HTML with Live Preview in Brackets 74
HACK 72 Free Wildcard X.509 Certificates for Your Domain 75 HACK 75 Safely Power Off Your Machine 78
HACK 73 Test Alternative CMSs with Docker 76 HACK 76 Make Files Immutable or Append-Only 79
HACK 74 How Fast Is Your Server? 76 HACK 77 Mount .tar.gz and .zip Archives 79
HACK 78 Recover Deleted Files with PhotoRec 80
and TestDisk
HACK 79 Change Root into Second Distro 81
HACK 80 Bind Mount a Directory with New Permissions 81
HACK 81 Run Binaries from a Different Linux Installation 82
HACK 82 Don’t Be So Case-Sensitive 83
Having Fun Q
92
Curing the
Caps Lock Disease
HACK 1 Figure 2
H AC K
Latte Dock: The Best Dock for KDE 2
One of the best things about KDE – and there are Figure 3
many – is the functionality contained within the panel.
It works well horizontally stretched across the entire
display or as a small panel across half. It works well
vertically, as well as floating in the middle. You can
have more than one, and each one can be configured
to do as much or as little as you want. But the default
KDE panel can still feel a little utilitarian, partly be-
cause it’s nothing like the panel in macOS. This is why
there are perhaps so many panel replacements that
look more like Apple’s similar dock.
Latte Dock is the best alternative I’ve seen for KDE
(Figure 3). Unlike most panel replacements, it has got a
comprehensive set of configuration options that mimic
much of what KDE’s regular panel does. By default, it
will appear in the middle of your screen’s bottom bor-
der when your pointer gets close. The icons for running
applications appear and enlarge as you roll over these
in beautifully animated transitions. The same happens
when you open the configuration panel, which allows
you to change the location of the panel and its align-
ment. You can place it anywhere and get the icons to
center exactly as you wish. You can also control the
transitions and zoom levels, as well as enable or dis- To try it, install the package via sudo zypper in
able the panel background and running application latte-dock (openSUSE) or sudo apt install latte-dock
highlight modes. On a high DPI desktop, it looks abso- (Ubuntu, Mint, and Debian). Then run the latte-dock
lutely fantastic. The SVG icons scale perfectly, and re- command.
placing the old KDE panel with this is a serious tempta-
tion, despite it not fully supporting functional applets By Graham Morrison
https://store.kde.org/p/1169519/
like monitoring tools or desktop pagers.
and the traditional ./flif --help for the list of options, such Lepton has a very simple syntax, and while you can
as interlacing, palette, quality, and more. Keep in mind that enjoy many of its advanced features, you can start with
FLIF currently can convert only PNG, PAM, and PNM file this template:
formats, so it makes sense to compare FLIF outputs with
$ lepton input.jpg output.lep
PNG as the most widespread format from the above list. In
our tests, lossless FLIF output was smaller than PNG with If your JPEG file uses progressive encoding (Gimp does it
the highest compression ratio and comparable with JPEG by default when exporting to JPEG), you’ll need the appro-
in terms of file size (Figure 6). The only problem is that you priate extra option:
cannot view .flf files, so right now you can only use the
$ lepton -allowprogressive input.jpg output.lep
Figure 6
To restore (decompress) your file, use the same command but
switch the .lep and .jpg order. Lepton is quite effective: It can
trim down your files by 15-20 percent without losing quality.
The reason why you might want to use FLIF, Lepton, or both
is precisely one. The volume of images that have to be stored
is growing faster and faster. Converting some thousands
JPEGs to the new Lepton format lets you free extra disk
space. Lepton files are about 20 percent smaller than their
source JPEGs, so the savings can be be very noticeable.
By Alexander Tolstoy
https://flif.info/
http://flif.info/UGUI_FLIF/
https://blogs.dropbox.com/tech/2016/07/
https://github.com/dropbox/lepton
H AC K
Zoom Everything on Your Screen
Many applications let you zoom the content they dis-
Fix KDE
KDE, like Gnome, needs some
6
play; for example, in Firefox and LibreOffice, you can extra work so you can zoom smoothly. You will need
press the Ctrl key and move the mouse wheel to in- the xbindkeys tool and also dbus-send or qdbus (which
crease or decrease the zoom level. should be preinstalled with KDE).
But sometimes you may need a different kind of Try the following commands:
zooming. Imagine for example that you show a Libre-
qdbus org.kde.kglobalaccel /component/kwin U
Office Impress presentation to your audience, and
invokeShortcut view_zoom_in
there’s a detail you want to draw attention to on your
dbus-send --type=method_call --dest=U
slide. You’ll have to leave presentation mode and
org.kde.kglobalaccel /component/kwin U
zoom into the slide in Impress’ editing mode, which is
org.kde.kglobalaccel.Component.invokeShortcut U
not really professional. Luckily, it is possible to zoom
string:view_zoom_in
the whole desktop. Depending on your desktop envi-
ronment, you may have to activate the feature. If one of them zooms a tiny bit into the desktop,
you’re ready for the next step – on my openSUSE test
Cinnamon Can Do It, Gnome Almost machine only the second command worked. If none
If you use Cinnamon, open Preferences | Accessibility of them works, try to enable the zoom effect as ex-
and click on Enable zoom. Then change the Mouse plained in the “KDE: Enable the Zoom” box.
tracking mode to Cursor pushes contents around: First of all, zoom out again: Just repeat the com-
That way mouse movements will not change what mand that worked, but replace view_zoom_in with view_
you see on the screen – until you reach the borders. zoom_out. Then create (or open) the file .xbindkeysrc in
The default key, called Super, is the Win key next to your home directory and add the following four lines:
Left Alt. So keep Win pressed and use the scroll wheel
to zoom into your desktop and out again. "<WORKING COMMAND ENDING IN view_zoom_in>"
Gnome has a preconfigured zoom feature; it is alt + b:4
one of the accessibility functions. Press Win+Alt+8 "<WORKING COMMAND ENDING IN view_zoom_out>"
to enable zooming, then Win+Alt+= to zoom in, alt + b:5
and Win+Alt+- to zoom out. However, you cannot
configure it to change the zoom in small steps, and The first line contains the command for zooming in,
you cannot use the mouse. If you want that to hap- placed between double quotation marks; the third line
pen, check the hack on the next page – it is more is the same but ends in view_zoom_out. Lines 2 and 4
advanced. hold the mouse/key combinations: alt is the Alt key (it
will work with both the left and
KDE: Enable the Zoom right Alt keys); b:4 and b:5 are
Scroll Up and Scroll Down on
the mouse wheel. (If you want a
If zooming does not work at all or if you the zoom is active and you try to move
want to fine-tune how much KDE the mouse out of the visible area, KDE more complicated combination,
zooms in/out with one wheel move, scrolls so that the mouse pointer stays try control + alt + b:4, for exam-
open KDE’s System Settings and go to visible. But try the other options, too: ple; the xbindkeysrc man page ex-
Workspace | Desktop Behavior. Then It’s a matter of taste. plains how to use the
click on Desktop Effects. Figure 7 other modifier keys.)
Make sure that Zoom Now start xbindkeys (if
(Magnify the entire desk-
you already use it, kill it
top) is activated and click
on the settings icon. first) and check whether
zooming with Alt and
In the new dialog win-
dow (Figure 7), change the mouse wheel works.
the Zoom Factor value If so, make things per-
to something between manent by adding
1.01 and 1.20. My sug- xbindkeys to your auto-
gestion for the Mouse start programs.
Tracking option is to set
it to Push: then, when By Hans-Georg Eßer
#!/bin/bash Figure 8
[ -r ~/.local/zoom-config ] && source ~/.local/zoom-config
ZOOM_MIN=${ZOOM_MIN:-1.00}
ZOOM_ADJUST=${ZOOM_ADJUST:-0.01}
SCHEMA=org.gnome.desktop.a11y.magnifier
zoom=$(gsettings get $SCHEMA mag-factor)
check=$(echo "$zoom > $ZOOM_MIN" | bc -l)
if [[ $check -eq 1 ]]; then
zoom=$(echo "scale=2; $zoom - $ZOOM_ADJUST" | bc -l)
gsettings set $SCHEMA mag-factor $zoom
zoom=$(gsettings get $SCHEMA mag-factor)
fi
H AC K
Use Virtual Desktops, Memorize the Hotkeys
Do you work with virtual desktops? If not, try them. As- also the right place if you want to add
8
suming that you do more with your Linux machine than more desktops. Add the Workspace Switcher
run a browser, a mail client, and LibreOffice, it is likely applet to your panel so that you can switch the desktop
that your desktop becomes cluttered with windows. with a single click.
Maybe you minimize some of them to get the chaos If you would prefer to use Ctrl+F1, Ctrl+F2, etc. on Cin-
under control. Connecting one or two extra monitors namon, open Preferences | Keyboard from the menu,
would improve the situation, but that requires free switch to the Shortcuts tab, and pick the Workspaces |
space on your desk (and money). Direct Navigation category: You can now define your
Instead of physical, go for virtual. Linux desktop envi- own hotkeys that will let you switch to a desktop directly.
ronments like KDE, Gnome, and most others have a
feature called virtual desktop. You can have two or Gnome
more independent areas where you can place your win- With a Gnome installation, Ctrl+Alt+Down (or
dows. There’s no need to minimize them; just spread Win+PageDown) will bring you to a fresh, new desktop
them out on as many desktops as you need. – but only, after you’ve opened at least one window on
the current desktop. With Ctrl+Alt+Up (or Win+PageUp)
KDE you can go back to the previous desktop.
On KDE, press Ctrl+F2 to reach a second (empty) desk- By default, Gnome only has a hotkey for switching to
top; Ctrl+F1 brings you back to the original one. If that the first desktop (Win+Home), but when you open the
doesn’t work, virtual desktops are disabled. Open the settings and go to Devices | Keyboard, you can add hot-
start menu, type virtual, and select the Virtual Desktop keys for further desktops. Ctrl+F1 is not available be-
configuration entry. Then set the Number of desktops cause some Gnome applications use it to show the
to some value that makes sense: I like to have eight of shortcuts available in that program.
them (Figure 9). KDE automatically creates more hot- In all desktop environments, each window’s menu
keys (Ctrl+F3, Ctrl+F4, etc.). will let you move a window to a different workspace,
and there may even be hotkeys for doing that without
Figure 9 the mouse. The developers have come up with multiple
ways to configure your desktop’s behavior (e.g., some
program may always open on the second desktop).
It takes some time to get used to multiple desktops,
but once you know the most important hotkeys by
heart, you’ll do many things faster than before.
If you tend to switch between KDE, Gnome, and other
environments or window managers often, it might
make sense to change the settings so that working with
virtual desktops feels the same in every environment –
but if you’ve already chosen your favorite desktop, sim-
ply get to know its default hotkeys: They are likely to
stay the same for future releases.
By Hans-Georg Eßer
Cinnamon
If you run Cinnamon, press Ctrl+Alt+Right to move to
the next desktop. Cinnamon calls them “workspaces,”
but the concept is the same. Press Ctrl+Alt+Up to view
a summary of all desktop contents (Figure 10). This is
Caffeine
Helps Your
HACK 9 H AC K
Linux PC Stay
Awake
What Would That
Resolution Look Like?
There’s a command-line tool called
10
Sometimes you don’t want your computer to start xrandr that can work magic in configuring your desk-
the screensaver (and possibly lock you out) or acti- top. You may already be aware of its capability of
vate some energy-saving mode and suspend. For ex- changing the resolution via a command similar to
ample, I used to get very annoyed when I brought my
notebook to a classroom and stepped away to ex- xrandr --output DP-1 --mode 2560x1440
plain something on the blackboard – only to find a
few minutes later that the beamer no longer showed and even defining completely new resolutions using
my presentation slides. For me, that’s a problem of a modeline (which you’ll have to create with a tool
the past, because I use Caffeine. There are several like cvt or an online modeline generator).
tools with that name (including ones for macOS and But xrandr can do more. A not so well-known trick
Windows); pick the right one for your desktop! is using a scaling factor to make the desktop bigger
If you work with KDE or Cinnamon, you can install (in pixels) than the maximum resolution offered by
the caffeine package (do not confuse this with Kaf- your monitor. Try the following command:
feine, a KDE media player). Then run caffeine-indica-
tor (if you like it, add it to your auto-start applica- xrandr --output DP-1 --scale 1.5x1.5
tions). This will add a new coffee cup icon to your
panel. Clicking it opens a context menu from which (replace DP-1 with your monitor’s ID). If you see no ef-
you can select Activate (or Deactivate). When Caf- fect, use a number closer to 1.0. On my test machine, I
feine is active, you can see steam rising from the cup could not move beyond 1.7x1.7, but even with that
(Figure 11). scaling factor, I saw an incredible 4352x2448 resolu-
As a Gnome user, visit the Gnome Shell Extensions tion. Of course, the monitor could not display so many
website, search for Caffeine, and enable the exten- pixels, but internally the X server did render an image
sion – this will work best if you have installed the of that size and then created a smaller version for the
chrome-gnome-shell package and the Gnome Shell inte- monitor. I made a screenshot (Figure 12) to check:
gration plugin for Firefox. Using this is even simpler:
Just click it to toggle on/off. $ file megares.png
megares.png: PNG image data, 4352 x 2448, U
Figure 11 8-bit/color RGB, non-interlaced
If you enable zooming, you can even work with the high
resolution and still make the window contents visible.
By Hans-Georg Eßer
https://wiki.archlinux.org/index.php/Xrandr
https://arachnoid.com/modelines/
One last hint: Don’t try an online search for
“Cinnamon+Caffeine” – I did that, and it was com-
pletely useless: Google gave me coffee recipes and Figure 12
health-related articles.
By Hans-Georg Eßer
https://launchpad.net/caffeine
https://extensions.gnome.org/
https://www.zhornsoftware.co.uk/caffeine/
http://lightheadsw.com/caffeine/
HACK 11
Find Your Files with DocFetcher 17
HACK 12
Organize Your Ideas with Zim, the Desktop Wiki 18
HACK 13
Track Time with Chrono 20
HACK 14
Launch Programs Inside a VirtualBox VM 20
HACK 15
Create a Cheap Timer with sleep 22
HACK 16
Finding and Installing Online Fonts 23
HACK 17
Sync Up Your Phone and Linux Desktop 23
HACK 18
Self-Organization with GTG 24
H AC K
Find Your Files with DocFetcher 11
I like empty partitions: When I install a new Linux distri- the program, you need Figure 1
bution on a test machine and log in for the first time, I not care about complex
sometimes take a look at the empty Documents folder java command-line op-
and think: How beautiful! Let’s put two or three files in tions, just launch the
that folder and enjoy the clarity. DocFetcher-GTK3.sh script
On my real computers, things are different. The fol- to start the program.
lowing code was run on a notebook that holds only DocFetcher can index
some of my files: all sorts of files (Figure 1),
including PDF, LibreOf-
[esser@m2:~]$ for dir in Data Documents; do printf \ fice, and Microsoft Office
"%-9s: %5d files in %5d folders, " \ files (both classic and
"$dir" \ XML-based). It will also
$(find $dir -type f | wc -l) \ look at ID3 tags embed-
$(find $dir -type d | wc -l); \ ded in MP3 files, so you
du -sh $dir | cut -f1; done can later search for MP3
Data : 96477 files in 10818 folders, 58G songs by title or album
Documents: 1499 files in 335 folders, 14G name even if these meta-
data do not appear in the
(If you like what this command does, put it in a shell filenames. Normally,
script.) Creating or collecting thousands of files means DocFetcher uses the file
trouble when you need to find one of them. Linux gives extensions (like .odt,
you a few built-in options for searching, so you might .docx, etc.) to decide what
want to start with them. kind of file format it is looking at, but you can enable a
By cleverly combining shell commands such as Detect mime type option if you tend to store files with
• ls -lR (recursive listing) non-standard or without file extensions.
• grep (filter search terms) Once you’ve built the index, you can start your
• find (search for files with specific properties) searches. Results will show up in a table, and when you
• locate (use a pre-built database to search) select a particular result, DocFetcher gives you a preview
you can already do a lot. locate is especially helpful, be- (Figure 2). Depending on the file type, it is possible to
cause it gives you instant replies, whereas running find take a look at all search hits in a document: Imagine a
can take many minutes if you throw it at a large folder big PDF file that frequently contains your keyword.
hierarchy. It’s likely that you have to install locate first,
typically from the mlocate package, and you need to By Hans-Georg Eßer
regularly run a file database updater called updatedb. http://docfetcher.sourceforge.net/
Figure 3
the your wiki’s structure first. For each project (say, a lines using the Tab key. Zim continues these lists until
book project, a collection of links, or a to-do list), you you insert a blank line.
will first want to create a separate notebook to provide If you enable the tasklist plugin, you can expand on
an easy means for distinguishing the content. this function. Supplement the bullet by typing, say
A look at the Format menu clarifies the formatting
[] Task 1 12-23-2019 !
that you can apply to the currently selected text via the
toolbar or the usual keyboard shortcuts. If you do not to include a due date and a priority (each additional ex-
select a text passage explicitly, Zim formats the word clamation mark decreases the priority), and then dis-
under the cursor. In addition to the usual markup fea- play all of the project’s tasks by pressing the Task List
tures (such as bold, italics, underline, and striketh- button in the toolbar.
rough), you will find five levels of headings, and you Internal links to other pages of the notebook you are
can also highlight words or text passages in yellow. currently editing, or to another notebook, mean that Zim
Highlight source code by means of a fixed-width font also has a powerful organizational function. You can ei-
to set it apart from the remaining text. Charts, lists, and ther press Ctrl+L to create a reference to a nonexistent
enumerations complete the picture. If you use the right page (Zim then creates the page automatically) or link to
plugin, you can also embed calculations in Zim and an existing page. The link appears in blue in the text. Al-
represent formulas. The same applies to Gnuplot ternatively, you can create links without dialogs or short-
graphics and images. You can also use an arbitrary cuts using CamelCase or WikiWord notation. For exam-
image editor while working within Zim; launch the ple, entering LinuxMagazine automatically generates a
image editor via an image’s context menu and save the link of the same name and the appropriate page due to
results in Zim. The original image is not changed. the uppercase M. Since this feature can lead to un-
The Toggle notebook editable pen icon in the toolbar wanted links, you have the option of switching off Cam-
lets you enable write protection for the entire notebook. elCase linking through the configuration settings.
In the calendar, clicking on the icon labeled Today in the Zim automatically converts paths such as /etc/de-
active notebook generates the structure of a journal fault into links; clicking on one of these links takes you
with sub-items for the year, month, and day that you to the appropriate directory or opens the associated
can use as a diary. file. Local files can be saved as file attachments using
While you are working, Zim continuously stores the Tools | Attach. Zim assigns the attachments to the arti-
current state. Finished documents can then be exported cle and moves them to the new instance if you copy or
as HTML, LaTeX, or Markdown. The tab bar below the move the original. If you copy the wiki to a second com-
toolbar, which grows to accommodate the increasing puter, the attachments remain in place.
number of projects, shows the state of editing and can- The data is stored in text format with wiki markup,
not be deleted during the session. thus opening up numerous possibilities. For example,
you can use a makefile to generate a website from the
Lists, Links, and Annexes wiki entries. Thanks to the text format with wiki
If you start a line with an asterisk (*) or square brack- markup, you can use the stored information on all three
ets ([]), Zim automatically switches to a mode in supported operating system platforms. The flexible
which it is very easy to create bullet lists or checklists methods for linking let you build rich documents that
(Figure 5). To add a little more structure, indent the you either use as a preliminary stage for processing in
other applications or finalize in Zim.
Figure 5 Zim is easily accessible, revealing the power of its op-
tions only when needed. Once you have discovered the
versatility of Zim, you will not want to be without this
desktop wiki, which has been in development since
2005. Even Linux beginners who are familiar with Mi-
crosoft OneNote are likely to quickly find their way
around Zim.
Zim impresses as a complete package, and if you like
the organizational structure of wikis, you are bound to
feel right at home.
By Ferdinand Thommes
http://www.zim-wiki.org
https://en.wikipedia.org/wiki/WikidPad
https://github.com/jaap-karssenberg/zim-wiki/wiki/Plugins
https://en.wikipedia.org/wiki/Camel_case
By Graham Morrison
https://github.com/gochrono/chrono
H AC K
Launch Programs Inside a VirtualBox VM
If the Guest Additions are installed in a VirtualBox The parameters are always at
14
guest, you can start programs directly on the guest the end following the two minus signs. In the example,
with VBoxManage. The following command logs into gedit/arg0 indicates that the parameters for the gedit
the virtual machine (VM) named “Fedora 29” as the program follow next. Here, this is just the complete
user tim and a password of 123456: path to the text file that you want gedit to open.
The guestcontrol command gives an insight into the
VBoxManage guestcontrol "Fedora 29" start --exe U
state of the guest system if required:
"/usr/bin/gedit" --username tim --password 123456 U
--putenv "DISPLAY=:0"
VBoxManage guestcontrol "Windows 10" list all
When it gets there, it launches the gedit text editor. The
--exe option is followed by the full path to the program Among other things, guestcontrol also lists the current
you wish to execute. In the case of a Windows VM, you processes. If a process is hanging, you can kill it with
need to enter the backslashes in the path twice, such as closeprocess:
--exe "C:\\ Windows\\System32\\calc.exe". For a graphical
X11 application to launch on a Linux guest, you need to VBoxManage guestcontrol "Fedora 29" closeprocess U
set the DISPLAY environment variable using the --putenv --session-id 4 2022
parameter. You can also add further parameters to the
program: Via --session-id, you provide the ID of the session in
which the process is running. The number at the end
VBoxManage guestcontrol "Fedora 29" start --exe U
represents the troublemaker’s process ID.
"/usr/bin/gedit" --username tim --password 123456 U
--putenv "DISPLAY=:0" -- gedit/arg0 /home/tim/brief.txt By Tim Schürmann
By Hans-Georg Eßer
Figure 7
HACK
Finding and
16 Sync Up Your HACK 17
Installing Online Phone and Linux
Fonts Desktop
Fonts aren’t something most users spend too much KDE Connect is a utility I fell in love with at first sight.
time contemplating. Most distributions include a You install an app on your Android device and an-
good selection, with even some, such as Ubuntu, other on your Linux desktop, and your phone and
bundling their own fonts designed specifically for computer become part of the same computing envi-
clarity and design aesthetics. But if you spend a lot of ronment. Phone notifications appear on the desktop,
time with code or words, you’ll know that the right desktop notifications on your phone, your music
font doesn’t simply look good; it also helps ease eye player stops playing when you get a call, and you can
strain and aid clarity. For those reasons, spending a browse your phone’s filesystem from the desktop file
little time trying out a few more options than those manager (Figure 9).
provided by your desktop makes sense. There’s even a command-line interface and key-
KDE has a great font-browsing tool that will let board and touchpad emulation from your phone.
you preview fonts, as well as install them either lo- While these initially sound like gimmicks, they’ve ac-
cally or globally with a single click – and you can tually saved me serious hassle when mouse batteries
even do this from Dolphin’s right-click menu when have failed – on more than one occasion! The KDE
more than one font is selected. But there isn’t al- team have done a great job of implementing this in
ways an easy way of browsing fonts you may poten- such a way that actually works and is useful.
tially want to install. Font Finder (Figure 8) could be Since the early versions of KDE Connect, there has
the solution; it acts as a kind of application store for been a constant stream of updates with new features,
the free fonts hosted on Google’s font archive. It’s and there’s now even a version that decouples itself
also a lovely GTK3 application, with a sleek minimal from the majority of KDE Plasma bindings that make
interface. There’s a category browser, so you can it work so well with KDE. The developers are working
easily search for monospace, for instance, and a on a version that uses Bluetooth rather than a com-
search field that lets you filter fonts according to mon network connection for those times you need
your criteria. Results are delivered in the main view, KDE Connect synergy without wanting to connect to
but critically, the results are previews of the fonts a network.
themselves, which is exactly what you need. You You need not run a KDE desktop to use KDE Con-
can change the size of the fonts and even render nect: For example, there is also Nautilus support.
them onto a dark background. It’s a brilliant way for Gnome users can also try the alternative GSConnect
looking through fonts you may wish to install. When tool, which reimplements KDE Connect for Gnome.
you decide to install one, simply click on Install.
By Graham Morrison
By Graham Morrison
https://community.kde.org/KDEConnect
https://github.com/mmstick/fontfinder https://extensions.gnome.org/extension/1319/gsconnect/
Figure 8 Figure 9
H AC K
Self-Organization with GTG
18
Getting Things Gnome implements the Getting Things tasks for easy searching by category and record notes
Done (GTD) approach, which is so close to this catego- describing the state of the task.
ry’s name that we have to discuss it. GTD is a self-orga-
nization method developed by David Allen. It is based Creating Tasks
on the theory that trying to maintain a complex task list GTG focuses on the tasks, which the program displays
in your head takes a toll on concentration. The idea is to in the main window. You can create a new task by click-
move task tracking out of the mind and put it in the ing on the New Task button or using the keyboard short-
hands of a trusted external system. The system tracks cut Ctrl+N. A new dialog appears. In this example, I want
the tasks, so the user can focus on solving and com- to save a yoga class offer for a later date. In the first line
pleting the problems. of the new dialog, the title of the task, Yoga Class, ap-
GTD works both with physical objects (such as pen pears in a larger, underlined font followed by a task de-
and paper, an inbox that is a real box, and a physical fil- scription, Penguin Yoga, [email protected].
ing system) and with digital objects. Various applica- To make it easier to find tasks, you can assign tags,
tions let you implement the GTD system. One handy which consist of an @ sign, followed by the keyword. In
and free program that helps with GTD is Getting Things our example, you could assign the following tags:
Gnome (GTG). Even though development of the pro- @maybe/sometime @leisure @yoga. The tags are
gram ceased in 2014 and the former website (gtgnome. highlighted with yellow background making them im-
net) no longer works, it can easily be installed, and it mediately stand out in the text (Figure 10).
works well on modern systems. Figure 10 Finally, you will need to define
The first step is to collect all the a start and a due date. For the
documents that represent your yoga course, you might not
various responsibilities: letters, have time until August, and the
newspaper clippings, articles, offer is only good until October
photographs, and handwritten 31. There are two fields avail-
notes, as well as digital items able at the bottom of the dialog:
such as email messages or notes You can enter the data or select
in a digital notebook. You work from a calendar. If there is no
through the items that require ac- specific due date, just choose
tion and complete them according sometime. When you close the
to predefined criteria. The basic dialog, the new task will appear
rule is: Anything that you have in the main window.
taken from the inbox must not be Using View | Tags sidebar or
put back, but must be assigned to the F9 key, you can now open a
a suitable place in the system. sidebar in which all the tags you
Select items one by one. The first question for each have assigned are displayed. Right-clicking on a key-
item is: Throw it away, archive it, save it for later, or word opens a dialog, in which you can change the color
complete it? You can archive a newspaper article that the program uses to highlight a keyword for a task. Ad-
you have read but want to keep. The archive can also ditionally, you can assign an icon to the keyword; this
include things you might want to do later but don’t icon then appears in the main window next to the task
have time for now. Some of the tasks that you won’t ar- title. A search function is available in the sidebar.
chive or throw away are easier to do immediately, with-
out cluttering up the system. As a rule of thumb: Do Wait
things that take less than two minutes immediately; re- You can also enter tasks delegated to others in GTG.
serve the rest for later completion. Tracking delegation helps you keep an overview of
After separating out the things you will throw away, what you assigned, for when, and to whom, and it can
archive, or do immediately, you get down to something also remind you that completion is overdue.
resembling a to-do list with items that require intermit- For instance, you could forward a letter from the IRS,
tent or ongoing attention. GTG is a convenient, simple reminding you that you need to complete your income
tool for tracking tasks and maintaining that to-do list. tax return, to your tax consultant. At the same time,
You can quickly record the task, the start date, the de- you would use Ctrl+N to create a new task. Give the
sired completion date, and any sub-tasks that might be task a new title, such as Income Tax Return: Reminder
required as part of the process. GTG also lets you tag from Internal Revenue Service forwarded to tax consul-
Projects
Tasks that you want to complete yourself,
and that take more than two minutes, are
referred to as projects in GTD. Such proj-
ects are typically broken down into individual tasks. so that you are sure to complete all your pending pur-
First, create a new task for the overall project in the chases in a single visit. You can then highlight any com-
usual way by pressing Ctrl+N. If you want to write an pleted tasks, and they will disappear from the list.
article for a professional journal, the title could be Write
article. The following tags seem appropriate: @projects Simplification
@article. The completion date is the editorial deadline. Various plugins add functionality to GTG. To view and
Enter the individual sub-tasks line by line with a leading enable any available plugins, select Edit | Plugins. You’ll
dash; for example: -1. Literature research, -2. Get litera- find plugins that let you automatically delete high-
ture, -3. Read literature, -4. Write draft, -5. Send draft to lighted tasks, color-code tasks for easy recognition of
editor, -6. Incorporate editorial changes, and -7. Send urgency, and more.
finished article to editor. Use the Tomboy/Gnote plugin to sync tasks between
GTG creates its own subentry for each part of the task GTG and the Gnote or Tomboy note-taking tools (Fig-
and also creates a corresponding link in the main en- ure 12). First enable the plugin, and then enable syn-
try’s window. In the main window, the entries are chronization using Edit | Synchronization Services. A
shown indented under the main entry. To keep track, it new menu appears bottom left; now click on Add.
is useful to enumerate the tasks in the order in which Then select the program with which you want to sync
you want to complete them. tasks and notes (for example, Tomboy) and confirm by
In the sub-tasks, you can save notes for each step, for pressing OK. You just need to decide whether GTG
example, a list of the literature you want to read. As should synchronize all tasks and notes or just those
usual, you also have the option of entering tags. After that contain a specific keyword, say @GTG-Tomboy.
sending a draft of your article to the editor, you can to Click on Enable Synchronization and Close to complete
add the @wait tag to the corresponding sub-item. the synchronization.
You need to assign start dates and due dates for sub- By Daniel Tibi
http://gettingthingsdone.com
tasks. In this way, you can keep track of which sub-task
https://wiki.gnome.org/Apps/GTG
is pending; of course, the due date for a sub-task must
be no later than the due date for the project. After you Figure 12
complete a sub-task, right click on it and select Mark as
Done from the menu.
Regular Processing
To see which tasks are currently pending, you need to
work through GTG regularly as part of your daily rou-
tine. In the main window, click the Work View button.
Pressing the button changes the view of the main win-
dow (Figure 11). GTG only displays those tasks that you
need to complete. They include tasks that either have
no start date or whose start date has already been
reached. If required, you can filter this list for keywords.
For example, if you are heading into town for shopping,
you can display all items with the keyword @shopping,
HACK 19
Clone It with Clonezilla 27
HACK 20
Write ISOs to USB Sticks 28
HACK 21
Get a Quick Machine Configuration 29
Overview with inxi
HACK 22
Repair Your Bootloader 30
HACK 23
Cleaning House with Stacer 32
HACK 24
Image © bowie15, 123RF.com Reset Your Debian-Based Distribution 33
HACK 25
Repair the Debian Package Database 34
HACK 26
Learn the vi Editor Basics 36
HACK 27
Follow File Updates 37
HACK 28
Monitor Your System in a Terminal 37
HACK 29
Visualize ddrescue’s Progress 38
HACK 30
Run dmesg with the Right Options 38
HACK 31
Where Did You Mount That Disk? 39
By Graham Morrison
https://github.com/jsamr/bootiso
Figure 4
Figure 6 Desktop
formation on the system config-
uration here, but – at the end of Besides the tools for repairing the sys-
the log – also some hints on tem, you will only find a few prein-
how the repair tool will ap- stalled applications. Office applica-
proach the task. You can thus tions, games, multimedia, and educa-
determine what modifications tional applications are missing com-
the tool will make on the com- pletely. The Accessories menu con-
puter (Figure 6). tains entries for the LX terminal, the
The tool lists all the partition Leafpad text editor, and the PCManFM
data of all mass media (includ- file manager.
ing USB flash drives) connected You can launch Firefox from the In-
to the computer system, as well ternet menu, and the usual LXDE
as the GRUB configuration files. configuration dialogs are found
In addition to the repair pro- below the Preferences menu. As a
gram’s log, you will also find the special feature, the System Tools
complete output from the parted menu offers the Synaptic package
-l, parted -lm, mount, df -Th, and manager, which provides access to
fdisk -l commands in the text file. You are thus given a the Lubuntu repositories, if you need additional software.
good overview of the mass storage device configuration.
Hands-On
OS Uninstaller In our practical tests, the system was totally convincing. It
The third in-house developed tool included with Boot Re- not only successfully restored damaged boot sectors in
pair Disk is found in the System Tools menu: OS Unin- Linux-only installations, but also repaired a mixed system
staller. This helps you delete an operating system without with one Windows and two Linux partitions.
leaving any remains on your mass storage device and Also the OS Uninstaller enormously simplifies adminis-
without painstaking manual work. trative tasks: In our lab, it always reliably completed the
After launching, the desired tasks on multiple machines with a variety of
Figure 7
application first lists all shared storage devices, thus removing the need for time-
the existing operating consuming manual deletion and modification of the parti-
systems after a brief tion table, as well as the GRUB configuration files.
scan of the system (Fig- Boot Repair Disk is a very useful tool that every admin-
ure 7). Select the operat- istrator in a heterogeneous environment should include in
ing system that you want their toolbox. Even less experienced users will be able to
to delete from this list quickly control the intuitive tools without any problems.
and press Apply. After a The system itself is extremely stable, and the special tools
safety prompt, the unin- for revitalizing the MBR and the GRUB 2 boot manager
staller first deletes the operating system, then reconfig- were impressive. Also the deletion tool for unneeded op-
ures the boot manager, and finally displays the results. erating system installations saves a huge amount of man-
After a reboot, you will find the remaining operating sys- ual configuration work.
tems in the GRUB startup menu, where the OS Uninstaller By Erik Bärwaldt
adds entries for the Plop Boot Manager and Smart Boot https://sourceforge.net/projects/boot-repair-cd/files/
Manager. They do not have a function without additional https://unetbootin.github.io/
configuration, so you can safely remove them from the
Start menu. Figure 8
More Tools
In the event that hardware problems cause difficulties
when booting a computer, Boot Repair Disk comes with
two graphical diagnostic tools in the form of HardInfo and
GParted. HardInfo, which you will find under the System
Tools menu labeled System Profiler and Benchmark,
clearly visualizes the hardware in a two-pane window and
also performs benchmarks. GParted, on the other hand,
helps to manage the storage devices. This is where you
can, for example, identify problems arising from incorrect
formatting or damaged filesystems (Figure 8).
By Ferdinand Thommes
https://github.com/gaining/Resetter
https://github.com/gaining/Resetter/releases/tag/v2.1.0-stable
H AC K
Repair the Debian Package Database
25
Sometimes the package database on a Debian-based which builds packages that contain only dependency
Linux installation becomes inconsistent, and you can information.
no longer install or remove packages. There are ways In all these tools, you should gather whatever infor-
to fix the situation with apt, aptitude, and dpkg. mation you can about the state of the packages in-
Maybe you installed the wrong package from the volved. However, actually fixing the problem is likely to
Testing or Unstable repositories or gambled on Ex- take you far beyond the usual internal commands like
perimental. Maybe you installed a flawed third-party install and remove.
package or mixed packages from different Debian de-
rivatives. Or maybe the maintainer made a mistake, Making Repairs with apt
or a major technology change has happened, and When apt announces that you have broken dependen-
you are not to blame at all. But in all of these cases, cies and suggests solutions, very occasionally, remov-
you either receive an error message (Figure 13) or a ing problem packages with
ranked list of possible solutions, and suddenly you
are unable to install, remove, or update anything apt remove PACKAGES
until the problem completes its efforts and returns
you to a waiting command prompt. can solve the problem. On the principle of starting with
If you are patient, a new version of the problem pack- the simplest solution, try this command, but don’t be
age will be released that fixes the problem. The only surprised if it does not succeed.
trouble is, the new version might not be released for Another relative long shot is editing package sources
weeks, depending on where Debian, or your Debian de- to get newer versions of the problem package(s), using
rivative (like Linux Mint or Ubuntu), happens to be in its apt update to make them available. In particular, search
development cycle. Even after filing a bug, it can some- for a mirror site with more recent packages than your
times take time to resolve the problem. Probably, then, usual ones to add to the file /etc/apt/sources.list.
you want to take more active steps. A more promising approach is running
Fortunately, the tools you need are ones with which
you are likely already familiar: apt, the package manag- apt dist-upgrade --no-upgrade
er’s front end; aptitude, the popular command-line in-
terface; and dpkg, the basic package tool. All three have to upgrade all the packages installed on the system. Do
the structure not use apt upgrade, since the last thing you want to do
is complicate the problem by adding more packages to
COMMAND SUBCOMMAND PACKAGES the mix.
Another possibility is to force completion of an install
as well as many of the same features for installing and with:
removing packages.
apt and dpkg are installed by default on any Debian or apt dist-upgrade -f
Debian derivative system. However, if you have risky
habits, like constantly taking the latest package ver- Sometimes, specifying some or all of the packages
sions from Unstable, you should make sure that apti- mentioned in apt messages will work instead:
tude is installed, as well as other useful tools such as
script, which can log your recovery efforts, or equivs, apt install -f PACKAGES
Aptitude Dancing
When run without options, ap-
titude opens an ncurses inter-
face to the Debian package manager (Figure 14). How- ing background information that can help you develop
ever, what many users do not know is that aptitude a solution. The --yet-to-unpack option can be especially
contains many of the same tools as apt, apt-get, and useful when you have been looking for solutions for
dpkg for fixing broken packages, as well as several some time and don’t care to scroll back in your history
extra of its own. for the names of the problem packages.
For example, you may be able to resolve problems by An especially powerful dpkg option is --purge (-P).
using the markauto command to mark packages as being --purge is a more powerful version of remove, deleting
automatically installed, or unmarkauto to mark them as not only the package, but all records of it, including the
manual installations. Another useful command is -t RE- configuration files. In addition to removing the pack-
LEASE, which specifies which release version to use, or its age, --purge also runs its postrm (post-removal script).
counterpart forbid-version to specify a version not to use. While you are troubleshooting, this thorough deletion
Another useful pair of tools is why and why-not. Both are can simplify the problem’s background and sometimes
followed by a dependency. The why command shows why even solve the problem itself. The dpkg man page will
a dependency would be required, whereas why-not shows give you more information.
why a dependency produces a conflict. The results of Another important option is:
both can indicate how a subset of broken packages in-
volving conflicts with another package can be resolved. dpkg install --ignore-depends=PACKAGE
However, the most popular feature of aptitude is the
Resolver menu. The menu lists the package manager’s Descent into Dependency Hell
suggested solutions to dependency problems (see the
“Descent into Dependency Hell” box) and allows you Manually finding a solution when the package system no
to approve and reject them. Often, this menu alone longer works can be hard. Resolving broken dependen-
solves problems that apt-get, dpkg, or other features of cies can take hours, and the complications are so numer-
aptitude cannot, although at the cost of hiding exactly ous that, when you do find a solution, it can feel like luck.
what it is doing. The real solution, though, is to work systematically
through the possibilities.
Escalating to dpkg If you regularly find yourself in dependency hell – as bro-
ken dependencies were once called – then maybe you
Because dpkg is a lower-level package than apt, it in-
should consider your computing habits. While everyone
cludes many features that apt and aptitude do not. As is tempted by the latest possible release and can make
its man page shows, dpkg is especially useful for read- mistakes out of enthusiasm, by stepping outside the
ing detailed information about packages, including the safety of the package management system, you are strik-
state it is in, and for filtering the information displayed. ing out on your own.
You might be able to run dpkg with the option --forget- An expert can do that, but to do so requires caution
old-unavailable, --clear-selections to remove problems, every step of the way. Otherwise, you may be reduced to
or --audit (-C) to receive advice on what actions to try. desperate efforts such as editing a package’s scripts or
However, more often, dpkg options or commands, such fiddling with /etc/apt/preferences in the faint hope of
changing results that have already failed.
as dpkg-query, will be most useful in filtering or gather-
This option is misnamed, since it does check for depen- well as the man pages, before using it.
dencies but only reports conflicts between packages. In fact, dpkg as a whole can be so deadly that you
Often, it can be the solution for which you are looking. should use
An equally powerful solution is:
--no-act [--dry-run, --simulate]
dpkg --configure -a
to do a dry run of any action, simply on the off-
which configures all partially installed packages. In my chance of unexpected effects. The simulation will not
experience, this command fixes more broken depen- tell you in so many words that your system or desk-
dencies than any other option mentioned in this article, top environment will crash, but studying the list of
although it is not infallible. affected files should warn you that you risk making
If not, then take a detailed look at --force-things your situation worse.
THING, as well as --no-force-things and --refuse-things. The Debian package manager has other front ends,
Just as --purge is an enhanced version of remove, so notably Synaptic, a desktop interface. However, if apt,
--force-things is a fine-tuned version of the apt-get dpkg, or aptitude cannot restore full functionality, then
--force option. You probably want to avoid completions the chances are high that neither Synaptic nor anything
of these commands such as bad-version, remove, or over- else can do so.
write unless you are absolutely confident of what you By Bruce Byfield
are doing. However other completions, such as down- https://wiki.debian.org/Synaptic
grade, configure-any, and remove-reinstreq may provide
https://en.wikipedia.org/wiki/Dependency_hell
solutions. But --force-things can bring your system
down when used carelessly, so consult --force-help, as
HACK
27
Figure 16
tail -f <logfile>
In the case of one daemon process that handles logging of some ser-
But there is a tiny problem: Every now vice, telling it to switch to a new version of the logfile is easy. But there’s
and then a server will rotate some or all no way to keep track of various other processes that read the logfile and
of its logfiles. Rotating such a file means contact the processes in a meaningful way. Using a tool like lsof will
renaming it, possibly compressing it, and show all processes that have opened a specific file:
creating a new logfile with the old name.
When a helper program like logrotate has esser@xps13:~$ lsof /var/log/syslog
finished the rotation of some daemon’s COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
logfile, it will then inform the daemon by tail 16841 esser 3r REG 259,3 612458 12058755 /var/log/syslog
sending it a hang-up (HUP) signal (killall
-HUP daemon), and the daemon in turn will But how would you try to inform those processes of a change? The so-
close the (old) logfile and reopen it. If that lution must lie on the clients’s side. For tail, it is simple: Use the -F op-
last step does not happen, the daemon tion instead of -f, and you’re set. It will also make tail wait indefinitely
will continue to write to the old logfile for the watched file to reappear.
(even when that file completely disap- By Hans-Georg Eßer
pears after a compression step).
By Graham Morrison
https://github.com/p-e-w/hegemon
HACK 32 HACK 37
Install and Run Tor Browser 41 Enhancing Security with sudo Options 44
HACK 33 HACK 38
Permanently Wipe Files from Your Hard Disk 41 Use Two-Factor Authentication with Authenticator 46
HACK 34 HACK 39
Disable Webcam and Microphone 42 Start Your Training with Web Security Dojo 46
HACK 35 HACK 40
Disable Password-Based SSH Logins 43 Lock Your Screen, Always 47
HACK 36 HACK 41
Encrypt Your Emails with GPG 43 Use ccrypt for Quick Encryption 47
HACK
Permanently Wipe
33
Files from Your Hard Disk
H AC K When you delete a file in the file manager, it
does not exactly disappear. In most cases, it
By Christoph Langner
http://wipetools.tuxfamily.org/
Figure 2
# Webcam Disabled
blacklist uvcvideo
Although a browser requires the user to confirm that Cams with Microphone
the website is allowed to enable the webcam and micro- Things are a little different with a microphone built into the
phone, errors (on the part of developers, as well as device. Theoretically, as with a webcam, you need to dis-
users) occur time and time again. And with a locally in- able the necessary kernel module, which you can deter-
stalled application – installed voluntarily or by a trojan – mine quite easily by looking at a file in the /proc hierarchy:
you might not even be prompted to confirm. Apart
from a small light in the bezel, there is usually nothing $ cat /proc/asound/modules
to indicate that the device is recording. With some de- 0 snd_hda_intel
vices, the program can even turn off the webcam LED. 1 snd_usb_audio
With a classic desktop PC, you can usually simply un- 2 snd_usb_audio
plug the camera and microphone to stop the possibility 3 snd_usb_audio
of video spying. This solution is not available for porta-
ble systems with integrated input devices. Users with However, switching off snd_hda_intel not only takes
laptops and smartphones therefore often apply stickers down the microphone, but also the entire internal
to the webcam and the internal microphones. sound card. In this case, therefore, you need to com-
Alternatively, you can disable the webcam in the sys- promise between sound and perfect privacy. If neces-
tem settings so that programs can no longer call it. On sary, you could still connect a USB headset (even with
Linux, you have to disable the uvcvideo kernel module, an integrated microphone) – those devices use the snd_
which is normally loaded automatically at boot time. In usb_audio kernel module.
principle, you can do this manually via You can also scan the BIOS or UEFI settings for an
option to disable the integrated devices. Working at the
sudo modprobe -r uvcvideo BIOS or UEFI level gives you even more security: Theo-
retically, a blacklist created through the operating sys-
but very often, some program will have claimed the tem can be reversed by software running with adminis-
module so that modprobe fails with a “module in use” trative privileges.
error message that forces you to go for the heavy artil-
By Christoph Langner
lery and try:
https://webrtc.org
sudo rmmod -f uvcvideo https://github.com/webrtc/apprtc
HACK
Use Two-Factor
Authentication 38
with Authenticator
Many of us now use two-factor authentication
(2FA) when connecting to vital online services
such as Google Mail and GitHub. 2FA adds a
Start Your Training
with Web Security Dojo
HACK 39
second factor alongside your password, with Protecting your own websites from attack either costs a
the most common second factor being a time- lot of money or requires a lot of expertise. A specialized
limited, one-time pin generated by an app on Linux environment called Web Security Dojo offers an easy
your smartphone. way for everyday users and beginning professionals to
But using a smartphone app isn’t always learn about web security. Dojo is designed to provide prac-
ideal. This is where Authenticator helps. It is a tical, hands-on exercises on web security and intrusion
GTK3+ application that fits perfectly into a techniques. On SourceForge, you can find a virtual ma-
Gnome or Cinnamon desktop (Figure 6). It has chine (VM) image of around 2.7GB in OVA format that
both a light and a dark theme and looks lovely, works with both VirtualBox and VMware; it is based on
oriented in a portrait style much like the app. Its Ubuntu 16.04 LTS with an Xfce desktop.
best feature is that when you press the Add but- When you launch a browser in the VM, you learn about
ton to add a credential, almost every service the software you’re going to attack: Damn Vulnerable Web
you can imagine that supports 2FA is listed, Application (DVWA). From a menu, you can pick various at-
rather than leaving you randomly entering en- tack technique options, such as Cross Site Scripting (XSS),
cryption keys in the hope it works. With that SQL Injection, CSRF, or Brute Force (Figure 7). For the vari-
done and with the necessary keys exchanged ous scenarios, you will receive background information in
with the online service, you can then use Au- the form of links to related websites and wikis.
thenticator just like the app – selecting the pre- Web Security Dojo provides an excellent training oppor-
configured service to get a time-limited code tunity for budding security professionals who want to be-
and entering this into your login prompt. come familiar with the basic mechanisms for protecting
Having this facility on the machine where web applications. The OVA image is easy to install, and
you’re likely to use the codes is very convenient. the Xfce desktop is easy to configure. The developers
However, it does add a security risk, as anyone have carefully adapted the tools and test environments for
with access to your machine will be able to con- their intended use, so you can get started with the practi-
nect to your services (if they know the other fac- cal exercises right away.
tor – the password), so be careful!
By Erik Bärwaldt
By Graham Morrison
https://www.mavensecurity.com/resources/web-security-dojo
https://github.com/bilelmoussaoui/Authenticator/
https://sourceforge.net/projects/websecuritydojo/
Figure 6
Figure 7
By Hans-Georg Eßer
https://lockyourscreen.com/
H AC K
Use ccrypt for Quick Encryption
There are many ways you could encrypt a file before
sending it as an email attachment or uploading it to
The command-line tool ccrypt
provides a quick solution. It is avail-
41
some cloud storage service, and most of them will able from most distributions’ repos, so apt install, zyp-
need some amount of preparation or contain needless per in, or dnf install the package on your machine.
steps. For example, sending the attachment in a GPG- For encrypting a single file, type ccrypt filename. The
encrypted email requires you and the recipient to have tool will ask for an encryption key twice (because it
GPG installed and configured, and you need the other does not echo the characters you type), and that’s it.
party’s public key. Putting the file in a password-pro- Look into the directory, and you find that filename is
tected ZIP archive is an option, but why create an ar- gone and a new file filename.cpt has taken its place.
chive when you have just one file to send? The program has actually overwritten the data blocks
of the original file.
Figure 9
If you’ve chosen a good password (something that
won’t easily be found in a dictionary attack), you can
now transfer the file over insecure channels. The re-
cipient runs the ccdecrypt command on the file and
enters the password – after that the original file is re-
stored (Figure 9). For even better security, drop the
.cpt extension before sending the file making it
harder to guess what kind of encryption algorithm
was used.
By Hans-Georg Eßer
http://ccrypt.sourceforge.net/
HACK 42 HACK 48
Monitor Your Network with Nutty 49 Run a Simple HTTP Server: weborf 53
HACK 43 HACK 49
DIY Network Configuration 49 Use screen in SSH Sessions 53
HACK 44 HACK 50
Share Files on the Local Network 50 Access a Remote PC’s Shell Session 54
HACK 45 HACK 51
Dig a Tunnel with sshuttle 51 Slow sudo? Check Your Hostname 56
Configuration
HACK 46
Send Files Without Knowing the Target’s IP 51 HACK 52
Use Network Manager’s CLI 56
HACK 47
Check Your DNS Server with DNSDiag 52
By Graham Morrison
https://github.com/babluboy/nutty
DIY Network
Configuration HACK 43
Just because you can have your IP address assigned
# ip route add default via 192.168.1.1
This brings the device “up,” that is, to the active state. Figure 2
Now, assign it an IPv4 address with:
By Charly Kühnast
https://github.com/apenwarr/sshuttle
H AC K
Send Files Without Knowing the Target’s IP
Magic Wormhole really is one of those tools that, once recipient then simply types wormhole
46
you’ve used it, you’ll wonder how on earth you man- receive followed by the same phrase, and
aged to get by without it. This is because Magic Worm- the transfer will start immediately downloading the file
hole solves one of those ancient problems that have from one machine to the other, no server required. It’s
been around on Linux since we first started to connect perfect for transferring between virtual machines or
computers together with null modem connectors and a people sitting next to each other, when every other solu-
couple of lengths of wire. Back in those olden days, you tion requires more than a set of Python scripts.
might have used ZMODEM to transfer a file across the By Graham Morrison
serial connection. If you then upgraded to a connection https://github.com/warner/magic-wormhole
capable of TCP/IP, you could use FTP to transfer files
and then came HTTP. In the modern age, scp is often the Figure 6
best choice if you’re accessing an SSH server and want
to securely transfer files, or rsync if you want to copy
folders or perform incremental backups. But all of these
solutions suffered and suffer from the same problem:
The remote machine needs to be running a server of
some kind, and you need to know the remote address
of the machine you want to access.
This is why Magic Wormhole is so brilliant. If you want
to send a file, simply type wormhole send followed by the
file name (Figure 6). In the output, you’ll see a secret
phrase that you’ll need to share with whomever you want
to receive the file. The phrase is constructed from a few
words, so it’s easy to say or copy without mistakes. Your
Figure 7
Figure 8
HACK 48
Run a Simple HTTP Server: weborf mously, even adding the ability to do NAT traversal to
share files outside of the local network and sending di-
The wormhole tool mentioned in hack 46 is perfect for rectories as .tar.gz files.
one-off transfers, but it’s not all that great if you want to
share more than a single file or leave the tunnel open By Graham Morrison
so that you don’t have to keep renegotiating keywords. https://github.com/ltworf/weborf
There are of course lots of ways this can be done, but
weborf attempts the task while remaining almost as sim- Figure 9
ple to use as wormhole.
weborf (Figure 9) sets up a simple HTTP server, just
like running Apache in the olden days to share the con-
tents of /home. This makes it supremely flexible, not just
from a web browser, but from almost anything with ac-
cess to the network using WebDAV, with caching, even
from virtual hosts or running CGI scripts. You simply
run the server command with an argument for the port
to use and a folder to share, and all the client has to do
is access your IP address with the correct port. It can be
run in the background as a daemon, use certificates,
handle authentication with your own tools, and listen
only for connections from specific IP addresses. If the
command line offers too many options, a convenient
Qt-based GUI can be run to handle all this semiautono-
Figure 13
While the SSH ID displayed at the start of tmate The tmate software itself is only required on the ma-
creates a read-write session in a terminal, tmate chine where you want to start sharing a session – that
show-messages also shows an ID for a terminal session can run Linux, macOS, or one of the BSDs.
that supports read-only access. In addition, the pro- When the other party now enters the transmitted
gram provides two URLs that support the same pro- SSH ID/URL, the terminal shows what the person
cedure in the browser. seeking help is seeing in the terminal themselves.
Commands and their results run back and forth be-
Sending Keys tween the computers in fractions of a second. In the
Now you only have to send the SSH ID or URL to the session with read and write access, all parties can
other participants of the session. The best way to do enter data themselves. In the restricted session, only
this is to use chat and mail or share via a service such the host can write; the participants remain restricted
as Nextcloud. The final option you could consider is an to reading.
error-prone transmission by telephone. If you no longer need the split terminal, it is advisable
The participants you invited and entrusted with an to end the session by entering exit. If you just close the
ID or URL do not need to install tmate or tmux. You terminal, the other side will still have access to the
don’t need to use the same distribution or even use computer – a potential security risk.
Linux: Any operating system is fine as long as it has
an SSH client (Figure 14). And even the SSH client re- By Ferdinand Thommes
quirement can be lifted, because tmate also supports https://tmate.io
web-based connections: Just create a URL https:// https://github.com/tmux/tmux/wiki
tmate.io/t/SESSION where SESSION is replaced with https://www.gnu.org/software/screen/
the username part.
Figure 14
H AC K
51 Slow sudo? Check Your Hostname Configuration
While playing with a virtual machine, I the machine on which it is running, and that operation
came across a strange problem: Each time I ran a may cause a delay when you have mismatching infor-
command via sudo, there was an artificial delay of mation in your network configuration files.
about two or three seconds. After some Internet When you notice inexplicable delays, check the con-
searches and a confirming look at the source code, I tents of some of your configuration files – even if you
found out that the sudo tool queries the hostname of don’t think the problem is network-related:
• /etc/hosts should have an entry for your hostname –
Figure 15 either pointing to 127.0.0.1 (in that case it will be
placed on the same line as the localhost name) or on
a separate line with some other 127.* address.
• /etc/hostname should contain the hostname.
• Running the hostname command should also return
the hostname.
Figure 15 shows a situation (taken from a Linux Mint
18.3 desktop) in which settings are as expected: All
three use mint183cin. If you get different results (which
may happen after you have manually changed the
hostname instead of using your distribution’s “official”
configuration tool), fix the situation so that the new
hostname replaces the old one everywhere.
By Hans-Georg Eßer
By Graham Morrison
https://github.com/Xfennec/progress
Figure 3
By Christoph Langner
https://directory.fsf.org/wiki/Dtrx
and place the alias in the ~/.bashrc file. The above alias exa‘s ability to display entire folder structures recursively
would let you call the command by simply typing ll. in a tree view is also practical. To display a tree, supple-
ment the call with exa --tree or exa -T.
Table 1: Important exa Options You can limit the tree depth with the
Switch Long Form Comment --level=<n> option, where <n> is the
Display Options number of levels you want to display.
-1 --oneline Shows each file and folder in a new line Alternatively, switch off the tree view
-l --long Displays metadata, such as file permissions
and let exa list just the subfolders with
and size the -R or --recurse switch. Again, you
-R --recurse Lists the contents of subdirectories recursively can restrict the depth with the --level
(depth option: --level=<level_number>) option (Figure 8).
-T --tree Displays a tree structure (depth option: The shortcuts for sorting the output
--level=<level_number>) also make everyday life in the shell
--color <when> Color output is never, always, or automatic easier. For example, to find the largest
--color-scale Highlights the display of the file size in color files in a folder quickly, call exa like this:
for large files
Filtering and Sorting Options exa -lr --sort=size
-a --all Shows hidden files and folders
The -r switch reverses the order of
-d --list-dirs Treats directories like files
the output so that the largest files
-r --reverse Reverses the sort order
are at the beginning of the list.
-s <option> --sort=<option> Sorts by name, size, created, newest, or oldest,
By Christoph Langner
among other options
--group-directories-first Lists directories before files
https://the.exa.website
7 It is inconspicuous.
cheat.sh is a GitHub repos-
itory that delivers on all of
these promises by allow-
ing you to grab pre-pre-
pared text documents that
help you to work with the
tools you commonly use.
Type
curl https://cheat.sh/ssh
Figure 11
or redirect standard input via the < oper-
ator (hl keyword < filename).
Since hl simply forwards all options to
grep, you can use advanced features such
as searching for regular expressions or
asking the tool to ignore case. Highlight-
ing USB and network events took a simple
By Hans-Georg Eßer
By Graham Morrison
https://github.com/railsware/upterm
Using a Sub-Shell
HACK 65 or modify variables that might influence the shell’s be-
havior. For example, deleting the PATH variable (via unset
When you’re working in the shell and you type bash, PATH) renders the shell almost useless since it cannot
nothing happens – apparently. The shell prompt returns find binaries (unless you specify the full path).
at once, and you can continue to enter commands. But You may also start a sub-shell if you want to “hide”
when you try to run a command from the history, you commands: The shell writes the command history from
will notice that it is somehow outdated (and especially memory to disk when it terminates. The commands saved
the bash command that you’ve just typed will not appear by the sub-shell will be lost when the parent shell exits.
in the history). Another reason for a sub-shell is staying in a directory
That’s because you’re no longer working in the shell with a long path that you don’t want to memorize: Just
that was active when you typed the bash command: start a sub-shell, cd out of the current directory to do
You have started a sub-shell in a child process, and the some other work, and when you want to return, simply
original shell has been suspended until you leave the exit the sub-shell with Ctrl+D. Of course, there’s also the
new shell with exit. Running ps --forest will reveal the directory stack that was invented for exactly this pur-
parent-child pose – so if you know the pushd, popd, and dirs com-
Figure 18
relationship of mands, it is better to use those. If you don’t, a sub-shell
the two shells does the job, too.
(Figure 18). You can even temporarily suspend a sub-shell (using
But what is the suspend command) so that you can use the parent
that good for? shell; entering fg brings you back to the sub-shell.
Working in a When you use a desktop environment, you’re more
sub-shell is a likely to simply open more terminals instead of starting
good idea sub-shells. But if you often log into remote machines via
when you SSH, knowledge of sub-shells can come in handy.
want to test
shell options By Hans-Georg Eßer
HACK 67
Install the draw.io Diagram Editor Locally 71
HACK 68
Record Screencasts with Peek 72
HACK 69
Edit Your Videos with VidCutter 73
HACK 70
Creating Long Documents with Styles 73
HACK 71
Editing HTML with Live Preview in Brackets 74
HACK 72
Free Wildcard X.509 Certificates for
Your Domain 75
HACK 73
Test Alternative CMSs with Docker 76
HACK 74
How Fast Is Your Server? 76
Installation
For Ubuntu and Linux Mint,
there’s a Personal Package Ar-
chive (PPA) repository (Listing 1).
On Arch Linux, you can simply
install the application from the
Arch User Repository (AUR), and
if you use openSUSE, you can
find a package on software.open-
suse.org. For other distributions,
such as Fedora, Debian, or
Solus, the developer provides in-
structions for installation on the
project page.
HACK 69 HACK 70
Edit Your Videos with VidCutter Creating Long Documents
If you create lots of videos, such as screencasts of with Styles
your desktop (see hack 68 featuring Peek), you often Some documents that I create in LibreOffice Writer
need to cut bits out of them. That’s an essential part are “throw-away” documents: I type a few lines, add
of both the recording and editing process. Editing is some quick formatting, print the document, and then
obviously the central process in all video editors, but save the file or just close the program and discard it
often, all you want is the video equivalent of selecting all. That’s the one case where it doesn’t make sense
a piece of text and pressing delete. to work with styles.
VidCutter aims to do just that: Make practical edits But most documents are different: You create them
quick and easy. The UI is refreshingly simple. Most one day, and weeks, months, or years later you edit
videos load without conversion, thanks to the libmpv them again or create a copy to which you add new
back end, and you can immediately start playing with text. The longer those documents become and the
the edits. The basic process mimics that of fully more they are structured (into chapters, sections,
fledged editors while restricting options to a mini- etc.), the more it becomes vital to format them with
mum. You go through a file creating clips by selecting proper styles. For example, automatic generation of
the start point and end point of each clip. The mouse a table of contents is only possible when you’ve as-
wheel or left/right cursor keys can be used to step a signed a headline style to every headline.
single frame forward or backward, which is excellent, Using styles also guarantees that you can keep a
while up and down keys will skip five seconds. The uniform look throughout the whole document:
Return key can be used to quickly create a start or Headlines on page two will look the same as those
end marker for a clip, and a thumbnail of each clip ap- on page 102 – same font, same size, same color (if
pears on the right after being defined. that’s something you do to your headlines). Also,
You can reorder the clips by dragging and dropping exporting the document into a format that can be
them within the panel, and when you’ve finished used for web publishing is much easier when you
making clips and dragging them into a sequence for stick to using styles.
your final video, clicking Save will output the final Figure 4 shows two headlines in a document – but
version to a new file (Figure 3). only the second one is a real headline. When you
modify the headline style settings, only the real one
By Graham Morrison will show the changes, while the faulty first headline
https://github.com/ozmartian/vidcutter will remain unchanged.
By Hans-Georg Eßer
Figure 3
Figure 4
letsencrypt/letsencrypt-auto --help
Let’s Dance
The following command lets me request a certificate
for the namespace *.sensorenresidenz.de (just don’t ask
why I registered the domain):
By Charly Kühnast
https://github.com/reorx/httpstat
HACK 75
Safely Powering Off Your Machine 78
HACK 76
Make Files Immutable or Append-Only 79
HACK 77
Mount tar.gz and zip Archives 79
HACK 78
Recover Deleted Files with PhotoRec 80
and TestDisk
HACK 79
Change Root into Second Distro 81
HACK 80
Bind Mount a Directory with New Permissions 81
HACK 81
Run Binaries from a Different Linux Installation 82
HACK 82
Don’t Be So Case-Sensitive 83
HACK
75 Safely Powering Off Your Machine
Turning off your Linux com-
puter by cutting off the power is a bad idea: The system
magic-sysrq.conf file explain what each number means;
for this hack, we only show three lines:
wants to shut down properly so that it terminates all • 16 – enable sync command
running processes and unmounts the filesystems. If • 32 – enable remount read-only
you simply pull the plug, you risk losing data or cor- • 128 – allow reboot/poweroff
rupting the filesystem. Thanks to journaling, the repair To check whether these values are set you can either
procedure is quick, but you still should avoid a hard manually perform bitwise AND operations or use the shell.
shut down. For example, the following commands check whether 32
However, sometimes a regular shutdown procedure is part of the sum – the result is either 0 or 32:
takes too long. If you need to leave a room very sud-
denly and take your machine with you, waiting that one $ a=$(cat /proc/sys/kernel/sysrq)
minute until shutdown -h now completes may not be an $ echo $((a&32))
option. Maybe you have already heard of the magic 32
SysRq key – it can help you.
If enabled, Linux responds to key combinations Ubuntu sets the value to 176 which is 16+32+128 and
that begin with pressing Alt+SysRq. (The SysRq key precisely what you need to safely reboot the system. If
might be called PrintScreen on your keyboard or you need to change the value, either echo it into /proc/
have both names. On a keyboard with a standard lay- sys/kernel/sysrq or use the sysctl tool (Figure 2). In both
out, you will find it next to F12, see Figure 1.) Keep cases you will need root privileges.
Alt (or both keys) pressed, and then press a com- There are more magic SysRq features besides pre-
mand key to make the kernel perform some action. paring and performing the reboot, but most of them are
How should you use it? Just remember the following rarely needed. Check the official kernel documentation
sequence: (see link below) for a full description.
• Sync (S) – write buffered data to open files
By Hans-Georg Eßer
• Unmount (U) – remount filesystems in read-only
mode https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
• Boot (B) – force reboot
Thus, press Alt+SysRq+S, Alt+SysRq+U, and
Alt+SysRq+B for fast and safe rebooting. Figure 2
Will It Work?
Check the contents of /proc/sys/kernel/sysrq – if it’s 0,
then the magic key combinations are turned off com-
pletely, and pressing Alt+SysRq will have no effect at
all. If the answer is 1, all hotkeys are enabled.
It is more likely that specific functions are enabled
and others are not: In that case, the result will be a sum
of some powers of 2 (namely, 2, 4, 8, 16, 32, 64, 128,
and 256). Comments in Ubuntu’s /etc/sysctl.d/10-
Figure 1
By Hans-Georg Eßer
Figure 3
Figure 5
cd /mnt/dist
mount -o bind /proc proc
mount -o bind /sys sys
mount -o bind /dev dev
mount -t devpts pts dev/pts
By Hans-Georg Eßer
https://bindfs.org/
https://github.com/libfuse/libfuse
H AC K
Run Binaries from a
Different Linux Installation
81 able. Try to launch the program copy in the cur-
rent directory and check the error message. In the
example, xv was missing the file libpng.so.16. But it’s
Software installation has become so simple with the ad- right here: You copied it from the source system. So
vent of repositories and management tools like APT, Zyp- add that (with its absolute path) to LD_PRELOAD by typing
per, Yum/DNF, and so on: Just pick a package you want
LD_PRELOAD="$PWD/libpng.so.16" ./xv
and let the package manager figure out what other pack-
ages (dependencies) it needs and install all of it in one go. This might lead to another (new) error message com-
Sadly, not every application appears in every Linux plaining about some other file. For the xv example, the
distribution’s repositories. For example, the image next command was
viewer xv is one of my favorite tools, because it is incred-
LD_PRELOAD="$PWD/libpng.so.16 $PWD/libz.so.1" ./xv
ibly fast. But it’s also very old and has not seen any up-
dates since 1994. Its source code is available, but it has a and that finally started the tool (Figure 10). Note how the
habit of not compiling. Some distributors (for example file names have to be separated by a blank character, and
openSUSE) have managed to get it running and provide the whole argument is put inside double quotation marks.
packages in their repositories. Other, like Ubuntu, do not. For other programs, constructing the command line
So how about just copying the binary file from a open- might take longer, and there are going to be problems
SUSE system to an Ubuntu installation? if you want to use this method to make a 32-bit binary
Well, that is likely to cause problems; in most cases, run on a 64-bit system. At least, those can normally be
attempting to run the binary will produce an error mes- solved by installing the 32-bit compatibility layer. The
sage that complains about missing libraries. In that other way (moving a 64-bit binary to a 32-bit machine)
case, don’t start searching for them on the target sys- is technically impossible.
tem. They are either missing, or they have been in-
stalled with the wrong version numbers. Or Use LD_LIBRARY_PATH?
Instead, go back to the source system, and search for If you’re aware of the LD_LIBRARY_PATH variable in which
the library files there. You can use ldd to get a list by you can add directories with libraries that the program
typing ldd /usr/bin/xv (for the xv example; Figure 9). loader will search before the default folders, you might be
Now quickly build a ZIP archive by supplying the whole tempted to simply set it to the local directory that has all
output of ldd as argument list for zip: the needed libraries in them: I tried that, too. Turns out, it
did not work with the example files, because the GNU C
zip xv.zip $(ldd /usr/bin/xv)
Library was incompatible with the running kernel. But
This will generate many error messages, because there’s you can start with that approach, too: Run the command
more than file names in the output, but it does not matter:
LD_LIBRARY_PATH=$PWD ./xv
zip will happily put everything it recognizes as a file into
the new ZIP file. Copy that one over to the target machine. and then, step by step, delete all libraries that the
On the target machine, create a new folder for your loader complains about until those error messages
program, move the program binary itself into that stop and your program starts. Read the ld.so man page
folder, and unzip the file with if you want to find out more about how loading a pro-
gram works on Linux.
unzip -j xv.zip
The -j option makes unzip lose the path information, so By Hans-Georg Eßer
it simply drops all files in the current directory. http://www.trilon.com/xv/
Now you’re almost there: Start an incremental pro-
cess in which you add library files to the LD_PRELOAD vari- Figure 10
Figure 9
HACK 82 Don’t Be So
Case-Sensitive
We all know the eternal Unix rule: File names are case-
Now the ciopfs driver follows these rules:
• Files that already exist in folder1 and whose file
names are all lowercase appear in folder2 with the
same spelling – other files are left out completely.
sensitive. That means, Makefile is not makefile. While it • Files that you create in folder2 – with whatever mix of
would be bad practice to have both in the same folder, upper/lowercase letters – will show up in folder1 in all
you could do it, and it has been done. lowercase (Figure 11).
When you leave the Linux world, the situation be-
comes complicated: Windows stores file names the Adjusting a Folder
way you typed them at file creation, and that’s the way So how can you convert a folder’s file names to all
you will see them in the file manager or in the shell – lowercase? If you don’t, files with upper-case letters
but the system does not care what spelling you use for will not show up under the ciopfs mount point. Sev-
accessing them. This means that you can not have eral solutions have been discussed on Stack Overflow
Makefile and makefile in the same directory on an NTFS – the overall idea is to let find run a breadth-first
or FAT partition. Then again, Windows is not a Unix-like search over the directory tree with
system. But turn to macOS, which is partly based on
find . -depth -exec mksmall {} \;
BSD, yet also ignores upper/lowercase differences in
file names – the old Unix rule is not valid for macOS. where mksmall is a shell script that will update the file
This is relevant to Linux users who use Wine to run name. Listing 1 shows an example implementation; it
Windows applications on their Linux machine. Some uses a collection of classic command-line tools:
Windows apps have problems with the Linux way of • dirname extracts the directory part from a file’s path
expecting the precise spelling of a file name and may • basename extracts the file name
break. If you’ve encountered this problem, then there • tr exchanges one set of letters with another one, in
is a solution: ciopfs (which stands for case insensitive this case uppercase (A-Z) with lowercase letters (a-z)
on purpose file system), a FUSE filesystem driver. It al- • test compares two strings
lows you to perform an action similar to a bind-mount Ciopfs, like archivemount and bindfs, is one of many
(see hack 80), but with an important difference: when FUSE-based filesystems. The FUSE project page lists
you try to access files under the new mount point, several more – maybe you’ll find some other interest-
case doesn’t matter. ing drivers (e.g., ClamFS, which integrates antivirus
Of course, you’re not restricted to using ciopfs with a scanning).
Wine installation. If you’re also a macOS user and often By Hans-Georg Eßer
switch between the two Unix-like environments, you
may want to unify the experience and make Linux be- http://www.brain-dump.org/projects/ciopfs/
have like macOS. https://wiki.winehq.org/Case_Insensitive_Filenames
https://stackoverflow.com/questions/152514/
Installation
https://github.com/libfuse/libfuse/wiki/Filesystems
If you’re running Ubuntu or Linux Mint, you can just
type sudo apt install ciopfs. I could not find any RPM
packages, and I tested source code compilation on an Listing 1: mksmall
openSUSE Leap 15 machine. If you have an openSUSE
system, get the source archive from the project web- #!/bin/bash
site, unzip it, and run the following commands (which FILE="$@"
DIR=$(dirname "$FILE")
assume that you’re still in the directory that holds the BASE=$(basename "$FILE")
ZIP archive): NEWBASE=$(echo "$BASE" | tr A-Z a-z)
if test "$BASE" != "$NEWBASE"; then
sudo zypper in gcc fuse-devel glib2-devel libattr-devel mv "$DIR/$BASE" "$DIR/$NEWBASE"
cd ciopfs-0.4; make && sudo U fi
make install Figure 11
Type ciopfs --version to check
whether you’ve been successful.
Using the new tool is ex-
tremely simple: Just type ciopfs
folder1 folder2 where folder1 is
the original directory that holds
files, and folder2 is an empty
directory that’s used as the
mount point.
HACK 83 HACK 89
Run C Code from the Command Line 85 Reverse Engineering with Cutter 88
HACK 84 HACK 90
Edit Binary Files with hx 85 Textadept Works in Graphics 89
and Text Mode
HACK 85
Edit Your Text Files with Textosaurus 86 HACK 91
Perform Dynamic Code Analysis with 89
HACK 86
SystemTap
Manage Your git Repository with GRV 86
HACK 92
HACK 87
Count Lines of Code in Your Project 90
Make git Interactive 87
HACK 93
HACK 88
Fix Disturbing Indentation and More 90
Replace hexdump with a Colorful Tool 87
will print a sequence of numbers (just like seq -s " " 0 999
does). It is also possible to use code that stretches across
several lines: When you start the C string with the ' charac-
ter (like in the examples), you can press Return as often as
you like – until you end the string with another ' symbol.
As a fun example, in order to generate a segmenta-
tion fault, just try an assembler instruction that would
disable interrupts: runc 'asm("cli")' cannot be run suc-
cessfully, because cli is a privileged instruction that
can only run in kernel mode.
By Hans-Georg Eßer
H AC K
Manage Your git
Repository with GRV 86 the repository are captured by monitoring the filesys-
tem and updating the UI automatically. This means it
works well in a separate tmux panel, for example, cap-
So many of us now use git on the command line that it’s turing changes as you make them, or as they’re pulled
difficult to contemplate using a GUI tool to make access- from upstream. git is complicated; while GRV is never
ing git repositories easier. The context shift from com- going to make the learning curve any easier, it’s a fan-
mand line to desktop is often enough to break your train tastic tool for confirming what you think is happening is
of thought or concentration, but here is a helpful tool actually happening, as well as helping you to visualize
that’s worth using: Git Repository Viewer (GRV) effec- how your projects are developing.
tively builds an entire GUI on the command line around By Graham Morrison
your local git repositories. The main view, called the His- https://github.com/rgburke/grv
tory View, consists of three panels (Figure 4). On the left is
a pane for branches, tags, and remote references, and in Figure 4
the middle is a list of commits for your chosen branch.
The pane on the right side lists the changes, as a diff, for
that specific commit. The other view is Status View, which
gives an overview of what’s changed in your local branch
since the last push. If you’re already familiar with git, this
makes complete sense. It’s wonderful to see your work
presented in such a clear way, just as you likely imagine
the whole repository hanging somewhere.
GRV is also deep. It defaults to using Vim key bind-
ings and makes a wonderful partner to programming in
the editor. There’s even theme support and the ability
to filter through the data using a query language rather
than simple searches. In the background, changes to
HACK
87
Make git Interactive
Tools for navigating git repositories, their history, and
their branches are becoming almost as common as
Replace
hexdump with
a Colorful Tool
HACK 88
CPU monitors. And like CPU monitors, they also hap-
pen to be very useful. Having more options to choose When viewing binary files in hexadecimal,
from means you’re more likely to find a tool to fit your you’re able to decode more than the literal value for
exact requirements. One fully fledged option is GRV any one location; you’re actually able to see pat-
(see previous hack), which runs from the command terns and even raw data emerge, because the view
line and features several different view modes. can represent the way data is physically passing
At the other end of the feature spectrum, gitin is through memory. This is why a hexadecimal viewer
another great option. Unlike GRV, gitin isn’t an appli- is an essential utility to have at hand, especially if
cation in which you spend time; instead, it works best you’re interested in how files are stored or how an
as a form of wrapper around the git commands you executable may work.
might use anyway. Its principle functions allow you One such tool, hexyl, couldn’t be any simpler (Fig-
to work with branches, check the status of a reposi- ure 6). It’s driven from the command line and takes a
tory, and view the logs, which are all you need in a filename as an argument. The only other potential ar-
tool, since you don’t want to duplicate what git al- gument is a value to adjust the number of bytes read
ready does so well. from the input. This is useful if you’re trying to view
Type gitin log within a repository, for instance, and something large, such as a swap file or even a virtual
you see a list of the most recent commits. Using the device such as memory. But the best thing about
cursor keys to scroll through them updates details on hexyl is how clean the output is. There’s no superflu-
each commit, and pressing return dives into which ous detail, with the same three columns you tradi-
files have changed. Select a file, and you get the tradi- tionally see in hexadecimal viewers and editors – the
tional diff view of what’s changed within that file starting location for a row, the hexadecimal value for
(Figure 5). It’s minimal and effective and, most impor- each location for the input shown on the left, and an
tantly, doesn’t detract from the work you’re likely try- ASCII rendering of those locations on the right. Loca-
ing to do in the same terminal. It just lets you see the tions are colored according to their type: NULL bytes,
same details git can provide in a more convenient and printable ASCII characters, ASCII white-space charac-
interactive way that’s also quicker than trying to work ters, other ASCII characters, and non-ASCII. This
out the commands using git alone. The use of color is makes it very easy to correlate the ASCII output with
also very effective and helps especially in the diff view that data’s location within the main view.
where the red of a remove line and the green of a new
line is far easier to see than the - and +. By Graham Morrison
https://github.com/sharkdp/hexyl
By Graham Morrison
https://github.com/isacikgoz/gitin
Figure 6
Figure 5
HACK 89
Reverse Engineering with Cutter
The reverse engineering tool radare2 takes your Linux ence, Cutter still helps you get some usable knowledge
binaries and turns them into a stream of assembler, let- out of almost any binary, even if it’s just a greater un-
ting you work out exactly what happens when a pro- derstanding of how many subsystems there are in
gram is executed. You need to understand assembler, Linux and how many CPU cycles are potentially wasted
your hardware, and the various subsystems a binary drawing drop shadows.
takes to produce output, but
that’s where radare2 will try and Figure 7
help, splitting the assembler
into functions, libraries, and
symbols to help you make bet-
ter sense of what’s happening.
The only problem with
radare2 is that it’s pretty com-
plex. Fortunately, there’s a
shiny GUI called Cutter that
makes its functions better ac-
cessible. After launch, you sim-
ply select a binary and you’re
done. Something locally com-
piled will reveal the most use-
ful information, but you can try
anything. Cutter will then
spend a little time analyzing
the binary, the results of which
are shown in a “sections” pie
chart that brilliantly shows the
components detected within
the binary. A similar graphical
representation of the binary is
also shown as a horizontal bar
chart at the top of the window,
with each slice showing the use of sequential memory. Figure 7 shows the following areas of the Cutter pro-
But the main part of the Qt-configurable window is gram window:
the disassembler itself, showing the assembly mne- Functions: Cutter can detect when a chunk of code
monics, usually helpfully annotated to show loops 1 is independent and therefore a function.
and jumps, the names of registers, and function Binary map: See where things are in the binary file
names. This is where you can follow the track of exe- 2 you’re viewing.
cution through your binary. Cutter helps with this, Search: Look through the binary for both flags and
too, as you can click on jump or branch instructions to 3 a specific address.
see where the code runs next. Overview: See the details for where you are and
The disassembler is augmented with various other 4 where you’re going next.
tabs to help you make sense of the code. There’s a hex Pie chart: Analysis breaks up the executable into
viewer, for instance, so you can see the raw binary con-
tents of the file. There’s also an excellent pseudocode
5 parts; this chart shows how each part is propor-
tionately used.
generator that will turn the assembler in a function into Details info: Create pseudocode, see a visual repre-
something where loops and structures are demarcated 6 sentation of the current function, and view the hex.
by curly brackets – it feels a lot like C, where the key-
words have been replaced with assembler. Strings, 7 Sections: The annotated version of the pie chart.
entry points, and imports can be investigated in the
same way, and you can search directly for either a flag 8 Disassembly: The code being run by your binary.
By Graham Morrison
https://foicica.com/textadept/
H AC K
Perform Dynamic Code Analysis with SystemTap
In multithreaded programs, the order of statements in One of the things that SystemTap
91
the sources is different from the order of execution. So, can do is help determine “contended
merely looking at the code doesn’t reveal the sequence locks.” SystemTap comes with many examples found in
of the program’s operations. You want some tools for /usr/share/doc/systemtap/examples. One of these is the
live introspection, also called process/futexes.stp script. It traces the futex system call
dynamic code analysis. and dumps how many times the thread had to sleep
SystemTap is one waiting for the lock and for how long:
such tool, and stap is
its main executable. $ sudo stap -c ./sampleprog futex.stp
SystemTap lets you ...
write small scripts sample[3006] lock 0x7ffcc7301fe0 contended 79 times,
called probes and attach them 26 avg us
to various events happening
in user space and in the ker- Lower values are generally better. Make sure you
nel. It was designed to be safe have the kernel debug info installed.
for use on production sys-
tems, so you can study non- By Valentine Sinitsyn
trivial situations such as dead- http://sourceware.org/systemtap/
locks in the wild.
H AC K
Fix Disturbing Indentation and More 93
A classic developer tool is the “indenter”: a program Once it’s installed, grab a suitable source file and run:
that takes a source code file and creates a new version
uncrustify -c linux.cfg testfile.c
where indentation and brace placement follow some
fixed rules. To see an old example program from this This will create a new file testfile.c.uncrustify. I tried it
category, look at indent. The Unix original is from the on auto-generated (and poorly formatted) code with
late 70s, and on Linux you can install GNU indent, some success, as you can see in Figure 10.
which was last updated in 2008.
By Hans-Georg Eßer
For a more flexible approach have a look at the
uncrustify tool: It can do a bit more than indent, and https://en.wikipedia.org/wiki/Indent_(Unix)
you can configure it by writing a complex config file. http://uncrustify.sourceforge.net/
The program supports the C, C++, C#, Objective C, D, http://uncrustify.sourceforge.net/linux.cfg.txt
Java, Pawn, and Vala languages. To get you
Figure 10
started, there’s a sample file (search for linux.
cfg.txt in the package contents or on the pro-
ject web page).
I found packages for Ubuntu/Mint and open-
SUSE in the regular repositories. If it isn’t avail-
able for your distribution, compile it from the
sources; you can check out the current version via
HACK 94
Interesting Terminal Output for Your Visitors 93
HACK 95
Scan the Network Like a Script Kiddie 94
HACK 96
Image © lightwise, 123RF.com
Drive Your Moon Lander – in ASCII! 94
HACK 97
Run Your Own BBS 95
HACK 98
Explore, Expand, Exterminate: Play Star Ruler 2 95
HACK 99
Edit Files Like It’s the 90s Again 96
HACK 100
Read Old Unix Books 96
HACK 101
Pick a Retro Screensaver 97
H AC K
94 Interesting Terminal Output for Your Visitors
Are your friends or colleagues coming over Other than producing interesting output and (when
and you want to impress them with interesting programming) seeing stuff in octal, knowing od is help-
and mysterious stuff happening on your computer ful when you prepare for the LPI tests: It’s listed in the
screens when they take a tour of the house? Then you curriculum, and that is why I know it.
have lots of options.
Create Slowly Scrolling Output
Glitch in the Matrix You know those movies where hackers sit in a dark
Let me introduce to you the od program. The name is room behind a big screen, and occasionally you get a
short for “octal dump,” and the tool works like hexdump glimpse of what’s happening on the screen. In some
but uses octal numbers (0-7) instead of hexadecimal window, there’s always some scrolling output. That
ones. Let it output /dev/urandom to get a (very cheap) could be C compiler messages, dmesg lines, or just some
text mode version of the scrolling symbols from The random JavaScript and HTML from a webpage – it
Matrix movies. If you want to get rid of the space signs, doesn’t really matter (to the film directors) as long as it
remove them with tr: looks geeky.
Now you want to have this on your screen, but sim-
od /dev/urandom | tr "\n" " " | tr -d " " ply running dmesg or cat source.c in a terminal window
lets the text scroll far too fast. The following code re-
Run the od output through lolcat to get the colorful places cat as a filter and introduces a short sleep after
version shown in Figure 1. Some distributions carry a every line:
lolcat package; if yours does not, you can install it
manually. while read -r; do echo "$REPLY$"; sleep .02; done
HACK
95 Scan the Network Like a Script Kiddie
The nmap (network mapper) tool searches for open security focus – as well as hackers gone bad who at-
ports in a computer network or on some specific ma- tack machines for evil purposes. The second group in-
chine, and it can even find out what operating system cludes script kiddies.
and version is running on a remote computer. That True script kiddies like to see their texts in leetspeak
makes it an important tool for IT professionals with a (or l3375p34k). Since they are likely to (mis-)use the
nmap tool, it provides a leetspeak option to
Figure 3 make them comfortable. You can feel like
a script kiddie, too: Just run the mapper
with the option -oS to change the output
format to “Script kiddie” – the result will
look like Figure 3.
The -o option has further, more legiti-
mate parameters as well: -oX switches to
XML output, and -oG to a format that can
easily be filtered with grep. But where’s the
fun in that?
By Hans-Georg Eßer
https://nmap.org/
https://en.wikipedia.org/wiki/Leet
By Graham Morrison
http://ascii-patrol.com/
HACK 97
Run Your Own BBS
code, it benefits a much wider audience. Star Ruler 2
is a great example (Figure 6). This is a popular real-
time strategy (RTS) game from 2015, and it’s still
available on Steam, but the studio behind it, Blind
Mind Studios, has been inactive for a few years.
Those of a certain age will remember a time before Rather than drop off the radar completely and alien-
the Internet: If you wanted your computer to commu- ate its players, the studio decided to open source
nicate with other computers, you did it on a 1:1 basis both its game and the expansion pack.
across a telephone line. You dialed a number, and an- You can install the game with just a single com-
other computer answered before proceeding to ne- mand, sudo snap install starruler2, if your system
gotiate a stream of ASCII going back and forth down supports snaps. You get a major multiplayer RTS title
the line. There were many popular “online” services on Linux for free, and that’s never a bad thing.
that you could pay to access, but perhaps the best
Figure 6
use of this technology was the humble bulletin board
system (BBS). These were portals for files, messages,
and games that were usually run from a home com-
puter with nothing more than one or two phone lines
that became available in the middle of the night.
The Internet killed the BBS scene, but it’s now hav-
ing a slight renaissance, partly for nostalgia, but also
because the web has become hugely distracting.
These new BBSs, and even the old ones restored
from backups, are accessible over a simple Telnet
connection (and sometimes SSH); you can even be-
come the sysop of your domain. MBSE BBS is a mod-
ern BBS (Figure 5) you can install that’s still being up-
dated, although it takes some setting up. If you try it,
your users will be able to create accounts and log in,
leave messages, download and upload curated files,
and chat with each other. You can even allow as
many concurrent users as you need. Set in space, the game itself is known as a “4x”
RTS game, meaning your role as the ruler of the gal-
By Graham Morrison axy is to explore, expand, exploit, and exterminate.
https://sourceforge.net/projects/mbsebbs/ There are seven different races with different attri-
butes, or you can create your own. With that done,
Figure 5 you’re dumped into space where you need to man-
age your finances and local resources to build an em-
pire. You map resources between systems by drag-
ging lines between them, creating networks for im-
ports and exports. You use your fleet of ships to ex-
plore and colonize just as you do with other RTS
games. As you play, you acquire influence points that
can be used in diplomacy, and you can even design
your own ships. The game is a lot of fun, and it’s pol-
ished, just as you’d expect with a commercial game.
By Graham Morrison
http://starruler2.com
By Hans-Georg Eßer
https://www.dosbox.com/
https://www.freedos.org/
H AC K
Read Old Unix Books
Reading a good book is always worth-
100 pen to all documentation. While a KDE book
from the late 90s has lost all usefulness (except
as a picture album to see what desktops looked
while, but computing literature tends to age in like in the old days), you can always grab a good intro-
a way that makes most practical descriptions obsolete duction to the shell – for example the article “The UNIX
within a decade. In the case of Linux, that doesn’t hap- Shell” from Stephen R. Bourne, who developed the
Bourne shell (sh), an ancestor of the Bash
Figure 8 shell. After all, Bash is an acronym, meaning
“Bourne-again shell.”
The article was published in 1978. Grab a
copy from archive.org and read the introduc-
tion to using the shell, working with variables,
writing shell scripts with for and while loops,
pipelines, and much more (Figure 8). Travel-
ing back in time 40 years does not change
shell usage a lot. Of course, a modern Bash
has more features and offers more comfort,
but the basics have remained the same.
By Hans-Georg Eßer
https://archive.org/details/bstj57-6-1971
By Hans-Georg Eßer
https://www.jwz.org/xscreensaver/
We are always looking for good articles on Linux and the The technical level of the article should be consistent
tools of the Linux environment. Although we will consider with what you normally read in Linux Magazine. Re-
any topic, the following themes are of special interest: member that Linux Magazine is read in many countries,
• System administration so it is best to avoid using slang and idioms that might
not be understood by all readers.
• Useful tips and tools
Be careful when referring to dates or events in the future.
• Security, both news and techniques
Many weeks could pass between your manuscript sub-
• Product reviews, especially from real-world experience mission and the final copy reaching the reader’s hands.
• Community news and projects When submitting proposals or manuscripts, please use a
If you have an idea, send a proposal subject line in your email message that helps us identify
with an outline, an estimate of the your message as an article proposal. Screenshots and
length, a description of your back- other supporting materials are always welcome.
ground, and contact information to Additional information is available at:
[email protected]. http://www.linux-magazine.com/contact/write_for_us.
Contact Info
Editor-in-Chief While every care has been taken in the content of the
Hans-Georg Eßer magazine, the publishers cannot be held responsible for
Senior Editor the accuracy of the information contained within it or any
Joe Casad consequences arising from the use of it. The use of the
Managing Editor DVD provided with the magazine or any material provided
Lori White on it is at your own risk.
Localization & Translation
Ian Travis Copyright and Trademarks © 2020 Linux New Media
Authors USA, LLC
Copy Editors
Amy Pettle, Megan Phelps No material may be reproduced in any form whatso-
Erik Bärwaldt Layout ever in whole or in part without the written permis-
Dena Friesen, Lori White sion of the publishers. It is assumed that all corre-
Paul Brown
Cover Design spondence sent, for example, letters, email, faxes,
Bruce Byfield Dena Friesen, Illustration based on graphics photographs, articles, drawings, are supplied for
by bowie15,123RF.com publication or license to third parties on a non-exclu-
Hans-Georg Eßer
Advertising sive worldwide basis by Linux New Media unless
Frank Hofmann Brian Osborn, [email protected] otherwise stated in writing.
phone +49 89 3090 5128
Klaus Knopper
Marketing Communications Linux Magazine Special (ISSN 1757-6369) is published
Charly Kühnast Gwen Clark, [email protected] by Linux New Media USA, LLC, 2721 W 6th St, Ste D,
Christoph Langner Publisher Lawrence, KS, 66049, USA.
Brian Osborn
Graham Morrison All brand or product names are trademarks of their re-
Customer Service / Subscription spective owners. Contact us if we haven’t credited your
Tim Schürmann For USA and Canada:
Email: [email protected] copyright; we will always correct any oversight.
Valentine Sinitsyn Phone: 1-866-247-2802
(toll-free from the US and Canada) Printed in Germany on FSC and PEFC certified paper.
Ferdinand Thommes
For all other countries: Distributed by Seymour Distribution Ltd, United
Daniel Tibi Email: [email protected] Kingdom
Alexander Tolstoy Linux New Media USA, LLC
2721 W 6th St, Ste D, Lawrence, KS, 66049 USA Published in Europe by: Sparkhaus Media GmbH,
Uwe Vollbracht www.linux-magazine.com Zieblandstr. 1, 80799 Munich, Germany