January 9, 2010

If you were to tell me that you have never had to create a password for any kind of electronic account I would think that you lived under a rock or didn’t have a bank account.

I don’t know about you but for me the worst part about having a password for an account is creating one. Sure there are ones that are easy to remember, but are at the same time easy to guess. Such as you birthday or your anniversary. On the flip side, there are passwords that are near impossible to “break”, but they are also damn near impossible to remember. Well I’m not going to talk about how you should go about creating a password. If you really don’t know then I suggest you spend some time on Google or even CNN and NYT.

Instead I will discuss how you can use your computer to generate pretty strong (and “random”) passwords for you.  To do this we will make use of  /dev/urandom, cat, tr, and grep.  Suppose that you must create a password that has length 8 and contains at least one of the following characters !,*,&, and #, in addition to alphanumeric characters.  Well here is what you would enter to have your system create a list of, say 4, such passwords.

cat /dev/urandom | tr -dc 'a-zA-Z0-9!*&#' | fold -w 8 | head -n 4 | grep -i '[!*&#]'

Now instead suppose that your password did not have to have one of !, *, &, or #.  Then instead you could run:

cat /dev/urandom | tr -dc 'a-zA-Z0-9!*&#' | fold -w 8 | head -n 4

In addition to using /dev/urandom you could also use /dev/random for an even more secure password. For more information on this (and other aspects) go and read this post. It should answer some, if not most, of your questions.

To lean more about head and fold just go and read their man pages.  They are pretty straight forward.

More to Kill

July 22, 2009

Well not too much new has gone on.  I’ve recently started playing around with the Bluetooth capabilities, but don’t have anything useful to say thus far.

But don’t worry I have something that might be interesting.  Though not entirely new it will combine some commands that have been previously mentioned, and make life easier.

Remember back when I first talked about kill, I said that you only had to type ps ux | less then kill <process number>. Well the only “problem” with this approach is that you have to search through the list of process to find the one that you want.  So here is a cool little trick that might help, if you know part of the process name, that uses grep.

ps ux | grep "audacity"

This will only output all the process whos “name” contains audacity.  This is pretty useful, especially if you are lazy and not in the mood to read through the rest of the rubbish.  You will still have to use kill but all the real work has been removed.

On my First Script

July 15, 2009

Well as promised it is time to explain parts of my script. Well I shall start at the beginning.  The !#/bin/bash tell the OS where the interpretor for the script can be found. The following line is just a place where most of the work will be done.  This should actually be changed to cd ~ if I were planning on sharning this script (which I am).

Now for the more “interesting” aspects.

ls -a | grep “^\.” > temp

This line will first list all the fils found in a directory (ls -a). Then it will find those that begin with a ‘.’ (dot) and print them to a file called temp.  This is done through the use of grep “^\.” grep works with regx, and in the one used here it will match ‘phrases’ that begin with a ‘.’ (dot).  Pretty much grep can do a lot of things (or so I have read) but they rely on regx so needless to say I am currently working on learning regx.  Anyway back to the code. After this I do a search to find a file called .myPw, this is where the password will be stored.  So if the file doesn’t exist we shall create it, along with a password to place into it.

After this I basically use some basic loops to test the user’s input to see if it matches the password.  I won’t talk about the loop structure since 1: this isn’t a tutorial on bash, and 2: it is easy enough to figure out from just reading the code.  I won’t explain what echo does, if you don’t know just click on the man link at the top of this blog and then click on echo.  It’s actually a pretty “simple” command.

One last thing, I would like to point out that after making the file temp I deleted it once I no longer needed it. This turns out to be somewhat optinal (I’ll explain in a moment), but I think it’s just “polite” to delete temporary files you put on someone else’s system.  Now for why this is optional.  The way the code is set up, if there already exist a file called temp it will overwrite it.  If however I had used

ls -a | grep “^\.” >> temp

It would append the output to the end of the file (in which case who knows what was in there before and how much you will have to seach through while looking for .myPw).  So there is a BIG difference between > and >>, both direct output to a file but in differnt fashions.