Linux System scripts Configure the FTP server

Source: Internet
Author: User
Tags stdin temporary ftp server


[Email protected] test]# vim vsftp_home.sh

#############################################
##### Date 2017-09-10
##### Name FTP server
##### Anth Joker
#############################################
#!/bin/bash
. /root/test/vsftp_function.sh
While True
Do
#clear
Cat<<-eof
*************************************
Do not repeat operations * * *
*************************************
1 Installing the FTP service
2 Configuring a temporary FTP server
3 Configuring the Enterprise FTP server
4 Configuring a virtual FTP server
5 exit
*************************************
Eof
#选择
Read-p "Please enter your choice [1-5]:" Choise
Case $CHOISE in
1)
Install_ftp
;;
2)
Install_provisional_server
;;
3)
Install_enterprise_server
;;
4)
Install_virtualaccount_server
;;
5)
Exit 520
;;
Esac
Done


[Email protected] test]# vim vsftp_function.sh

# # # #检查服务, install the service function
Install_ftp () {
Service VSFTPD Status &>/dev/null
# state1= ' Service VSFTPD status | awk ' {print $} '
Case $? Inch
0)
echo "FTP service is already installed, checking whether the service is started ..."
state1= ' Service VSFTPD status | awk ' {print $} '
if [$STATE 1 = = "Stopped"];then
/ETC/INIT.D/VSFTPD start
State2= ' service sshd status|awk-f ' [.] + "' {print $} '
if [$STATE 2 = = "Running"];then
echo "Service has started ..."
Else
echo "Please check service"
Fi
Else
echo "Service has started ..."
Fi

;;
1)
Yum-y Install VSFTPD lftp

Esac
}

# # #配置临时ftp服务器
Install_provisional_server () {
Source=/etc/vsftpd/vsftpd.conf
Sed-i ' s/#anon_mkdir_write_enable =yes/anon_mkdir_write_enable=yes/' $SOURCE
Sed-i ' s/#anon_upload_enable =yes/anon_upload_enable=yes/' $SOURCE
Chown ftp.ftp/var/ftp/pub
/bin/ls/var/ftp/xuegoddate
If [$?-ne 0];then
Mkdir/var/ftp/xuegoddate
Else
echo "already exists"
Fi
Chown Ftp.ftp/var/ftp/xuegoddate
Service VSFTPD Restart
}

# #配置系统账号FTP服务器
Install_enterprise_server () {
#添加两个账户
For i in ' cat/etc/passwd|awk-f: ' {print '} '
Do
if [$i! = "team1"];then
Useradd-s/sbin/nologin team1
echo "123456" |passwd--stdin team1
Fi
if [$i! = "Team2"];then
Useradd-s/sbin/nologin team2
echo "123456" |passwd--stdin team2
Fi
Done &>/dev/null
#配置vsftpd. conf configuration file
Source=/etc/vsftpd/vsftpd.conf
Sed-i ' s/anonymous_enable=yes/anonymous_enable=no/' $SOURCE
Sed-i ' s/#chroot_list_enable =yes/chroot_list_enable=yes/' $SOURCE
Sed-i ' [email protected] #chroot_list_file =/etc/vsftpd/[email protected]_list_file=/etc/vsftpd/[email protected] ' $ SOURCE
echo "local_root=/var/www/html" >> $SOURCE
#配置chroot_list文件
Echo-e "Team1\nteam2" >/etc/vsftpd/chroot_list
# echo "Team2" >>/etc/vsftpd/chroot_list
#查看 whether/var/www/html exists
Ls/var/www/html
If [$?-ne 0];then
Mkdir-p/var/www/html
Else
echo "already exists!! "
Fi
Chmod-r o+w/var/www/html
Service VSFTPD Restart
}

# #创建虚拟账号ftp服务器
Install_virtualaccount_server () {

#创建用户数据库
Echo-e "commuser\n123456\nvipuser\n123456" >/etc/vsftpd/vsftpd_virtualuser.txt
Which db_load
If [$?-ne 0];then
Yum Install-y db
Fi
chmod 600/etc/vsftpd/vsftpd_virtualuser.db

#配置PAM
cp/etc/pam.d/vsftpd/etc/pam.d/vsftpd. ' Date +%f '. bak
>/etc/pam.d/vsftpd
echo "Auth required/lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_virtualuser" >>/etc/pam.d/vsftpd
echo "Account required/lib64/security/pam_userdb.so Db=/etc/vsftpd/vsftpd_virtualuser" >>/etc/pam.d/vsftpd
#创建虚拟账号对应的系统账号
For i in ' cat/etc/passwd|awk-f: ' {print '} '
Do
if [$i! = "Ftpuser"];then
useradd-d/var/ftp/share Ftpuser
Chmod-r 500/var/ftp/share
Fi
if [$i! = "FTPVIP"];then
useradd-d/VAR/FTP/VIP FTPVIP
Chmod-r 700/VAR/FTP/VIP
Fi
Done &>/dev/null

#配置主文件
Source=/etc/vsftpd/vsftpd.conf
Sed-i ' s/anonymous_enable=yes/anonymous_enable=no/' $SOURCE
Sed-i ' s/local_enable=yes/local_enable=yes/' $SOURCE
echo "User_config_dir=/etc/vsftpd/vuserconfig" >> $SOURCE
echo "max_clients=300" >> $SOURCE
echo "max_per_ip=10" >> $SOURCE

#建立虚拟账号配置文件
Mkdir/etc/vsftpd/vuserconfig
Touch/etc/vsftpd/vuserconfig/commuser
Touch/etc/vsftpd/vuserconfig/vipuser
Echo-e "guest_enable=yes\nguest_username=ftpuser\nanon_world_readable_only=no\nanon_max_rate=50000" >/etc/ Vsftpd/vuserconfig/commuser
Echo-e "Guest_enable=yes\nguest_username=ftpvip\nanon_world_readable_only=no\nwrite_enable=yes\nanon_mkdir_ Write_enable=yes\nanon_upload_enable=yes\nanon_max_rate
=100000 ">/etc/vsftpd/vuserconfig/vipuser
Service VSFTPD Restart


}


This article is from the "Linux_ Little Red Hat" blog, please make sure to keep this source http://baidjay.blog.51cto.com/12582052/1964339

Linux System scripts Configure the FTP server

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.