This blog is about the Linux Command Line Interface (CLI), with an occasional foray into GUI territory.
Instead of just giving you information like some man page, I hope to illustrate each command in real-life scenarios.

Search This Blog

Monday, July 28, 2014

My Debian system runs the current stable Debian distribution Wheezy.
However, there are software packages that are only available in the current testing distribution Jessie.
Examples are dateutils, and Enlightenment 0.17.
Too eager to wait for Jessie to become stable, and too lazy to build these packages from source, I used the apt-pinning technique to coerce APT, Debian's package manager, to install these packages on Wheezy.

Apt-pinning lets you mix and match the different distributions in a Debian release: stable, testing, and unstable. The steps below explain how to specify that all packages should be installed or updated from Wheezy (the stable version), with the exception of dateutils which we 'pin' to Jessie (the testing version).

Disclaimer: Apt-pinning is considered an advanced topic in Debian. Use at your own risk.

Any package that is not named dateutils, and is not part of Wheezy is matched by the third section with a priority of -10. A negative priority means that the package will never be installed or upgraded. This entails that no package from Jessie other than dateutils will ever be installed or upgraded.

When a newer version of dateutils becomes available in Jessie, dateutils will be updated. This is because the dateutils package is matched by the first section, which takes precedence over the third section.

It is highly recommended that you read the man(5) page for apt_preferences to know more about setting preferences.

Update APT repository.

$ sudo apt-get update

Install dateutils.

The following command installs dateutils from testing, and also attempts to fulfill its dependencies from testing.

$ sudo apt-get -t testing install dateutils

To upgrade your system, execute, as usual, sudo apt-get upgrade. dateutils is upgraded from Jessie while all other packages are upgraded from Wheezy.

Sunday, July 20, 2014

If I ask a Linux user what desktop environment he is running, most likely he can tell me the correct answer - GNOME, KDE, Xfce, LXDE, etc. But if I ask him what window manager he is running, I won't be too surprised if he can't answer me. In fact, not long ago, I did not know that myself.

The Window Manager dictates how various visual elements - windows, panes, icons, etc - look, and how users may interact with these elements. There are many window manager choices: Metacity, Mutter, Compiz, Openbox, etc.

The key is that you are not locked in to any window manager. If you don't like your current window manager, change it. This post explains how to change the window manager, specifically for the GNOME desktop environment.

Before we change it, let's find out which window manager is currently running. To do that, you need to install and run a tool named wmctrl.

Wednesday, July 16, 2014

Linux is known as a very secure operating system. But, it is not going to save us if we voluntarily or unknowingly expose ourselves to unnecessary danger.
For instance, a password-authenticated command may allow you to specify the password right on the command-line.

$ mysql -u root -pMyPassword

The command you just executed - with the mysql root password - gets recorded in the shell command history file. For bash, the history file is ~/.bash_history.
This is not desirable for security.

$ tail ~/.bash_history
...
mysql -u root -pMyPassword
$

The most effective solution is to break the bad habit: don't enter any password on the command line. For the above example, make mysql prompt you for the password:

$ mysql -u root -p
Enter password:
mysql>

Failing that, you can mitigate the security risk by hiding a command from the command line history. Note: the technique below only works for the
bash shell.
It won't work for zsh, tcsh, etc. (If you do know the trick for these shells, please let us know through comments).

The bash trick is to enter one or more leading spaces before the actual command.

$ mysql -u root -pMyPassword

A leading blank. Just like that, and the command you enter won't be written into the command history file.

Saturday, July 12, 2014

Part 1 of this 2-part series covers x2x, a nifty software tool that lets you use the keyboard and mouse of one X terminal to control another. If you want to control more than 1 other machine, or the machines are on different platforms (Linux, Mac OS X, and Windows), Synergy is the tool.

Installation

My primary machine runs Debian 7.5 - aka Wheezy. I want to use the keyboard and mouse of this machine to control my secondary machine which runs Fedora 19. I have both good news and bad news for you - regarding installation.

First, the good news. Both the Debian and Fedora releases have included Synergy in their official package repositories. Installation is as simple as:

Now, the bad news. The 2 Synergy versions from the respective repositories, 1.3.8 for Debian Wheezy and 1.4.10 for Fedora 19, are incompatible. Starting Synergy on the secondary machine generated this error message:

2014-07-09T20:33:52 WARNING: failed to connect to server: incompatible client 1.3
You're using different versions of synergy on the client and server. You should use the same version on all systems.

