Connecting Kindle Fire HD to Debian 7

“Because of my poor patch of moorland I can never produce crops to compete with my neighbour’s, ought I remain arms folded?”
Paul Sabatier Modernism: the Jewett Lectures 1908
Santa came and left exactly one Kindle Fire HD 7 per child, there were two, went about his merry way, never again to lose a thought about the father, the mother, the two children or the Kindles.
Not the first order of business, but certainly pretty high on the list was connecting a Kindle to a Debian 7 PC. Kindle Fire doesn’t support USB, but instead uses MTP (Media Transfer Protocol) for automatically transferring data to its media. MTP has several drawbacks, some of which are no parallelization, no multi-tasking and it doesn’t support direct modification of data. But the biggest drawback is that MTP devices are not treated as traditional removable disks. The file system is implemented by the device and not by the operating system, which means that most software will not recognize a MTP device.
libmtp ( and thanks very much for that) offers a MTP implementation for POSIX based operating systems. libmtp is really just a C library and it comes with a set of example programs which allow you to do anything imaginable with your MTP device.  A FUSE (Filesystem in User Space) filesystem which supports reading and writing to a MTP device is also required. This comes in the form of MTPfs ( and again thanks for that). There is also a GUI (gmtp for anybody who isn’t console enamored.
All that is left is to run through an installation and mount the device.
  1. Add the Debian backports
    echo “deb wheezy-backports main” >> /etc/apt/sources.list
    # apt-get update
  2. Install the software
    # apt-get install libmtp9 mtp-tools jmtpfs gmtp
  3. Connect the kindle
    Sounds silly but the kindle has to be connected and logged on.
  4. Mount the device
    # mtp-detect
    # jmtpfs -o allow_other /mnt

That’s it.  When the device is to be unmounted.

  1. Unmount the Kindle
    # fusermount -u /mnt

Of course, once the software has been installed, there is the GUI option.  Although the GUI does offer an exercise in patience, as it tends to lag and it takes a 30 or 40 seconds before the device becomes visible, it is far easier and more intuitive to use than the console.

Public Domain Mark

A random assortment of helpful shell commands/scripts.

“It lies in the power of every man, either permissively to hasten, or actively to shorten, but not to lengthen or extend the limits of his natural life. He only (if any) hath the art to lengthen his taper, that put it to best advantage.”
Francis Quarles

Here are some nifty command line scripts which come in handy:

  1. Show the lines in a file which are uncommented and not empty
    grep -E -v “#|^$” file
    or alternatively (just to use sed)
    grep -E -v “#” | sed ‘/^$/d’
  2. Create 10 txt files
    touch test{0..9}.txt
  3. Move all txt files to bak files
    for i in *txt
    j=`echo $i | sed ‘s/txt/bak/’`
    mv $i $j
  4. Find out who is using the most disk space
    du -hs /home/* | sort -n
  5. Selecting the most recent file in a directory
    ls -rt | tail -1
  6. Excluding the grep command from ps aux
    Lets say you want to grep the process list for all vi processes. The resulting list  will contain the grep command itself. To avoid this use
    ps aux | grep [v]i
  7. Compare the differences between a remote & local file
    ssh user@server cat remote.txt | diff -y local.txt –
  8. Quickly create a dated backup
    Firstly create an alias in your .bashrc
    echo “alias d=’date +%F” >> .bashrc
    Restart your terminal & try
    mv file.txt{,.$(d)}
  9. Quickly remove all whitespace
    cat file.txt | sed ‘s/\s\+//g’
  10. Columnize output
    column -s : -t /etc/passwd
    would format passwd in columns using : as a delimiter.
  11. Get the total weight of certain files in a directory
    du -hc *txt
    ls -al *txt | awk ‘{ print; total += } END { print total / 1.024e+9 }’
  12. Count any number of lines before or after a search match
    egrep -A 15 test testytest.txt
    Provides the next 15 lines after the match.
    egrep -B 15 test testytest.txt
    Provides the 15 lines before the match.
  13. List services running on a machine
    netstat -nptl | egrep ‘^tcp’ | awk ‘{if($7!=”-“){print $7}}’ | cut -d/ \ -f2 | sort -u
  14. How much RAM does a machine have?
    egrep ‘MemTotal’ /proc/meminfo | awk ‘{print $2/1024, “MB”}’
  15. How many disks does a machine have?
    fdisk -l 2>/dev/null | egrep ‘/dev/(s|xv)d[a-z]:’ | \
    awk ‘{count++}END{print count}’

Public Domain Mark

Standardizing a personal work environment over multiply ssh servers.

“As if the finest and most manly of spectacles were not that of a man who conquers his soul hour after hour, fighting first against himself, against the suggestions of egoism, idleness, discouragement…”
Paul Sabatier “The Life of St. Francis of Assisi”

A system administrator will generally, during a normal day, work on more than one server . It is very helpful if certain settings (a personal working environment or PWE) and changes to these settings travel without any effort from server to server. OpenSSH offers a novel but effective approach of achieving just this. This article is concerned with describing experiences made with Debian Wheezy and its openssh-server (1:6.0p1-4+deb7u2).

The Principle
A client defined shell variable will be filled with the files which make up the personal environment (in this case .vimrc and .bashrc) and then passed to the server, which in turn will per shell script decode the variable and place the files in the appropriate user home directory.

The Preparations (The Client)
To simplify the creation of the shell variable ($PWE) a directory  ~/personal_work_envir is created. The files .bashrc and .vimrc are copied to this directory.

  • client: $ mkdir ~/personal_work_envir
  • client: $ cp -v ~/{.bashrc,.vimrc} ~/personal_work_envir

To create the shell variable $PWE the following line is added to ~/.bashrc

  • export PWE=$(tar -C ~/personal_work_envir -cz .| base64)

Finally the directive SendEnv is added to ~/.ssh/config.

  1. Host server
  2.     SendEnv PWE

The Preparations (The Server)
The shell script /etc/sshrc is invoked by the ssh server for every incoming ssh connection. A similar script namely ~/.ssh/rc can be defined for individual users. If this script exists it overrides /etc/sshrc but like /etc/sshrc,  it is executed before the shell or any remote command requested by the incoming connection. Unlike /etc/sshrc which is always executed by /bin/sh, the ~/.ssh/rc should be executed by the user’s normal login shell. Generally speaking /bin/bash. The ~/.ssh/rc script should look as follows:

  1.   #!/bin/bash
  2.   # unpack the personal work environment
  3.   if test “$PWE” ; then
  4.               echo “$PWE” | base64 -d | tar -xzC ~
  5.   fi

Now it only remains to ensure that the server accepts the client defined variable. This is achieved by adding the following entry to the sshd configuration /etc/ssh/sshd_config

  • AcceptEnv PWE

Public Domain Mark