python程序 添加具有root权限的 linux 用户
#! /usr/bin/env python# This Python file uses the following encoding: utf-8''''Created on 2012-9-28@author: zero'''import os,crypt,sysif len(sys.argv)<3:print("usage: python %s test11 test
·
#! /usr/bin/env python
# This Python file uses the following encoding: utf-8'
'''
Created on 2012-9-28
@author: zero
'''
import os,crypt,sys
if len(sys.argv)<3:
print("usage: python %s test11 test11\n" %(sys.argv[0]))
sys.exit() #退出程序
else:
username=sys.argv[1]
os.system("useradd -o -u 0 -g 0 %s" %username) #新加一个root权限的用户
passwd=crypt.crypt(sys.argv[2],"ab") #将密码加密转换输出
#print "passwd=%s\n" %passwd
cmd='usermod -p %s %s' %(passwd,username) #修改指定用户的密码
#print "cmd=%s\n" %cmd
os.system(cmd);
print("Congratulation! add user %s:%s successed!\n" %(username,sys.argv[2]))
sys.exit() #退出程序
更多推荐
已为社区贡献13条内容
所有评论(0)