#搭建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
使用虛擬用戶登陸: