#搭建ftp服务器
说明:
操做系统:Red Hat 7.0
vsftpd版本:3.0.2
目标:
经过配置ftp服务器,向外提供文件传输服务
##安装vsftpd服务器linux
# yum install vsftpd -y
###备份配置文件数据库
# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.confbak # grep -v "#" /etc/vsftpd/vsftpd.confbak > /etc/vsftpd/vsftpd.conf
###查看默认配置文件vim
# cat /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
###使用默认配置启动vsftpd安全
# systemctl start vsftpd # systemctl status vsftpd
###添加系统服务服务器
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service'
###防火墙设置(防火墙配置请参考配置iptables或firewalld配置)app
# systemctl stop iptables.service # 关闭selinux
###匿名登录tcp
ftp匿名访问模式是不安全的服务模式,正式环境不容许匿名登录ide
##配置ftp
###配置本地用户模式ui
# cat /etc/vsftpd/vsftpd.conf
anonymous_enable=NO #禁止匿名访问
local_enable=YES #容许本地用户模式
write_enable=YES #容许写入
local_umask=022 #本地用户文件umask值
userlist_deny=YES #禁止list中的用户值为NO则为仅容许名单
userlist_enable=YES #容许"禁止登录名单",名单文件为ftpuser与user_list
dirmessage_enable=YES #是否激活目录欢迎信息功能
xferlog_enable=YES #记录服务器上传和下载状况的日志文件
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
tcp_wrappers=YES 操作系统
重启服务:
# systemctl restart vsftpd.service
查看禁止登录用户:
添加普通用户:
# useradd moxiaokai # passwd moxiaokai Changing password for user moxiaokai. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully.
在客户端尝试登录ftp:
###配置虚拟用户模式
####添加虚拟用户:
单行为帐号,双行为密码
# cd /etc/vsftpd/ # vi vuser.list moxiaokai pa33word cy pa22word
####生成数据库文件:
生成库文件:
# db_load -T -t hash -f vuser.list vuser.db # file vuser.db vuser.db: Berkeley DB (Hash, version 9, native byte-order)
受权:
# chmod 600 vuser.db
删除原始文件:
# rm -f vuser.list
####建立ftp根目录及虚拟用户映射系统用户
# useradd -d /var/ftproot/ -s /sbin/nologin vmxk # chmod -Rf 755 /var/ftproot/
####创建PAM文件
auth required pam_userdb.so db=/etc/vsftpd/vuser account required pam_userdb.so db=/etc/vsftpd/vuser
####配置vsftp
anonymous_enable=NO local_enable=YES guest_enable=YES guest_username=vmxk write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=NO listen_ipv6=YES pam_service_name=vsftpd.vu userlist_enable=YES tcp_wrappers=YES allow_writeable_chroot=YES user_config_dir=/etc/vsftpd/vusers_dir
建立目录&文件:
# mkdir /etc/vsftpd/vusers_dir # cd /etc/vsftpd/vusers_dir # touch moxiaokai # vim moxiaokai anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES
重启vsftpd服务:
# systemctl restart vsftpd.service
使用虚拟用户登陆: