Skip to content

Latest commit

 

History

History
293 lines (243 loc) · 11.6 KB

File metadata and controls

293 lines (243 loc) · 11.6 KB

On encryption

(copied verbatim from http://www.madboa.com/geek/openssl/#encrypt mostly as a mirror if the site ever goes down)

Note: the site has very interesting information on openssl, encryption, keys etc you should definitely check it out

Encryption/Decryption

How do I base64-encode something?

Use the enc -base64 option.

$ openssl enc -base64 -in file.txt

$ openssl enc -base64 -in file.txt -out file.txt.enc

It’s also possible to do a quick command-line encoding of a string value:

$ echo “encode me” | openssl enc -base64 ZW5jb2RlIG1lCg==

Note that echo will silently attach a newline character to your string. Consider using its -n option if you want to avoid that situation, which could be important if you’re trying to encode a password or authentication string.

$ echo -n “encode me” | openssl enc -base64 ZW5jb2RlIG1l

Use the -d (decode) option to reverse the process.

$ echo “ZW5jb2RlIG1lCg==” | openssl enc -base64 -d encode me

How do I simply encrypt a file?

Simple file encryption is probably better done using a tool like GPG. Still, you may have occasion to want to encrypt a file without having to build or use a key/certificate structure. All you want to have to remember is a password. It can nearly be that simple—if you can also remember the cipher you employed for encryption.

To choose a cipher, consult the enc(1) man page. More simply (and perhaps more accurately), you can ask openssl for a list in one of two ways.

$ openssl -h

$ openssl list-cipher-commands

After you choose a cipher, you’ll also have to decide if you want to base64-encode the data. Doing so will mean the encrypted data can be, say, pasted into an email message. Otherwise, the output will be a binary file.

$ openssl enc -aes-256-cbc -salt -in file.txt -out file.enc

$ openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc

To decrypt file.enc you or the file’s recipient will need to remember the cipher and the passphrase.

$ openssl enc -d -aes-256-cbc -in file.enc

$ openssl enc -d -aes-256-cbc -a -in file.enc

VirtualBox

VirtualBox on Mac

Install Virtualbox’s Guest Additions first.

mounting shared folders inside the virtual Linux instance.

Virtualbox’s automount is broken. To reliably share folders between the host and the guest operating systems:

  • Mark the folders you want to share in the VM’s settings, but don’t choose auto-mount.
  • Start the VM.
  • Add the following line to /etc/fstab Documents /media/Documents vboxsf uid=1000,gid=1000,nodev,noexec,nosuid,auto,rw 0 0
  • reboot for Magic

Getting rid of piix4_smbus 0000.00.07.0: SMBus base address uninitialized

  • Check if the module is being loaded
  • blacklist it in /etc/modprobe.d/blacklist.conf by adding the following line to it:
  • Update initramfs

General notes

Mounting the Vbox root in the host machine (for fsck or other FUBAR scenarios)

If you want to mount your Vbox root partition without using Virtual Box, you might find the following commands useful :

$ sudo apt-get install qemu-kvm # Assumes you use Ubuntu as host $ sudo modprobe nbd $ sudo su

$ qemu-nbd -c /dev/nbd0 /media/Misc/ubuntu10.10-OS.vdi

$ mount /dev/nbd0p1 /mnt

Now you should be able to the see all your files in /mnt.

For fsck :

$ umount /mnt $ fsck /dev/nbd0p1

ffmpeg

Recording a full desktop screencast

Identify the max screen resolution that your system can support

xrandr

Take the top-most value

Identify the pulseaudio sound sources available to you

pactl list sources

Look for the input source alsa_input and note the source number. (eg: Source #1)

Check what the value of $DISPLAY is, you need it to capture the display

echo $DISPLAY

Record the video with the following command

ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :1 -f pulse -ac 2 -i 1 output.mkv -async 1 -vsync 1
video_size
screen resolution, taken from the output of xrandr
framerate
the framerate you want
f
video format. In this case, input format is the output of the X server (x11grab)
i
The video input, taken from output of echo $DISPLAY
f
Set expected format to be PulseAudio (pulse)
ac
Set the number of audio channels (2)
i
The audio input, taken from output of pactl
output.mkv
Output filename
async,vsync
Deprecated options. Added to avoid cluttering output log.

Converting from flac to mp3

$ ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3

Convert a webm video to mp3 audio

Youtube videos are downloaded as webm. To keep only the audio:

ffmpeg -i in.mp4 -q:a 0 -map a out.mp3

The better way to encode MP3 is to use -q:a for variable bit rate.

The q option can only be used with libmp3lame and corresponds to the LAME -V option. See Encoding VBR (Variable Bit Rate) mp3 audio: https://trac.ffmpeg.org/wiki/Encode/MP3

Cutting parts of an mp3 file

I needed to cut a 30 minute interview to only include the parts where Rani Maushi was being interviewed. ffmpeg solved the problem quickly.

Stitching the parts together to make a new mp3 file

  • ffmpeg -f concat -i parts.txt -c copy new_file.mp3
  • interview_parts.txt was in the same folder and contained the following:
    file 01_part.mp3
    file 02_part.mp3
    file 03_part.mp3
          

Speed up or slow down a video using ffmpeg

I recorded a run of dalai llama on my machine, and I want to share the recording, but since the llama is slow, it takes a long time to generate the data. I would rather cut out the empty parts of the video. To do this, I will wait for dalai to start producing data and then cut out 5 seconds after every second to speed up the demo.

This command speeds up the video 8 times. ffmpeg -ss 13 -i llama_in_action.mov -filter:v "setpts=0.125*PTS" -c:a aac -c:v libx264 02_llama_in_action.mov

To slow it down 4 times, use "setpts=4*PTS"

Convert a video to an animated gif

ffmpeg -i video.mp4 -vf scale=500:-1 -ss 30 -t 10 -r 10 image.gif
  • vf : applies a video filter, in this case scale. Here we are scaling the width to 500 and the height accordingly.
  • ss : starting point in the video, in seconds
  • t : duration of gif, in seconds
  • r : frame rate to use. here, 10 fps

Resize images using ffmpeg

ffmpeg -i 1.jpg -vf scale=480:-1 1_480.jpg ffmpeg -i 1.jpg -vf -qscale:v 5 1_qscale5.jpg

nmap

Scan for all devices connected to your network

$ sudo nmap -sn 192.168.1.0/24

PGP

Latex

Converting a PDF to a PNG (pdf-images)

  • Use poppler’s pdftoppm
    pdftoppm -png file.pdf > file.png
        

Email

How to delete email in your Notmuch / mbsync setup

  • In .mbsyncrc, set Expunge to Both for your email channels. This propagates the deletions to the mail servers when mbsync runs a sync operation.
  • List all the deleted emails
    notmuch search --output=files --exclude=false tag:deleted
        
  • Add the correct maildir flag (T to indicate Trash) to the end of the maildir files where it is missing. Ensure that the maildir file ends in the correct flags.
    • Flags are as follows
      • T : Trash
      • D : Draft
      • S : Seen
      • P : Passed (Forwarded)
      • R : Replied
    • File should end in 2,<flags> (eg: 2,ST).
  • Make sure that you are only dealing with maildir files with the correct flag information.
    notmuch search --output=files --exclude=false tag:deleted | grep "2,ST$" | wc -l
        
  • TODO : Add a step here to add the T flag to the files if it is missing.
  • Sync the files to the remote mailbox using mbsync, as you would normally do. (eg: /usr/local/bin/mbsync gmail;)
    • This will mark the files for deletion on the remote mailbox.
  • Delete the files from the local mailbox
    notmuch search --output=files --exclude=false tag:deleted | grep "2,ST$" | xargs rm