1、环境:centos7,bash
2、脚本使用说明:可以在执行脚本的时候带上用户名密码
例如:./script_name ftpuser_name passwd**
#!/bin/bash
if [ $# -ne 3 ];then
echo "please inputr <username> <passwd> <install_mode 1-rpm install 0-yum install>"
exit -1
fi
#指定用户名密码
ftp_user_name=$1
password=$2
#卸载ftp,排除干扰
rpm -e vsftpd
rm -f /etc/vsftpd/*
if [ $3 -eq 1 ];then
rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
else
yum -y install vsftpd
fi
#添加用户,排除干扰
#userdel $ftp_user_name
useradd -d /home/$ftp_user_name -s /sbin/nologin $ftp_user_name
chage -M 99999 $ftp_user_name
expect << EOF
#set timeout 60
spawn passwd $ftp_user_name
expect {
"New password: "
{
send "$password\n";
exp_continue;
}
"Retype new password:"
{
send "$password\n";
}
}
expect eof
EOF
echo -n $ftp_user_name > /etc/vsftpd/user_list
#配置防火墙
firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --reload
#配置SElinux
getsebool -a | grep ftp
setsebool -P ftpd_full_access on
#启动服务
echo
echo "++++++++++++++++++++++准备启动ftp!!!!!!!!!!!!!"
systemctl start vsftpd
systemctl status vsftpd
3、手动登录ftp服务器
①ftp ftp_ip,然后依次输入用户名和密码即可登录。
例如:ftp 192.168.100.100
②lftp ftp://user_name:passwd@ftp_ip:port
例如:lftp ftp://ftp_user1:12345678@192.168.100.100:21
提示:如果lftp没有安装,直接通过yum安装:yum -y install lftp