一、centos6.5 vsftp安裝
#已經(jīng)禁用了iptables
service iptables stop
chkconfig iptables off
如果開(kāi)iptables可以添加如下規(guī)則
iptables -I INPUT -p tcp? --dport 22 -j ACCEPT
iptables -I INPUT -p tcp? --dport 21 -j ACCEPT
iptables -I INPUT -p tcp? --dport 5000:5100 -j ACCEPT
iptables -P INPUT DROP
iptables -I OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -P OUTPUT ACCEPT
iptables -nL
#禁止了selinux
#如果off不行就不執(zhí)行“setenforce 0”,有條件的話執(zhí)行完下面命令最好重啟一下系統(tǒng)
setenforce off
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config
grep '^SELINUX=' /etc/selinux/config
#------------------------------------------------------直接刷命令-------------------------------------
#1.安裝vsftpd-2.2.2-14.el6.x86_64
yum -y install vsftpd
chkconfig vsftpd on
#2.基于虛擬用戶(hù)的配置
cd /etc/vsftpd/
cp vsftpd.conf vsftpd.conf.orig
#寫(xiě)入配置文件含被動(dòng)模式
cat>>vsftpd.conf<<EOF
#by hua
user_config_dir=/etc/vsftpd/vuser_conf
pasv_enable=YES
pasv_min_port=5000
pasv_max_port=5100
pasv_promiscuous=YES
#force_dot_files=yes
EOF
#3.進(jìn)行認(rèn)證,安裝Berkeley DB工具
yum install db4 db4-utils -y
#創(chuàng)建用戶(hù)密碼文本,單行為用戶(hù)名,雙行為密碼
cat>>vuser_passwd.txt<<EOF
t1
123456
EOF
#生成虛擬用戶(hù)認(rèn)證的db文件,如果添加用戶(hù)則需要重新生成一下vuser_passwd.db然后重啟vsftp
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
cp /etc/pam.d/vsftpd? /etc/pam.d/vsftpd.orig
echo '#%PAM-1.0' >/etc/pam.d/vsftpd
echo 'auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd'>>/etc/pam.d/vsftpd
echo 'account required pam_userdb.so db=/etc/vsftpd/vuser_passwd' >>/etc/pam.d/vsftpd
cat /etc/pam.d/vsftpd
#創(chuàng)建虛擬用戶(hù)配置文件
mkdir /etc/vsftpd/vuser_conf
cd /etc/vsftpd/vuser_conf/
#下面建立t1賬號(hào)配置,配置名和用戶(hù)名一樣,有多少個(gè)用戶(hù)名就有多少個(gè)配置
cat>>t1<<EOF
local_root=/disk1/tools
local_umask=022
write_enable=YES
guest_enable=yes
guest_username=daemon
anonymous_enable=no
anon_world_readable_only=no
anon_upload_enable=yes
anon_mkdir_write_enable=yes
anon_other_write_enable=yes
anon_umask=002
file_open_mode=0774
EOF
service vsftpd start
chkconfig vsftpd on
mkdir -p /disk1/tools
chown daemon.daemon /disk1/tools
#為了安全禁止匿名用戶(hù)登陸,如果發(fā)現(xiàn)問(wèn)題可以去掉
sed -i '/anonymous_enable/s/YES/NO/' /etc/vsftpd/vsftpd.conf
grep 'anonymous_enable' /etc/vsftpd/vsftpd.conf
service vsftpd restart
#------------------------------------------------------直接刷命令-------------------------------------
★★★★★★★★★★★★★★★★★★★★注意事項(xiàng)start★★★★★★★★★★★★★★★★★★★★★★★
每一次修改用戶(hù)賬號(hào)都必須生成一次密碼vuser_passwd.db文件,否則不會(huì)生效??!還要重啟vsftp!
#下面是操作命令!
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
service vsftpd restart
“guest_username=系統(tǒng)用戶(hù)”中的,如上例子中g(shù)uest_username=daemon
daemon是系統(tǒng)用戶(hù),一定存在的,一般是web軟件的進(jìn)程名字,比如我的是nginx的話,就用nginx,如果有php進(jìn)程我也把php配置文件進(jìn)程用戶(hù)改為nginx,
這樣的好處是web就可以對(duì)你上傳的文件進(jìn)行寫(xiě)讀刪除,因?yàn)橛械木彺嫖募莗hp動(dòng)態(tài)生成的,必須有寫(xiě)入權(quán)限!修改權(quán)限,刪除權(quán)限!
比如:我查看nginx和php進(jìn)程
[root@vm5 ~]# ps -ef|grep nginx|grep -v grep
nginx? ? 1634? 1632? 0 May23 ?? ? ? ? 00:00:05 php-fpm: pool www
root? ? ? 1648? ? 1? 0 May23 ?? ? ? ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx? ? 1821? 1632? 0 May23 ?? ? ? ? 00:00:05 php-fpm: pool www
nginx? ? 13818? 1632? 0 Jun08 ?? ? ? ? 00:00:04 php-fpm: pool www
nginx? ? 13851? 1632? 0 Jun08 ?? ? ? ? 00:00:04 php-fpm: pool www
nginx? ? 20165? 1648? 0 Aug17 ?? ? ? ? 00:11:06 nginx: worker process
nginx? ? 20166? 1648? 0 Aug17 ?? ? ? ? 00:11:18 nginx: worker process
nginx? ? 20167? 1648? 0 Aug17 ?? ? ? ? 00:11:05 nginx: worker process
nginx? ? 20168? 1648? 0 Aug17 ?? ? ? ? 00:11:23 nginx: worker process
nginx? ? 23453? 1632? 0 Jun12 ?? ? ? ? 00:00:04 php-fpm: pool www
nginx? ? 29795? 1632? 0 Jul12 ?? ? ? ? 00:00:02 php-fpm: pool www
nginx? ? 29796? 1632? 0 Jul12 ?? ? ? ? 00:00:02 php-fpm: pool www
從上面可以看到nginx和php的啟動(dòng)進(jìn)程是nginx用戶(hù)(這個(gè)用戶(hù)查/etc/passwd是存在的)
[root@vm5 ~]# grep nginx /etc/passwd
nginx:x:498:499:nginx user:/var/cache/nginx:/sbin/nologin
這樣guest_username配置就要寫(xiě)成“guest_username=nginx”,web的nginx還要能讀,主要是網(wǎng)站是php寫(xiě)的,以php進(jìn)程為主,一般情況都會(huì)有緩存目錄
要對(duì)其文件或目錄進(jìn)行增加,刪除,修改,所以才配置“guest_username=nginx”,這樣ftp虛擬用戶(hù)t1的權(quán)限就和nginx一樣了!
如果改為其它用戶(hù)如daemon,那第目錄和文件用戶(hù)和組都是daemon!你上傳了網(wǎng)站文件如果含緩存目錄的話,PHP因不能寫(xiě)入和刪除,就會(huì)出問(wèn)題!
★★★★★★★★★★★★★★★★注意事項(xiàng)END★★★★★★★★★★★★★★★★★★★★★★★★
#3.錯(cuò)誤解決:
500 OOPS: cannot locate user entry:daemon
說(shuō)明沒(méi)有nginx用戶(hù),可以修改guest_username=daemon為其他用戶(hù)。
###FTP客戶(hù)端使用注意事項(xiàng)##############
如果用FileZilla Client連接vsftpd,
1.“常規(guī)”選項(xiàng):“登陸類(lèi)型”用"正常",然后輸入用戶(hù)名和密碼
2.“傳輸設(shè)置”選項(xiàng)中:“傳輸模式”要用修改為“主動(dòng)”不能用“默認(rèn)”否則會(huì)報(bào)錯(cuò),連接不上
3.“字符集”選項(xiàng):建議強(qiáng)制用UTF-8,因?yàn)槲覀兪莄entos服務(wù)器
如果是cuteftp,直接就可以連接
#########END############################
二、centos7安裝vsftp
#1.禁用防火墻firewalld
#用兼容centos6方式關(guān)閉
yum install -y net-tools
service firewalld stop
#也可以用systemctl命令關(guān)閉
systemctl stop firewalld
systemctl disable firewalld
#2.關(guān)閉了selinux
#如果off不行就不執(zhí)行“setenforce 0”,有條件的話執(zhí)行完下面命令最好重啟一下系統(tǒng)
setenforce off
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config
grep '^SELINUX=' /etc/selinux/config
#3.其實(shí)centos7安裝vsftp很簡(jiǎn)單,按centos6.5安裝,然后在配置文件中添加多一項(xiàng)“allow_writeable_chroot=YES”
echo 'allow_writeable_chroot=YES'>>/etc/vsftpd/vsftpd.conf
service vsftpd restart
注:
centos7用的是vsftp 3版本,centos6 yum安裝的是2.2版本,不能添加“allow_writeable_chroot=YES”否則報(bào)錯(cuò)
500 OOPS: unrecognised variable in config file: allow_writeable_chroot
如果在centos7不添加“allow_writeable_chroot=YES”,用FTP客戶(hù)端連接也會(huì)報(bào)如下錯(cuò)誤:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
從2.3.5之后,vsftpd增強(qiáng)了安全檢查,如果用戶(hù)被限定在了其主目錄下,則該用戶(hù)的主目錄不能再具有寫(xiě)權(quán)限了!
如果檢查發(fā)現(xiàn)還有寫(xiě)權(quán)限,就會(huì)報(bào)上面提示的錯(cuò)誤。
★★★★★每一次修改用戶(hù)賬號(hào)都必須生成一次密碼vuser_passwd.db文件,否則不會(huì)生效??!還要重啟vsftp!
#下面是操作命令!
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
service vsftpd restart