标签:dev 检查 服务 mkdir open etc %s rap 系统
#!/bin/bash
/etc/init.d/iptables stop
setenforce 0
TIME=$(date +%Y%m%d-%H%M%S)
YUMINSTALL() {
YUMDIR=/etc/yum.repos.d
umount /dev/cdrom &>>/dev/null
mount /dev/cdrom /mnt &>>/dev/null
if [ $? -eq 0 ]
then
echo "光盘挂载成功!"
else
echo “光盘挂载失败请检查!”
exit
fi
mkdir $YUMDIR/bak &>>/dev/null
mv $YUMDIR/* $YUMDIR/bak &>>/dev/null
cat >> $YUMDIR/yum.repo << !
[base]
name=aaa
baseurl=file:///mnt
gpgcheck=0
!
yum clean all &>>/dev/null
yum makecache &>>/dev/null
if [ $? -eq 0 ]
then
echo "yum配置完毕"
else
echo "yum安装失败,请检查!"
exit 1
fi
}
FTPSERVER(){
read -p "ftp服务已经安装是否从新安装(yes / no)" CHONGXIN
case $CHONGXIN in
yes|YES)
clear
echo "正在重新安装ftp请稍后"
echo "#########################################"
rpm -e vsftpd --nodeps
yum -y install vsftpd &>/dev/null
if [ $? -eq 0 ]
then
echo "安装完毕!"
else
echo "安装失败!"
fi ;;
no|NO)
exit ;;
*)
echo “输入错误,请重新输入”
FTPSERVER ;;
esac
}
FTPCLIENT(){
read -p "ftp客户端已经安装是否从新安装(yes / no)" CHONGXINC
case $CHONGXINC in
yes|YES)
clear
echo "正在重新安装ftp客户端请稍后"
echo "#########################################"
rpm -e ftp --nodeps
yum -y install ftp &>/dev/null
if [ $? -eq 0 ]
then
echo "安装完毕!"
else
echo "安装失败!"
fi ;;
no|NO)
exit ;;
*)
echo “输入错误,请重新输入”
FTPCLIENT ;;
esac
}
NM(){
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/NM.vsftpd.conf.$TIME
chown -R ftp.ftp /var/ftp/pub
cat > /etc/vsftpd/vsftpd.conf << !
write_enable=YES
anon_umask=022
anonymous_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
!
}
TD(){
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/TD.vsftpd.conf.$TIME
cat >/etc/vsftpd/vsftpd.conf << !
local_enable=YES
local_umask=077
chroot_local_user=YES
write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=NO
tcp_wrappers=YES
!
}
TDb(){
read -p "是否要创建新的用户来使用FTP(yes / no):" TDnew
case $TDnew in
yes|YES)
read -p "请创建登录FTP的特定用户:" yonghu
cat /etc/passwd |grep $yonghu &>/dev/null
if [ $? -eq 0 ]
then
echo "用户已经存在"
exit 1
else
useradd "$yonghu" && echo "用户创建成功!"
read -p "请输入登录FTP的用户密码:" mima
echo "$mima" |passwd --stdin $yonghu && echo "密码设定成功!"
echo "$yonghu" >> /etc/vsftpd/user_list
echo “-----------------------------------------------------------”
echo "请使用$yonghu登录ftp!"
fi ;;
no|NO)
exit 1 ;;
*)
echo "输入错误,请重新输入!"
TDb ;;
esac
}
XN(){
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/XN.vsftpd.conf.$TIME
rpm -q db4-utils &>/dev/null
if [ $? -ne 0 ]
then
echo "正在安装db4-utils,请稍等!"
yum -y install db4-utils
fi
touch /etc/vsftpd/user
useradd -s /sbin/nologin vu
read -p "请创建登录FTP的虚拟用户:" xuyonghu
sed ‘2~2d‘ /etc/vsftpd/user |grep $xuyonghu &>/dev/null
if [ $? -eq 0 ]
then
echo "这个虚拟用户已经存在!"
exit 1
else
read -p "请输入登录FTP的用户密码:" xumima
echo "$xuyonghu" >>/etc/vsftpd/user
echo "$xumima" >>/etc/vsftpd/user
cd $xunifile
db_load -T -t hash -f /etc/vsftpd/user /etc/vsftpd/user.db
cat > /etc/pam.d/vsftpd.vu <<!
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/user
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/user
!
fi
cat > /etc/vsftpd/vsftpd.conf << !
write_enable=YES
anon_umask=022
anonymous_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
guest_enable=YES
guest_username=vu
pam_service_name=vsftpd.vu
local_enable=YES
local_umask=022
chroot_local_user=YES
virtual_use_local_privs=YES
!
}
FTP_CMD(){
rpm -q ftp &>/dev/null
if [ $? -ne 0 ]
then
echo "系统中未安装ftp客户端!"
exit 1
else
read -p "请输入要使用的操作(put / get):" caozuo
case $caozuo in
put)
read -p "请输入ftp服务端的ip地址:" IP
read -p "请输入登录ftp的用户:" xuniuser
read -p "请输入用户密码:" xunipass
read -p "请输入要上传文件的目录位置:" xunidir
read -p "请输入要上传的文件名称:" xunifile
ftp -n <<!
open $IP
user $xuniuser $xunipass
lcd $xunidir
put $xunifile
exit
!
echo "上传文件完成" ;;
get)
read -p "请输入ftp服务端的ip地址:" IP
read -p "请输入登录ftp的用户:" xuniuser
read -p "请输入用户密码:" xunipass
read -p "请输入要下载到系统的目录位置:" xunidir
read -p "请输入要下载的文件名称:" xunifile
ftp -n <<!
open $IP
user $xuniuser $xunipass
lcd $xunidir
get $xunifile
exit
!
echo "下载文件完成";;
*)
echo "输入指令有误,请重新输入!"
FTP_CMD ;;
esac
fi
}
clear
echo "----------------------------------------------------------------------------
| 欢迎使用vsftpd 脚本 |
----------------------------------------------------------------------------
|1.安装ftp服务 |
|2.安装ftp客户端 |
|3.选择ftp使用模式 |
|4.使用客户端(put|get) |
|5.退出当前程序 |
----------------------------------------------------------------------------"
read -p "请输入服务种类:" NUM
case $NUM in
1)
YUMINSTALL
rpm -q vsftpd &>/dev/null
if [ $? -eq 0 ]
then
FTPSERVER
else
echo "正在安装ftp服务端请稍后"
echo "#########################################"
yum -y install vsftpd &>/dev/null
echo "ftp服务端安装完毕!"
fi ;;
2)
YUMINSTALL
rpm -q ftp &>/dev/null
if [ $? -eq 0 ]
then
FTPCLIENT
else
echo "正在安装ftp客户端请稍后"
echo "#########################################"
yum -y install ftp &>/dev/null
echo "ftp客户端安装完毕!"
fi;;
3)
clear
rpm -q vsftpd &>/dev/null
if [ $? -eq 0 ]
then
echo "----------------------------------------------------------------------------
| 请选择ftp使用模式 |
----------------------------------------------------------------------------
|1.开启匿名用户 |
|2.开启特定用户 |
|3.开启虚拟用户 |
|4.退出当前程序 |
----------------------------------------------------------------------------"
read -p "请选择ftp使用模式:" moshi
case $moshi in
1)
NM
/etc/init.d/vsftpd restart
echo "注意:匿名用户为ftp,无删除权限" ;;
2)
TD
TDb
/etc/init.d/vsftpd restart ;;
3)
XN
/etc/init.d/vsftpd restart ;;
4)
exit 1 ;;
esac
else
echo "系统中不存在ftp服务,请安装!"
fi ;;
4)
FTP_CMD ;;
5)
echo "已经退出执行程序,欢迎下次使用!"
exit 1
esac
标签:dev 检查 服务 mkdir open etc %s rap 系统
原文地址:https://www.cnblogs.com/henglinux/p/9571467.html