CentOS中管理vsftpd虛擬使用者指令碼

來源:互聯網
上載者:User

使用方法:

 代碼如下 複製代碼

[root@itchenyi-1 ~]# ./vsftpd_auto_user.py create chenyi    #建立使用者
Please input your ftpuser's password
>>:password 

[root@itchenyi-1 ~]# ./vsftpd_auto_user.py delete chenyi    #刪除使用者

[root@itchenyi-1 ~]# ./vsftpd_auto_user.py       #使用方法
warning:>> syntax error
example : ./vsftpd.py {create|disable|enable|passwd|delete} {username}
example : ./vsftpd.py create username

展示部分python代碼,如需要下載 請到本文末尾處下載,:

 代碼如下 複製代碼

#!/usr/bin/env python
#Blog : www.111cn.net

#Des : auto add,delete,enable,disable user and change user's password

import sys,os,commands
USERFILE = "/etc/vsftpd/passwd.file"
USERFILEDB = "/etc/vsftpd/ftpuser_passwd.db"
VIRTUALFILE = "/etc/vsftpd/user_config"
TEMPLATEFILE = "/etc/vsftpd/template_file"
FTPROOT = "/vsftptest"
FTPENTITYUSER = "chenyi"
SYNTAXERROR = """warning:>> syntax error
example : ./vsftpd.py {create|disable|enable|passwd|delete} {username}
example : ./vsftpd.py create usernamen"""

try:
 PARAM = sys.argv[1]
 USERNAME = sys.argv[2]
except:
 print SYNTAXERROR
 exit()

def check_username_exist():
 DESTPATH = os.path.exists(r'%s'%USERFILE)
 if DESTPATH == False:
  print "%s not exitstnnP.S:nYou can create this file to solve the problem" %USERFILE
  exit()
 else:
  EN,SN = commands.getstatusoutput("sed -n 'p;n' %s | grep -w %s | wc -l" %(USERFILE,USERNAME))
  if not(SN) == '0':
   print "User %s ALREADY exist!" %USERNAME
   exit()

可能你覺得功能還挺符合你的要求,你需要自己使用,有以下幾個地方是你需要修改的:

注意

USERFILE = 你虛擬使用者存放帳號密碼的檔案
USERFILEDB = 你db_load 產生的資料庫檔案
VIRTUALFILE = 你虛擬使用者存放設定檔的路徑
TEMPLATEFILE = 你虛擬使用者預設使用的模版設定檔,其使用者目錄需要改成chenyi,你也可以自己修改代碼
FTPROOT = 你FTP的根目錄
FTPENTITYUSER = 你虛擬使用者映射到本地的實體使用者

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.