vsftpd服务搭建与配置脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vsftpd服务搭建与配置脚本相关的知识,希望对你有一定的参考价值。
公司中经常会用到ftp服务,为了方便,写了一个在linux运行的脚本,希望能对大家有所帮助。
测试环境: vsftpd和ftp软件可安装在一台linux系统上。
该linux系统IP:192.168.1.10
准备工作:
配置IP地址和yum源:
#!/bin/bash date +%F_%T #交互配置IP地址和yum源 service iptables stop setenforce 0 ip=`ifconfig eth0 |grep "inet addr"| awk ‘{print $2}‘` IPA=/etc/sysconfig/network-scripts/ifcfg-eth0 read -p "请问是配置ip地址吗(y|n):" A case $A in y|Y) sed -i ‘s#ONBOOT=no#ONBOOT=yes#g‘ $IPA sed -i ‘s#BOOTPROTO=dhcp#BOOTPROTO=static#g‘ $IPA read -p "请输入你想要配置的IP地址:" B echo "IPADDR=$B" >> $IPA read -p "请输入你想要配置的子网掩码:" C echo "NETMASK=$C" >> $IPA /etc/init.d/NetworkManager stop service network start echo "IP配置成功" >> /true.txt ;; n|N) echo "已经配置好IP地址" >>/true.txt echo "$ip" >> /true.txt ;; *) echo "错误" >> /error.txt ;; esac #配置centos的yum源,需要做以下一步: #mv /etc/yum.repos.d/Centos-Base.repo /etc/yum.repos.d/Centos-Base.repo_bak YUM=/etc/yum.repos.d/yum.repo funcation(){ cat > $YUM<<EOF [yum] name=rhel6.5 baseurl=file:///media/ enabled=1 gpgcheck=0 EOF } umount /dev/sr0 umount /dev/sr0 mount /dev/cdrom /media/ &> /dev/null || echo "失败" >>/error.txt read -p "请问是配置yum源吗(y|n):" AA case $AA in y|Y) funcation echo "yum源配置成功" >> /true.txt yum clean all &> /dev/null yum repolist &> /dev/null ;; n|N) echo "已经配置过yum源" >>/true.txt ;; esac
1) 匿名访问的FTP服务:
安装vsftpd和ftp软件包。
#yum -y install vsftpd ftp
#!/bin/bash date +%F:%T #vsftpd configuration if [ -f /etc/vsftpd/vsftpd.conf ];then sed -i ‘s/^#anon_upload_enable=YES/anon_upload_enable=YES/‘ /etc/vsftpd/vsftpd.conf #allow anonymous users to upload files sed -i ‘s/^#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/‘ /etc/vsftpd/vsftpd.conf #allow anonymous users have write access to create the directory. else echo "Anonymous users configured or configuration failed" >>/true.txt fi chmod -R 755 /var/ftp/ #give vsftpd root directory 755 permissions service vsftpd start if netstat -anpt | grep vsftpd;then echo "21 port have been detected" else echo "The vsftpd service did not start or start to fail">>/error.txt fi
windows和linux客户机都可以访问。
在linux下访问:
# ftp 192.168.1.10
Connected to 192.168.1.10 (192.168.1.10).
220 (vsFTPd 2.2.2)
Name (192.168.1.10:root): ftp
331 Please specify the password.
Password: #没有密码,直接回车即可。
230 Login successful.
2) 用户验证的FTP服务。
系统用户验证:
#!/bin/bash date +%F:%T #The system user authentication if netstat -anpt | grep vsftpd then read -p "Now if you want to configure the system user authentication(y|n):" Q case $Q in y|Y) sed -i ‘s/^anonymous/#anonymous/‘ /etc/vsftpd/vsftpd.conf echo -e "anon_root=/var/yuan" >> /etc/vsftpd/vsftpd.conf sed -i ‘22s/022/077/‘ /etc/vsftpd/vsftpd.conf sed -i ‘s/^#chroot_local_user/chroot_local_user/‘ /etc/vsftpd/vsftpd.conf userdel -r axy &>/dev/null useradd -d /var/yuan xy echo "123" | passwd --stdin xy service vsftpd restart #Restart the service ;; n|N) echo "Exit the script, and end users of the system configuration," break ;; *) echo "Input is not correct, please input again" ;; esac else echo "Not running FTP service, please restart your service." fi
系统用户验证:
# ftp 192.168.1.10
Name (192.168.1.10:root): axy
331 Please specify the password.
Password: #密码为脚本中设置的密码。
230 Login successful.
ftp> mkdir abc
257 "/abc" created
有关vsftpd配置项的说明,请参考博客:http://liyuanjie.blog.51cto.com/12877605/1967369
本文出自 “安然一笑” 博客,请务必保留此出处http://liyuanjie.blog.51cto.com/12877605/1977251
以上是关于vsftpd服务搭建与配置脚本的主要内容,如果未能解决你的问题,请参考以下文章