Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using this to set passwords in a script:

usermod -p `mkpasswd -H md5 passwordText` user

I need to create an exception in my script, just in case this command fails. What file contains the encrypted password and how do I reverse the encryption so I can verify it was written to the file correctly?

Edit: I finally found the problem with the line above. The password was allowing symbols that were being interpreted as wildcards on the command line making it appear as if the command itself failed. Nonetheless, it's lead me to new things I'm glad I know now.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Instead of reversing the the shadow- file, why not just do:

usermod -p `mkpasswd -H md5 passwordText` user

if [ $? -ne 0 ]; then
    echo "Changing password failed!!!!!!"
fi

You could replace whatever you want in the if block, but if a command ever fails for usermod it'll return a non-zero status.

share|improve this answer
    
I will give this a try because it sounds like it might do the trick. –  bambuntu Mar 1 '12 at 4:04

The password is stored in /etc/shadow and you can try to confirm it with john the ripper.

I am not sure if posting tutorials for john are allowed here, if so I can write one easily enough, but if not a google search will show you how.

Last I looked, John needed a patch, but the bug report on launchpad seemed to indicate that the patch was incorporated into the repos, so I would try the un-patched version first (I know, lazy =) ).

Short of john, su - test_user -> enter password.

Brief tutorial on john the ripper:

Install john

sudo apt-get install john

Prepare the working database (I made a user "test" with a weak password for this example).

sudo unshadow /etc/passwd /etc/shadow > password.db

Run john

john password.db

Loaded 2 password hashes with 2 different salts (generic crypt(3) [?/64])
Remaining 1 password hash
guesses: 0  time: 0:00:00:03 0% (2)  c/s: 222  trying: monday - emily

As you can see, john cracked the weak password in 0.03 seconds, my user password is too strong for john so I aborted it with Crtl + c

Show the password

john --show password.db

test:testing:1001:1001:,,,:/home/test:/bin/bash

1 password hash cracked, 1 left

Here we see the user "test" with the password "testing"

su test
Password: 

test@ufbt:/home/test

share|improve this answer
    
I actually not trying to crack the password, but I may be missing a description from my search on the ripper that it does simple reversals. Either way, I'm glad you brought it up. I think I could use the ripper in a script to test the passwords I'm making to improve security. It's better I understand what the black hat may use. Design based on secrets is the real threat, not an open platform that has to deal with the truth. –  bambuntu Mar 1 '12 at 4:16
    
There is nothing quite like seeing john crack your password in less then 1 second to make you appreciate strong passwords. –  bodhi.zazen Mar 1 '12 at 4:24
    
I've decided against using john at startup to create a stronger password. It would frustratingly increase boot time. –  bambuntu Mar 2 '12 at 6:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.