安裝前的準(zhǔn)備
關(guān)閉防火墻或者開端口權(quán)限。一般是firewalld或者iptables婚温。
systemctl stop firewalld
systemctl disable firewalld
關(guān)閉sellinux
立即關(guān)閉
setenforce 0
永久關(guān)閉
vi /etc/selinux/config修改SELINUX
SELINUX=disabled
查看是否關(guān)閉
getenforce
安裝vsftpd
yum install -y vsftpd
systemctl start vsftpd
systemctl enable vsftpd
配置vsftpd
建vsftpd使用的系統(tǒng)用戶锡宋,主目錄為/home/vsftpd儡湾,禁止ssh登錄。創(chuàng)建之后所有虛擬用戶使用這個(gè)系統(tǒng)用戶訪問文件执俩。
useradd vsftpd -d /home/vsftpd -s /bin/false
創(chuàng)建虛擬用戶主目錄徐钠,比如虛擬用戶叫ftp1,執(zhí)行下面的命令役首。
mkdir -p /home/vsftpd/ftp1
編輯虛擬用戶名單文件:(第一行賬號尝丐,第二行密碼显拜,注意:不能使用root做用戶名,系統(tǒng)保留)
vi /etc/vsftpd/loginusers.conf
增加
ftp1
123456
這樣就創(chuàng)建了ftp1這個(gè)虛擬用戶摊崭,密碼為123456
- 根據(jù)這個(gè)文件創(chuàng)建數(shù)據(jù)庫文件
db_load -T -t hash -f /etc/vsftpd/loginusers.conf /etc/vsftpd/loginusers.db
chmod 600 /etc/vsftpd/loginusers.db
-
啟用這個(gè)數(shù)據(jù)庫文件
vi /etc/pam.d/vsftpd
注釋掉所有內(nèi)容后讼油,增加下面的內(nèi)容
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/loginusers
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/loginusers
創(chuàng)建虛擬用戶配置文件目錄
mkdir /etc/vsftpd/userconf
創(chuàng)建虛擬用戶配置用(一個(gè)戶名對應(yīng)一個(gè)文件)
vi /etc/vsftpd/userconf/ftp1
增加下面的內(nèi)容
local_root=/home/vsftpd/ftp1/
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
配置說明
//設(shè)置FTP賬號根目錄
local_root=/home/vsftpd/ftp1/
//允許寫入權(quán)限杰赛,包括修改
write_enable=YES
//允許匿名用戶瀏覽呢簸,下載文件
anon_world_readable_only=NO
//允許匿名用戶上傳
anon_upload_enable=YES
//允許匿名用戶上傳/建立目錄
anon_mkdir_write_enable=YES
//允許匿名用戶具有建立目錄,上傳之外的權(quán)限乏屯,如重命名根时,刪除
anon_other_write_enable=YES
-
修改主配置文件
vi /etc/vsftpd/vsftpd.conf
更改如下
#修改
anonymous_enable=NO
ascii_upload_enable=YES
ascii_download_enable=YES
#增加
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/userconf
allow_writeable_chroot=YES
配置說明
//禁止匿名用戶登錄
anonymous_enable=NO
//禁止用戶訪問除主目錄以外的目錄
chroot_local_user=YES
//設(shè)定支持ASCII模式的上傳和下載功能
ascii_upload_enable=YES
ascii_download_enable=YES
// 啟動虛擬用戶
guest_enable=YES
//虛擬用戶使用的系統(tǒng)用戶名
guest_username=vsftpd
//虛擬用戶使用的配置文件目錄
user_config_dir=/etc/vsftpd/userconf
//最新版的vsftpd為了安全必須用戶主目錄(也就是/home/vsftpd/ftp1)沒有寫權(quán)限,才能登錄辰晕,或者使用allow_writeable_chroot=YES蛤迎,如果
不設(shè)置allow_writeable_chroot,#設(shè)置FTP上傳文件新增權(quán)限含友,可以對主目錄權(quán)限為755替裆,主目錄下面的子目錄再設(shè)置777權(quán)限 。如以下這般設(shè)置
chmod -R 755 /home/vsftpd
chmod R 777 /home/vsftpd/ftp1
-
最后重啟服務(wù)使配置生效
allow_writeable_chroot=YESsystemctl restart vsftpd