Press "Enter" to skip to content

Creating and Storing Passwords Securely

I had a quick google to see how people are creating/storing their passwords and
couldn’t find anything that quite matched how I do it, so I thought I’d share my
method here.

Step 1. Create Password

tr -cd '[:graph:] ' < /dev/urandom | fold -w100 | head -n1

How it Works:

  • tr takes an input from /dev/urandom and picks out all the graphical characters
    plus the spaces (note the space before the closing quotation mark).
  • fold formats the output so that a line is 100 characters wide. For passwords of a
    different length change the number after w
  • head gives us the first line (our password)

Step 2. Storing Passwords

So now you have a password that is very secure, but quite impossible to remember.
You’ll want to save the passwords you create somewhere, but never store passwords
unencrypted! I like to use gpg with aes to encrypt my files. On my system the
default cipher was CAST5 so to use aes you may need to add this line to the end of
your ~/.gnupg/gpg.conf file

cipher-algo AES256

To encrypt a file do

gpg -c yourfile

This creates a new encrypted file which you can safely upload to your favourite file
hosting service in case of of hard drive failure. Choose a strong password to encrypt
your password file! You can decrypt by clicking on the file in your file manager or by
using the command

gpg yourfile