CentOS 6.x yum安装与配置vsftp服务器(带自动安装shell脚本)

#!/bin/bash
 
# -------------------------------------------------------------------------------
# Filename:    vsftpd.sh
# Revision:    1.0
# Date:        2013/04/18
# Author:      三木
# Email:       linmaogan#gmail.com
# Website:     www.3mu.me
# Description: 安装vsftpd
# Notes:       需要切换到root运行,版本针对64位系统,操作系统为CentOS6.3
#            
# -------------------------------------------------------------------------------
# Copyright:   2013 (c) 三木
# License:     GPL
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Nagios);
#
# Credits go to Ethan Galstad for coding Nagios
# If any changes are made to this script, please mail me a copy of the changes
# -------------------------------------------------------------------------------
#Version 1.0
#2013-04-18 三木 初始版本建立
#Version 1.1
# -------------------------------------------------------------------------------

#变量设置#############################################################################
FTP_USER="ftpUser" 
FTP_DIR="/www/wwwroot/web/test" 


#解锁系统文件#########################################################################
chattr -i /etc/passwd 
chattr -i /etc/group
chattr -i /etc/shadow
chattr -i /etc/gshadow
chattr -i /etc/services
#安装vsftp############################################################################
yum -y install vsftpd
# rpm -Uvh http://mirrors.163.com/centos/6/os/x86_64/Packages/vsftpd-2.2.2-11.el6_3.1.x86_64.rpm

#开启防火墙
/sbin/iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart

#修改vsftp配置文件####################################################################
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

sed -i 's/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf
sed -i 's/#chroot_list_enable=YES/chroot_list_enable=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/#chroot_list_file=\/etc\/vsftpd\/chroot_list/chroot_list_file=\/etc\/vsftpd\/chroot_list/' /etc/vsftpd/vsftpd.conf
#sed -i 's/#idle_session_timeout=600/idle_session_timeout=600/' /etc/vsftpd/vsftpd.conf
#sed -i 's/#async_abor_enable=YES/async_abor_enable=YES/' /etc/vsftpd/vsftpd.conf
#sed -i 's/#ascii_upload_enable=YES/ascii_upload_enable=YES/' /etc/vsftpd/vsftpd.conf
#sed -i 's/#ascii_download_enable=YES/ascii_download_enable=YES/' /etc/vsftpd/vsftpd.conf
#sed -i 's/#chroot_local_user=YES/chroot_local_user=NO/' /etc/vsftpd/vsftpd.conf

#其它设置##############################################################################
# 添加ftp用户组
groupadd ftp

# 创建用户目录
mkdir -p $FTP_DIR
adduser -d $FTP_DIR -g ftp -s /sbin/nologin $FTP_USER

# 给用户设置密码,程序运行中会提示手动输入密码
passwd $FTP_USER

# 修改目录属性
chmod -R 777 $FTP_DIR
chgrp -R ftp $FTP_DIR

# 限制用户目录,不得改变目录到上级
touch /etc/vsftpd/chroot_list 
echo $FTP_USER > /etc/vsftpd/chroot_list

# 设置开机自动启动并重新启动vsftpd
chkconfig vsftpd on
service vsftpd restart

#系统文件加锁
chattr +i /etc/passwd        
chattr +i /etc/shadow
chattr +i /etc/gshadow
chattr +i /etc/group
chattr +i /etc/services

参考资料:
http://www.cnblogs.com/wycc/archive/2012/10/10/2718612.html
http://blog.csdn.net/open520yin/article/details/8744650
http://blog.phpcxz.com/2012/10/centos6_vsftpd.html
http://www.myxzy.com/post-349.html

发表评论?

0 条评论。

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据