Skip to content

Instantly share code, notes, and snippets.

@cvonkleist
Created November 29, 2009 19:39
Show Gist options
  • Save cvonkleist/245033 to your computer and use it in GitHub Desktop.
Save cvonkleist/245033 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
PASS_BIN = 'pass'
SHADOW_FILE = ARGV[0]
lines = File.read(SHADOW_FILE).split("\n")
def generate_password(user)
'houdini!@#' + user
end
def salt
(1..8).to_a.collect { ('a'..'z').to_a[rand(26)] }
end
def crypt(plaintext)
%x(pass "#{plaintext}" "#{salt}")
end
STDERR.puts "THIS WILL NOT CHANGE THE ROOT PASSWROD!@#!@#!"
users = []
lines.each do |line|
user, hash, the_rest = line.split(':', 3)
# not * or !
if hash.length > 1 && user != 'root'
users << user
hash = crypt(generate_password(user))
end
puts [user, hash, the_rest] * ':'
end
STDERR.puts "\n\npasswords changed for these users: " + users.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment