useradd/usermod -p 指定用戶密碼

老用管道去改密碼怕history記錄下來,偶爾看見usermod實際是有-p參數指定密碼的,問了度娘,終於知道怎麼用的了html

http://www.cppblog.com/aaxron/archive/2010/12/02/135251.html?opt=adminpython

用python獲得加密後字符串

# pythonlinux

Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import crypt
>>> print crypt.crypt('password','12')
12CsGd8FRcMSM

添加用戶時指定密碼

# useradd testuser -p 12CsGd8FRcMSMdom

測試

[root@ops1 ~]# su testuser
[testuser@ops1 root]$ su testuser
Password:            #輸入password
[testuser@ops1 root]$

####python腳本測試

# cat getcryptpwd.py加密

#!/usr/bin/env python

import crypt
import random

chars='AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
str=''
str += chars[random.randint(0,len(chars))]
str += chars[random.randint(0,len(chars))]

pw=raw_input("Please Enter Password:")
cryptpw=crypt.crypt(pw,str)

print "Cryptd Password is : " + cryptpw
相關文章
相關標籤/搜索