Created
November 29, 2009 19:39
-
-
Save cvonkleist/245033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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