O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



Simple insecure hack for saving passwords
A quick bash script I use to recall non-vital passwords.

Contributed by:
bremac
[05/11/05 | Discuss (0) | Link to this hack]

Caution: This is just a simple hack, and should only be considered as safe as saving passwords on the filesystem in any other circumstances.

I often end up saving non-vital passwords in ~/passlist, (never anything which I would mind losing), but I hate having to look them up. I save them in a format <passname>: <password>. This is great, but browsing, or even grepping this is annoying. The solution? Use bash and regex.

First, I just rigged up a simple grep script:

#!/bin/bash
#pwlst.sh - Grep's ~/passlist for the
# only passed argument
grep "$1" ~/passlist

This works, but leaves the entering the password to me, for example with ssh -l. Because I'm a bit lazy, I added some more processing to it - run it through sed, and cut everything but the password. This is done with a simple sed "s/$1: //", to give us a script which we can easily pipe output from to a login, for example pwlst.sh <name> | ssh -l.

#!/bin/bash
#pwlst.sh - Grep's ~/passlist for the only
# passed argument, then cuts out the name.
grep "$1" ~/passlist | sed "s/$1: //"

As you can see, chaining grep to sed can do the work of many other commands - learning regex can even replace many other commands.

See also:


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.