码迷,mamicode.com
首页 > 其他好文 > 详细

Centos小脚本(sftp)

时间:2017-06-30 01:01:52      阅读:177      评论:0      收藏:0      [点我收藏+]

标签: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()

 

Centos小脚本(sftp)

标签:import   read   mod   chown   shu   centos   bsp   text   pre   

原文地址:http://www.cnblogs.com/chimeiwangliang/p/7096756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!