Skip to content

Instantly share code, notes, and snippets.

@jfrost
Created February 3, 2015 18:30
Show Gist options
  • Save jfrost/26a489527de00a0b14e4 to your computer and use it in GitHub Desktop.
Save jfrost/26a489527de00a0b14e4 to your computer and use it in GitHub Desktop.
How to make a sha512sum for use in /etc/shadow in python
#!/usr/bin/python
import crypt
import random
import string
def getsalt(mysalt = "", chars = string.letters + string.digits):
# generate a random 16-character 'salt'
for i in range(16):
mysalt = mysalt + random.choice(chars)
return mysalt
salt="$6$" + getsalt()
cleartextpassword = raw_input('New password: ')
print crypt.crypt(cleartextpassword, salt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment