Setting up DKIM Keys for CPanel Server in DNSMadeEasy

I am in the middle of a server migration and am working on DKIM keys for the domains on the affected server. I ran into an issue where the DKIM key data I was getting from CPanel wasn’t working when trying to use it in a txt field DNS record on DNSMadeEasy. I contacted their tech support and figured I’d post the solution here since I couldn’t find it elsewhere and since their documentation on the matter is so sparse.

The key info I was getting from DNSMadeEasy was:

"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7jLS6S0MF4kJFyJOyE4Tm/Dv583oUGkUjbBa9CXWLrP4IYoamSrTqBiOQuXsbKw0yCObgDrJ844hH+yIFlTkw0FlKx/B706fEGPr7DL8L6mdicqZX1fbVqLs7GsX9OE0FOm1rUsr/eHQPug4F2JQ5yNDtjK0Jt07pYEpf6wWxY0HMNtq4oKwU3MBwgfsVx9Xs" xdDYMvs0vtVR2WQD1LAxgL20hWOPtZZ6QwhZhBFpHOuiN4WACSnGDtZhHE6Mxwy642eImQtsFjnJrIe1t0HT/dP2r5B7ptkk8ZgLbH8eiI2VY7GIV7g58sJTL86xvkYLrMXcWjow2L2Ho+MKivmawIDAQAB\;

Upon trying to put this into a txt field entry on DNSMadeEasy I would receive the following error:

Value contains mismatched quotes. All beginning quotes must have a corresponding terminating quote.

After fiddling with the quotes to make sure there were matched pairs, I would get this error:

Contiguous strings may not be longer than 255 characters

I contacted support and they informed me that by the standard, txt fields can’t have continuous strings longer than 255 characters, but can contain multiple strings. By the DKIM standard, any strings found are concatenated before being interpreted.

I broke the string up with double quotes into lengths of less than 255 in a text editor and made sure there were good matching pairs. I also removed the slash and semicolon at the end, as those don’t appear to have been necessary or helpful.

In the end I wound up with a txt record called default._domainkey.[domain] containing:

"v=DKIM1; k=rsa;""p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7jLS6S0MF4kJFyJOyE4Tm/Dv583oUGkUjbBa9CXWLrP4IYoamSrTqBiOQuXsbKw0yCObgDrJ844hH+yIFlTkw0FlKx/B706fEGPr7DL8L6mdicqZX1fbVqLs7GsX9OE0FOm1rUsr/eHQPug4""F2JQ5yNDtjK0Jt07pYEpf6wWxY0HMNtq4oKwU3MBwgfsVx9XsxdDYMvs0vtVR2WQD1LAxgL20hWOPtZZ6QwhZhBFpHOuiN4WACSnGDtZhHE6Mxwy642eImQtsFjnJrIe1t0HT/dP2r5B7ptkk8ZgLbH8eiI2VY7GIV7g58sJTL86xvkYLrMXcWjow2L2Ho+MKivmawIDAQAB"

It appears to work.

Quick Tip: Enable a Paused Printer in Cups

My HP Printer sometimes has an issue where after printing once the printer becomes unavailable. In system-config-printer – it shows up as paused, using lpstat-p on the command line shows it as disabled.

In my case, at least, restarting cups did nothing to resolve the problem, though restarting the whole system has sometimes worked.

The solution I found was to useĀ lpstat -p to find the name of the printer and verify its status there. The output I got was:

printer Home disabled since Thu 11 May 2017 10:55:02 AM PDT –
reason unknown
printer PDF is idle. enabled since Mon 27 Mar 2017 02:23:42 PM PDT

The “Home” printer is the one I want to start up again, which was done with this command: cupsenable Home

Now, the lpstat-p returns the following:

printer Home is idle. enabled since Thu 11 May 2017 11:07:06 AM PDT
printer PDF is idle. enabled since Mon 27 Mar 2017 02:23:42 PM PDT

and in the system-config-printer gui, it shows as ready, and will print without issue.

Quick Tip: Fix Scroll Lock

I found on my desktop that the scroll lock key doesn’t work. I’m using Ubuntu 17.04 (recently upgraded from 16.10, on which the problem also existed) with the i3 window manager and using a Logitech K120 keyboard (which seems to have this problem somewhat commonly).

All of the event signals were there, as tested by xev and other tools, but it wouldn’t actually turn on the scroll lock functionality or change the keyboard LED state.

