Archive for the ‘bash’ Category

encryption failed: Unusable public key

April 4, 2017 Leave a comment

Problem: gpg2 gives you an “Unusable public key” error when trying to encrypt a file.

gpg2 --output encrypted_file.gpg  --recipient <mykey> --recipient <other-guy's-key>  --encrypt file-being-encrypted.txt
gpg: <other-guy's-key>: skipped: Unusable public key
gpg: file-being-encrypted.txt: encryption failed: Unusable public key

In this case, the key had expired and needed to be refreshed.

A simple “gpg2 –refresh-keys” failed to run. So I opted to delete the key and try pull it down again.

gpg2 --keyserver hkp:// --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key> from hkp server
gpgkeys: key <other-guy's-key> can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
gpg: keyserver communications error: keyserver helper general error
gpg: keyserver communications error: Invalid public key algorithm
gpg: keyserver receive failed: Invalid public key algorithm

But when I tried again using an IP

gpg2 --keyserver  --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key>8 from hkp server
gpg: key KEYID123: public key "Julius Ceasar <>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Turns out that I need to update my gpg
For mac

$ brew upgrade gpg2

And now gpg2 works as expected without any issues.


Categories: bash Tags:

Ctrl + Left or Right arrow

November 17, 2016 Leave a comment

A colleague introduced me to using “Option + Left” shortcut on OSX. I’d like to set this up on my debian box.

Option/Alt + Left or Right

This shortcut allows you to move the cursor between separate words in a command line. Use Option and the left arrow to move back and use Option with the right arrow to move forward down the line.

I’ll be using “Ctl + Left” to move back and “Ctl + Right” to move forward between separate words.

For bash:
Add the following to .inputrc

"\e[1;5D": backward-word
"\e[1;5C": forward-word

For zsh:
Add this to .zshrc

bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word

To find out what is being sent by the keyboard. Type Ctrl + C to quit.

$ cat -v    
# When pressing Ctrl + Left Arrow                           

# When pressing Ctrl + Right Arrow

Source: (Look at the “How can I see what my keyboard sends?” section)

Categories: bash, Interesting, zsh Tags:

Change key mapping from caps lock to control key

October 29, 2016 Leave a comment

I needed to remap my caps lock key to be ctrl for tmux key bindings. Now I can use capslock + a instead of ctrl + a.

Added the following to .bashrc

$ /usr/bin/setxkbmap -option "ctrl:nocaps"


Categories: bash Tags: ,

apt-get notes

September 26, 2016 Leave a comment

A nice summary of some apt-get commands.

# Installs the selected package from repositories listed in
# /etc/apt/sources.list
$ apt-get install <package>

# Installs the selected package from repositories listed in
# /etc/apt/sources.list
$ apt-get install <package>

# Removes the selected package from your system
$ apt-get remove <package> 

# Updates the list of packages available on the repositories listed in
# /etc/apt/sources.list
$ apt-get update

# Installs the latest available versions of all your installed software
$ apt-get upgrade

# Installs the latest available software related to your configuration
$ apt-get dist-upgrade 

# Restarts/Starts the configuration script inside the package, 
# which will bring up the menu-based dialogs in the same way as after installation
$ dpkg-reconfigure

# Prints detailed information about the software package
$ apt-cache show <package> 

# Prints information on the installed software package
$ dpkg -l <package>

# Lists all files installed by the software package
$ dpkg -L <package>

# Installs a local (.deb) file to your system
$ dpkg -i <file>

# Prints information about the software package owning <file>
$ dpkg -S <file>

# Searches apt database for packages containing <string> in their 
# name and description
$ apt-cache search <string>

OpenVPN: Building and Integrating Virtual Private Networks

Categories: bash, debian, notes Tags: ,

GPG notes

September 22, 2016 Leave a comment

GPG Notes

1. Getting a gpg public key
You need to know the recipients key id

gpg2 --keyserver --recv-keys <recipient_key_id>

2. Sending a gpg public key to a key server

gpg2 --keyserver hkp:// --send-keys <key_id>

3. Encrypt a file (I locked myself out doing this. So if you want to read that file again later use the other option below)

gpg2 --output file.txt.gpg --sign --encrypt --recipient <recipient_key_id> 
--recipient <recipient_key_id> file.txt

4. Encrypt a file that you would later want to decrypt

gpg2 --output file.txt.gpg --sign --encrypt --recipient(yourself) <your_key_id> 
--recipient <recipient_key_id> --recipient <recipient_key_id> file.txt

More reading

Creating a new GPG key with subkeys

Categories: bash

Get colors in “less”

June 29, 2016 Leave a comment

When piping tree output through less, the colors are not displayed.


$ tree -C | less -R

man tree

-C Turn colorization on always, using built-in color defaults if the LS_COLORS environment variable is not set. Useful to colorize output to a pipe.

man less

R Repaint the screen, discarding any buffered input. Useful if the file is changing while it is being viewed.


Categories: bash


May 28, 2016 Leave a comment

Once again, portforwarding port 3141 on one vagrant box, to point to a local devpi-server running on another vagrant box has gotten tiring. I need to be able have this functionality on any vagrant box I provision.

Moved the command to a script. This may not be a secure way of doing this, but it suffices for now as this is only for local development work. This is not intended for work on remote production or staging servers.

1. Install sshpass

$ sudo apt-get install sshpass

2. Put the command in a script file (


cd /home/vagrant

export SSHPASS="vagrant"

sshpass -e  ssh -L 3141: -o LogLevel=Error -o StrictHostKeyChecking=no vagrant@

3. Make it executable

$ chmod +x

4. Now everytime I need to port forward I simply open up a separate tmux window and run the script.

Only changing StrictHostKeyChecking because of my frequency of using a new box. Change with caution.

If this flag is set to “yes”, ssh(1) will never automatically add host keys to the ~/.ssh/known_hosts file, and refuses to connect to hosts whose host key has changed. This pro‐
vides maximum protection against trojan horse attacks, though it can be annoying when the /etc/ssh/ssh_known_hosts file is poorly maintained or when connections to new hosts are
frequently made. This option forces the user to manually add all new hosts. If this flag is set to “no”, ssh will automatically add new host keys to the user known hosts files.
If this flag is set to “ask”, new host keys will be added to the user known host files only after the user has confirmed that is what they really want to do, and ssh will refuse to
connect to hosts whose host key has changed. The host keys of known hosts will be verified automatically in all cases. The argument must be “yes”, “no”, or “ask”. The default is


Categories: bash, vagrant Tags: ,