-
Notifications
You must be signed in to change notification settings - Fork 5
/
account.py
35 lines (30 loc) · 1.18 KB
/
account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding:utf8 -*-
from core import *
#----------------------------------------------------------------------------------------
#新加一个Linux账户
def add_account(server, port, username, password, account, passwd):
cmd_user = "useradd %s" % account
cmd_pass = "echo \"%s:%s\" | /usr/sbin/chpasswd" % (account, passwd)
check = "cat /etc/passwd | grep %s" % account
cmds = []
cmds.append(cmd_user)
cmds.append(cmd_pass)
cmds.append(check)
ret = execute(server, port, username, password, cmds)
return ret
#----------------------------------------------------------------------------------------
#删除Linux账户
def del_account(server, port, username, password, account):
cmd = "userdel -f %s" % account
cmds = []
cmds.append(cmd)
ret = execute(server, port, username, password, cmds)
return ret
#----------------------------------------------------------------------------------------
#修改密码
def modify_pass(server, port, username, password, account, newpasswd):
cmd_newpass = "echo \"%s:%s\" | /usr/sbin/chpasswd" % (account, newpasswd)
cmds = []
cmds.append(cmd_newpass)
ret = execute(server, port, username, password, cmds)
return ret