Monday, July 28, 2014

Mix and match stable and testing releases in Debian

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.

  1. Add testing to sources.list.

    The file /etc/apt/sources.list specifies the software releases you want and where to fetch them.

    Assuming that your sources.list file currently links to Wheezy only, it should resemble something like the following, notwithstanding the actual mirror site.

    deb http://deb.vanvps.com/debian/ wheezy main contrib non-free deb http://security.debian.org/ wheezy/updates main deb http://deb.vanvps.com/debian/ wheezy-updates main

    Append the following line to the file:

    deb http://deb.vanvps.com/debian/ jessie main contrib non-free
  2. Specify install priority preferences.
    • Create the file /etc/apt/preferences if it does not exist.

      This file specifies the priority preferences of which Debian version (e.g., testing vs stable) to install for packages.

    • Insert the following lines.
      Package: dateutils Pin: release n=jessie Pin-Priority: 750 Package: * Pin: release n=wheezy Pin-Priority: 700 Package: * Pin: release o=Debian Pin-Priority: -10

      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.

  3. Update APT repository.
    $ sudo apt-get update
  4. 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

How to change window manager for GNOME

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.

$ sudo apt-get install wmctrl $ wmctrl -m Name: Metacity Class: N/A PID: N/A Window manager's "showing the desktop" mode: N/A

The above output tells us that Metacity is the current window manager.

The procedure to change the window manager is:

  1. Choose a new window manager, say Mutter.
  2. Install the new window manager.
    $ sudo apt-get install mutter
  3. Change window manager.

    If you just want to try out the window manager, then execute the following command in your desktop environment:

    $ mutter --replace &

    The window manager is switched on-the-fly. However, Mutter does not persist after logging out. When you login to X, the window manager is reverted back to Metacity.

    To make Mutter your new default, create the file ~/.gnomerc like this:

    $ cat >> ~/.gnomerc export WINDOW_MANAGER=mutter

Wednesday, July 16, 2014

Hide command from bash command line history

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

Share the keyboard and mouse using Synergy - part 2/2

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:

# For Debian $ sudo apt-get install synergy # For Fedora $ sudo yum install synergy

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.
(2018-02-17 update: Synergy is no longer free. More precisely, it is no longer free to download. See pricing plan. Debian users can still download for free from official Debian repositories; Windows, macOS users need to pay.)

To install:

# For Debian $ sudo dpkg -i synergy-1.5.0-r2278-Linux-x86_64.deb # For Fedora $ sudo rpm -i synergy-1.5.0-r2278-Linux-i686.rpm

Setup

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

  1. Run Synergy.

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

  2. Synergy Premium or not.

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

  3. 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.

  4. Enable Encryption.

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

  5. 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.

  6. Configure Client (For secondary machine only).

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

  7. 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.

Command-line interface

You can launch Synergy using the command-line interface.

For the primary machine:

  1. Prepare the Synergy configuration file (~/.synergy.conf).
    $ cat > ~/.synergy.conf section: screens Laptop: Desktop1: end section: links Desktop1: left = Laptop Laptop: right = Desktop1 end section: aliases Desktop1: panther Laptop: localhost.localdomain end
  2. Start the Synergy Server.
    $ synergys -f

    The -f option means that the program is run in the foreground. The log messages are displayed in the terminal. Very useful for troubleshooting.

For the secondary machine, execute synergyc with the IP address of the primary machine:

$ synergyc -f 192.168.1.103

Thursday, July 3, 2014

Share the keyboard and mouse on two X terminals - part 1/2

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:

X11Forwarding yes

Restart the ssh daemon if you had to edit the sshd_config file.

$ sudo service ssh restart

For details on SSH X forwarding, please refer to my earlier post.

Running x2x

Execute a customized version of the following command on your primary machine, the one with the mouse and keyboard that you want to use.

$ ssh -X 192.168.1.111 x2x -west -to :0 peter@192.168.1.111's password:

The parameters to modify are:

  1. IP address

    This is the IP address of the secondary machine.

  2. Location of the secondary machine relative to the primary.

    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.