Manage vsftpd Virtual User scripts in CentOS

Source: Internet
Author: User
Tags centos

Usage:

The code is as follows: Copy code

[Root @ itchenyi-1 ~] #./Vsftpd_auto_user.py create chenyi # create a user
Please input your ftpuser's password
>>: Password

[Root @ itchenyi-1 ~] #./Vsftpd_auto_user.py delete chenyi # delete a user

[Root @ itchenyi-1 ~] #./Vsftpd_auto_user.py # Usage
Warning:> syntax error
Example:./vsftpd. py {create | disable | enable | passwd | delete} {username}
Example:./vsftpd. py create username

Demonstrate some python code. If you need to download it, please download it at the end of this article ,:

The code is as follows: Copy code

#! /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 t:
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 ()

You may think the function meets your requirements. You need to use it by yourself. You need to modify the following:

Note:

USERFILE = the file where your virtual user stores the account password
USERFILEDB = database file generated by your db_load
VIRTUALFILE = path for storing configuration files by your virtual user
TEMPLATEFILE = the default template configuration file used by your virtual user. The user directory must be changed to chenyi. You can also modify the code yourself.
FTPROOT = your FTP root directory
FTPENTITYUSER = Your Virtual User maps to the local real user

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.