Archive

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

Solution:
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://keys.gnupg.net --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key> from hkp server keys.gnupg.net
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 140.211.169.202  --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key>8 from hkp server 140.211.169.202
gpg: key KEYID123: public key "Julius Ceasar <julius.ceasar@example.com>" 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.

Source
https://github.com/rvm/rvm/issues/3544

Categories: bash Tags:

Ctrl + Left or Right arrow

November 17, 2016 Leave a comment

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

Solution:
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

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

$ cat -v    
# When pressing Ctrl + Left Arrow                           
^[[1;5D

# When pressing Ctrl + Right Arrow
^[[1;5C

Source:
http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2
http://invisible-island.net/ncurses/ncurses.faq.html#modified_keys (Look at the “How can I see what my keyboard sends?” section)

http://www.techrepublic.com/article/20-terminal-shortcuts-developers-need-to-know/

Categories: bash, Interesting, zsh Tags:

Change key mapping from caps lock to control key

October 29, 2016 Leave a comment

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

Solution:
Added the following to .bashrc

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

Source:
http://serverfault.com/questions/10437/how-do-you-swap-the-caps-lock-to-control-in-xfce#10537

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>

Source:
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 pgp.mit.edu --recv-keys <recipient_key_id>

2. Sending a gpg public key to a key server

gpg2 --keyserver hkp://pgp.mit.edu --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
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security_Guide/sect-Security_Guide-Encryption-GPG-Creating_GPG_Keys_using_the_Command_Line.html

Creating a new GPG key with subkeys

Categories: bash

Get colors in “less”

June 29, 2016 Leave a comment

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


Solution:

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

Source:
http://superuser.com/questions/117841/get-colors-in-less-command

Categories: bash

sshpass

May 28, 2016 Leave a comment

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

Solution:
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 (port3141.sh).

#!/bin/bash

cd /home/vagrant

export SSHPASS="vagrant"

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

3. Make it executable

$ chmod +x port3141.sh

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

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

StrictHostKeyChecking
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
“ask”.

Source:
http://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command

Categories: bash, vagrant Tags: ,