#!/usr/bin/python import commands import sys plainpass = sys.argv[1] command = "echo %s | openssl passwd -1 -stdin" %plainpass crypted = commands.getoutput(command) # print "Hash is: " + crypted f = open('/mnt/etc/shadow', 'r') lines = f.readlines() f.close() f = open('/mnt/etc/shadow', 'w') for x in lines: if x.startswith("root:"): f.write("root:%s:13474:0:99999:7:::\n" %crypted) else: f.write("%s" %x) f.close()