The solution I recommend is to download the latest stable release - 1.5.0 at the time of writing - directly from the Synergy download site.

Setup

First, configure Synergy on the primary machine. Then, the secondary machine. The setup procedure is as follows:

Run Synergy.

You will ﬁnd the Synergy program under the Accessories menu for Debian GNOME, and
Applications/Utilities for Fedora KDE.

Synergy Premium or not.

Synergy Premium is the non-free version. Not interested.

Specify Server or Client.

For the primary machine - the one with the keyboard and mouse that you want to use - select Server.
Select Client for the secondary machine.

Enable Encryption.

After you click Finish, which screen to display next depends on whether you selected Client or Server.

Configure Server (For primary machine only).

The following screen is displayed for configuring the primary machine.

Click Configure Server.

By default, the grid contains a single node labeled with the hostname of the primary machine ('panther').
Double click the node to edit its settings.

Optionally, enter a new Screen Name, say 'Desktop'. Then, add the hostname ('panther') as an alias.

Next, add a new node representing the secondary machine to the grid. Drag the monitor icon, and drop it at the grid location relative to how it is physically positioned with respect to the primary machine. In my case, the secondary machine is located to the left of the primary machine.

Edit the still unnamed secondary machine. Give it a meaningful screen name. Add the hostname as the alias.

Configure Client (For secondary machine only).

Specify the IP address of the Server (the primary machine).

Click Start.

This starts the actual Synergy Server - or Client - program using the latest configuration data.

Now, you can slide the mouse of the primary machine to the left, crossing the left edge, and into the screen of the the secondary machine. You can return to the primary machine by sliding the mouse to the right, crossing the right edge.

Auto-starting Synergy

Instead of manually launching Synergy, you can set up auto-start for Synergy like any other X application. For GNOME 3, execute the command gnome-session-properties to bring up the Startup Applications Preferences app. For KDE 4, follow this chain of menus: Applications / Settings / System Settings / System Administration / Startup and Shutdown.

Thursday, July 3, 2014

I have a desktop and a laptop on my workstation, side by side. No KVM switch. Each has its own display, mouse, and keyboard.
I thought I could always slide over to use the other computer. Wishful thinking at its finest.

I started investigating KVM options. I like the idea of having both displays visible simultaneously. Therefore, the final solution only needs to share the mouse and the keyboard. Part 1 of this 2-part series focuses on x2x, a software KVM solution for 2 computers. Part 2 is on Synergy, a software KVM solution that supports more than 2 computers.

My primary machine is the desktop which runs Debian 7.5 (aka Wheezy). With x2x, I use the desktop's keyboard and mouse to control my secondary machine, the laptop which runs Ubuntu 12.04 (aka Precise Pangolin).

Installation

You only need to install x2x on the secondary machine, the one whose keyboard and mouse you are NOT using.

Before the install, verify that the X Server on your secondary machine supports the XTEST extension.

$ xdpyinfo -ext XTEST |grep XTEST
XTEST
XTEST version 2.2 opcode: 141

If the secondary machine runs on a recent Debian or Ubuntu release, the install is as easy as:

$ sudo apt-get install x2x

Unfortunately, recent Fedora and other Red Hat-based distributions do not pre-package x2x in their official repositories. This is not totally surprising because x2x is currently not being actively developed. Its most recent release was back in 2003. Part 2 of this series introduces an alternative tool named Synergy that works for Fedora.

If you are successful in installing x2x on a recent Fedora release, please share your experience by leaving a comment.

Setup

Before you run x2x, verify that X forwarding over SSH is enabled on the secondary machine. Specifically, the /etc/ssh/sshd_config file on that machine must contain the following line:

My secondary machine is placed to the left of my primary, hence -west. When the mouse crosses the left edge of the primary display, the mouse pointer slides over to the secondary display. From there, when the mouse crosses the right edge of the secondary display, the mouse pointer slides back to the primary. Depending on the relative machine location, you can specify instead -north, -south, or -east.

Now, the two X displays are virtually integrated. Move the mouse of your primary display to the left, crossing the left edge. Notice that the mouse pointer lands in the secondary display. Any keystrokes you enter with the keyboard of the primary display appear inside a window on the secondary.

x2x is not currently under active development. But if your task is to share the keyboard and mouse between 2 Debian-based systems, x2x is a simple and effective solution. If you have more than 2 computers to share, or the computers are non-Debian, or even non-Linux (Mac OS X, Windows), consider using Synergy which is explained in the next post.