标签:import read mod chown shu centos bsp text pre
sftp用户创建,改变属组,家目录
#!/bin/python import os,sys class sftp_user(object): def __init__(self,user,passwd): self.user = user self.passwd = passwd # 改变用户的属组 def user_mod(self): for i in self.user: data = os.popen("usermod -g sftp %s"%i).read() print(data) #增加账户及设置密码 def user_add(self): connect = 0 for i in self.user: output1 = os.popen("useradd %s"%i).read() print(output1) #output = os.popen("echo ‘%s:%s‘|chpasswd"%(i,j)).read() output2 = os.popen("echo ‘%s‘ |passwd --stdin %s"%(self.passwd[connect],i)).read() connect += 1 print(output2) #删除用户及家目录 def user_del(self): for i in self.user: output = os.popen("userdel %s"%i).read() os.popen("rm -rf /home/%s"%i) print(output) def fill_create(self): pass #改变用户家目录及改变权限 def fill_chown(self): for i in self.user: os.popen("usermod -d /mnt/ftp/chinaflux/tongliangshuju-2-jieguo/%s %s"%(i,i)) os.popen("chown %s:sftp -R /mnt/ftp/chinaflux/tongliangshuju-2-jieguo/%s"%(i,i)) os.popen("chmod 755 /mnt/ftp/chinaflux/tongliangshuju-2-jieguo/%s"%i) user = ["arou","ailaoshan","damao""daxinganling","danzhou"] passwd = ["arou","ailaoshan","damao""daxinganling","danzhou"] abc = sftp_user(user,passwd) abc.user_add() #abc.user_del()
标签:import read mod chown shu centos bsp text pre
原文地址:http://www.cnblogs.com/chimeiwangliang/p/7096756.html