新建ftp用户
Posted hang0716
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了新建ftp用户相关的知识,希望对你有一定的参考价值。
新建ftp用户
#!/bin/bash # Filename: createFtpCentOS.sh # Revision: 1.0 # Date: 2018/5/23 # Author: YangHang # Email: 13716320887@139.com # Website: no # Description: centos7 添加ftp用户 function install_vsftpd(){ if test -z `rpm -qa vsftpd` ;then echo "vsftpd isn‘t install" yum install vsftpd -y else echo "vsftpd was installed" cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak fi } function ftpuseradd(){ useradd -s /sbin/nologin $userName echo $userPassword|passwd --stdin $userName } function init_vsftpd(){ cat > /etc/vsftpd/vsftpd.conf <<EOF anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 anon_upload_enable=NO anon_mkdir_write_enable=NO dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES chown_uploads=NO xferlog_std_format=YES async_abor_enable=YES ascii_upload_enable=YES ascii_download_enable=YES ftpd_banner=Welcome to MVTECH FTP service. chroot_local_user=NO chroot_list_enable=YES chroot_list_file=/etc/vsftpd/chroot_list listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES file_open_mode=0775 use_localtime=yes max_clients=0 max_per_ip=0 user_config_dir=/etc/vsftpd/user_config EOF touch /etc/vsftpd/chroot_list echo $userName > /etc/vsftpd/chroot_list } function add_vsftp(){ mkdir -p /etc/vsftpd/user_config touch /etc/vsftpd/user_config/$userName cat >/etc/vsftpd/user_config/$userName<< EOF anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES reverse_lookup_enable=NO xferlog_std_format=YES ascii_upload_enable=YES ascii_download_enable=YES allow_writeable_chroot=YES chroot_local_user=YES listen=YES pam_service_name=vsftpd tcp_wrappers=YES userlist_deny=NO local_root=dir EOF #替换配置文件中的ftphome目录 sed -i s#local_root=dir#local_root=$ftpHome#g /etc/vsftpd/user_config/$userName mkdir -p $ftpHome chown -R $userName:$userName $ftpHome } function start_service(){ systemctl start vsftpd systemctl enable vsftpd } #初始化方法 function init(){ source /etc/profile #定义变量 userName=‘mvtechftp‘ userPassword=‘mvtech123‘ ftpHome=‘/mvtech/ftp_root/mvtechftp‘ install_vsftpd; init_vsftpd; ftpuseradd; add_vsftp; start_service; } init
以上是关于新建ftp用户的主要内容,如果未能解决你的问题,请参考以下文章