The problem was that the key was not actually bound to that function, which is fixed by this command:

xmodmap -e 'add mod3 = Scroll_Lock'

This can be run in any number of places, including in a regular terminal for testing or temporary use. I put it in my i3 config file to run at startup each time and it works beautifully.


Quick Tip – Copying From Vim

This issue drove me insane. The answer was crazy simple so I figured I’d throw it out there.

I found that I could copy and paste anywhere in X without an issue (this uses the clipboard buffer). I could also select text and middle click to paste without issue (this uses the primary buffer. I could also select and paste with the mouse in URXVT. Within Vim, I could also copy by selecting and paste (when in insert mode) with a middle click. What I couldn’t do was select text in Vim and middle click to paste it anywhere else.

Further, I could confirm that the data wasn’t hitting the primary buffer upon selection using xsel -op to dump the primary buffer.

After a good while of searching (which came after more time than should have been spent diagnosing the exact issue) I found this thread, which described my issue and the solution.

The answer is that the mouse=a directive in my vimrc that makes visual mode work with the mouse is also keeping it from selecting text in the way that’s needed to drop it into the primary buffer (to copy it). Disabling this setting fixes the copy issue, but also turns off visual mode with the mouse, which I’d like to keep.

The workaround was to hold shift while selecting text I want to copy, which keeps it from entering visual mode and allows the copy to happen.


Startup script for i3 with Conditional Execution

I’ve been using the i3 window manager for roughly a couple of years now and have enjoyed playing with all the ways I’ve found to extend it through startup scripts, keybindings, etc. This little hack for enabling or disabling the launch of a group of applications at login is one of my favorites and I thought I’d share.

I’ve got a script in my i3 configuration directory called that fires up a number of persistent applications and launches things I normally use.

The first thing it does is load a saved layout and launch terminals with htop, dmesg –follow, and tail -f /var/log/syslog . I use this as a general system monitor workspace, a dedicated place I can go to see what’s happening on my system.

Next, it switches to a workspace I use as a dedicated terminal and launches urxvt, then switches to the workspace I use for my browser, switches the layout to tabbed, then launches my browser.

Then it loads up the scratchpad text app I use (Fromscratch), udiskie for managing removable media, the mpd daemon, and after some delay to make sure everything else is finished loading, dropbox.

I’ve been happy with this arrangement, but really wanted to find a way to keep it from launching some of those items on startup in case I wanted to do something more system intensive and didn’t need those things right away or want to do some kind of benchmarking and want fewer things tying up RAM.

Here’s the solution I found:

#load saved system monitor workspace and populate
i3-msg 'workspace "S"; append_layout ~/.config/i3/monitor3.json;'
sleep 0.25
urxvt -e "htop" &
sleep 1
urxvt -e sh -c "dmesg --follow" &
sleep 0.5
urxvt -e sh -c "tail -f /var/log/syslog" &
sleep 1

#read the current capslock state - result should be "on" or "off"
caps=`xset -q | grep Caps | awk '{ print $4 }'`

#if capslock is on at login, skip running these apps at startup
if [ $caps = off ]; then

        i3-msg 'workspace "3:>_"'
        urxvt &
        sleep 1
        i3-msg 'workspace "1:B"; layout tabbed;'
        sleep 0.5 
        google-chrome &
        sleep 10
        fromscratch &
        udiskie -s -f "/home/alex/bin/rangerwrapper" &
        mpd &
        autocutsel &
        sleep 30 #wait a while to launch dropbox so everything else can finish starting since it's a resource hog
        dropbox start &
        #Caps lock was enabled, so skip all the above after the monitor workspace and drop to the first workspace
        i3-msg 'workspace "1:B"'
        #since we got here because caps lock was on at login, simulate that keypress to toggle it off.
        xdotool key Caps_Lock

The idea here is that I can log in normally and get all my normal startup apps, or if I know I want a trimmed-down session, I can type my password to log in, then hit caps lock before hitting enter to log in. Beyond that, hopefully the comments make its function fairly clear.

It’s worth noting that I tried to do this with num lock, but discovered that while numlock is off at my login screen (lightdm with the gtk greeter), it is automatically turned on at some point as i3 starts, and before my script runs. Without figuring out how to disable that (or where it’s coming from) I can’t really use that key this way.

I also tried with scroll lock, but discovered that my scroll lock key isn’t actually tied to the scroll lock function. While I was able to fix that behavior at runtime, I couldn’t make it happen before I had a user session (tried messing with lightdm init scripts, with xinit scripts, etc, and couldn’t get it), which meant I had no way to turn on scroll lock until after I was logged in which defeated the purpose. In case it’s helpful, here’s the command that fixed scroll lock for me:
xmodmap -e "add mod3 = Scroll_Lock"

I’ve got other misc startup commands in my i3config, but those are all just adjusting settings at runtime, setting my wallpaper, etc., and indeed it’s the i3config that executes this launch script.

ThinkPad T440s Battery Warning Script for Ubuntu 16.04

Since I started with a stripped-down Ubuntu install that doesn’t include much in the way of power management I made a tool to warn me when my battery is low and to suspend the system when it is low enough. I borrowed some content and structure from this script, adding features to meet my own needs, in particular support for a second battery, notifications, and auto-suspend.

This script assumes you’ve got two batteries and will warn when both batteries are discharging or discharged (status = “unknown”) and both have remaining power below a certain threshold.

It saves status files in ~/tmp as per the TMPDIR variable at the top to keep from notifying you every minute or however often you choose to have this run. Those files are cleared when either of the batteries begins charging.

At 15% remaining a notification is given through the dbus desktop notification system. At 10% another notification is issued and a sound played. At 8% another notification is given, and a 15 second timer started, after which the system is suspended.


#get access to the dbus session for desktop notifications - must be used inconjunction with the other script run at startup to populate this file with that session information
if [ -r "$HOME/.dbus/Xdbus" ]; then
    . "$HOME/.dbus/Xdbus"


STAT1=$(cat "$DIR1/status")
STAT2=$(cat "$DIR2/status")

echo "Battery1: $STAT1"
echo "Battery2: $STAT2"

#if both batteries are either discharging or discharged (status unknown)
if [ \( "$STAT1" = "Discharging" -o "$STAT1" = "Unknown" \) -a \( "$STAT2" = "Discharging" -o "$STAT2" = "Unknown" \) ];
        REM1=$(cat "$DIR1/energy_now")
        REM2=$(cat "$DIR2/energy_now")
        FULL1=$(cat "$DIR1/energy_full")
        FULL2=$(cat "$DIR2/energy_full")
        PRCT1=$((100 * $REM1 / $FULL1))
        PRCT2=$((100 * $REM2 / $FULL2))

        echo "Power - Battery1: $PRCT1%, Battery2: $PRCT2%"

        if [ $PRCT1 -le 8 ] && [ $PRCT2 -le 8 ];
                notify-send "Battery Critical" "Suspending while there's a little juice left. You have 15 seconds."
                #you will not hear this if the sound is muted - assuming if the sound is muted it should stay that way.
                paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
                sleep 15
                sudo systemctl suspend
        elif [ $PRCT1 -le 10 ] && [ $PRCT2 -le 10 ];
                if [ ! -f $TMPDIR/battwarn10 ];
                        notify-send "Battery Low" "Remaining battery is at 10% or lower"
                        #you will not hear this if the sound is muted - assuming if the sound is muted it should stay that way.
                        paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
                        touch $TMPDIR/battwarn10
        elif [ $PRCT1 -le 15 ] && [ $PRCT2 -le 15 ];
                if [ ! -f $TMPDIR/battwarn15 ];
                        notify-send "Battery Low" "Remaining battery is at 15% or lower"
                        touch $TMPDIR/battwarn15
elif [ "$STAT1" = "Charging" ] || [ "$STAT2" = "Charging" ];
        #if the status is charging, clear the temp files
        if [ -f $TMPDIR/battwarn15 ];
                rm $TMPDIR/battwarn15
        if [ -f $TMPDIR/battwarn10 ];
                rm $TMPDIR/battwarn10
exit 0

To get this working you’ll need to do a few things. First up, make sure ~/tmp exists, or change the TMPDIR variable to a suitable location with write permissions for your user.

You’ll also need to install this script in ~/bin or another suitable location, then configure it to launch on startup (such as in an i3 config). This script creates a means for the power script to access the dbus session for desktop notifications. The script came from this answer on stack exchange.


#include the following in a script that needs access to the dbus session
#if [ -r "$HOME/.dbus/Xdbus" ]; then
#    . "$HOME/.dbus/Xdbus"


touch $FILE
chmod 600 $FILE

exit 0

To make suspend work you’ll need to run

sudo visudo

and add a line like the following

%sudo ALL = NOPASSWD: /bin/systemctl suspend

This allows all users with sudo access to run the command to suspend using sudo without a password, which means we can run it from the script without asking for a password. If you’d prefer to allow this for just your user, replace %sudo with your user name.

Lastly, you’ll need to configure your crontab to execute this script at routine intervals. I chose every two minutes.

Run the following to edit your crontab:

crontab -e

And add this line:

*/2 * * * * /home/user/bin/power_status

Of course, make sure to replace with the path to your script. If you haven’t already, make sure the script is executable by running the following on it.

chmod +x power_status


Preivew OpenOffice/LibreOffice .odt documents in Ranger File Manager

Quick tip for those that use the Ranger file manager (which is awesome, by the way).

Ranger file previews are defined in the configuration file. You can add your own preview mechanisms here.

To preview .odt documents in Ranger, you’ll need to install the odt2txt tool. On Ubuntu (and presumably other debian-based distros) install it using the following command:

sudo apt install odt2txt

The odt2txt command converts a .odt document into a text file and outputs it to standard output (prints it to the terminal or makes it available to be piped).

In your file add the following within theĀ case “$extension” block.


odt2txt “$path” && fmt -s -w $width; exit 0;

Save the file and fire up a new instance of Ranger, then select a .odt file and you should get a text preview in the right pane.

Synaptics Clickpad Configuration for ThinkPad T440s

I briefly tried an Arch Linux install on my laptop. It wasn’t my favorite for my daily use, would probably be great for a lightweight computer or a server. In any case, the default configuration (non-) settings for the clickpad were utterly unusable, and the examples I was finding didn’t have all of the features I wanted. I dug into the man pages for the driver and put together a configuration I’m happy with, and have since rolled out to my Ubuntu 16.04 install on the same machine.

These settings enable the soft-buttons at the top of the clickpad to use with the trackpoint, creates another soft-button on the right half of the bottom of the pad for right click, disables edge scrolling, enables two-finger scrolling (horizontal and vertical), and single/double/triple-finger clicking.

This file lives (in a 16.04 Ubuntu system) in /usr/share/X11/xorg.conf.d/ . I replaced the default 50-synaptics.conf file with the following contents:

Section "InputClass"
 Identifier "touchpad"
 Driver "synaptics"
 MatchIsTouchpad "on"
 MatchDevicePath "/dev/input/event*"

 Option "ClickPad" "1"

 Option "PalmDetect" "1"
 #soft buttons at top of pad
 Option "SoftButtonAreas" "60% 0 0 2400 40% 60% 0 2400"
 Option "AreaTopEdge" "2400"

 #soft buttons at bottom of pad
 Option "HasSecondarySoftButtons" "1"
 Option "SecondarySoftBUttonAreas" "50% 0 85% 0 0 0 0 0"

 Option "HorizHysteresis" "30"
 Option "VertHysteresis" "30"
 Option "FingerLow" "30"
 Option "FingerHigh" "50"
 Option "MinSpeed" "1"
 Option "MaxSpeed" "1"
 Option "AccelerationProfile" "2"
 Option "ConstantDeceleration" "4"

 Option "VertEdgeScroll" "0"
 Option "HorizEdgeScroll" "0"
 Option "TapAndDragGesture" "0"
 Option "CircularScrolling" "0"

 Option "TapButton1" "1"
 Option "TapButton2" "3"
 Option "TapButton3" "2"
 Option "ClickFinger1" "1"
 Option "ClickFinger2" "3"
 Option "ClickFinger3" "2"

 Option "VertTwoFingerScroll" "1"
 Option "HorizTwoFingerScroll" "1"
 Option "CoastingSpeed" "0"
 Option "MaxTapTime" "125"

Tray Icons Not Appearing in i3 on Ubuntu

On my laptop install of Ubuntu Server 16.04, when I first installed i3 I found that tray icons weren’t working. I tested with volti, the network manager applet, and dropbox – nothing, and no errors from the applications.

The problem was with the following line in the i3 configuration file (located at ~/.config/i3/config, formerly .i3/config in prior versions [or packages]):

tray_output primary

I suspect this would work fine if there were a primary display configured in my xorg settings, but that isn’t the case. Commenting out this line did the trick (removal would also work) after restarting i3 (shift+mod+r).