1、用root 進入系統
2、使用命令 rpm -qa|grep vsftpd 查看系統是否安裝了ftp,若安裝了vsftp,使用這個命令會在屏幕上顯示vsftpd的版本
3、使用命令rpm -e vsftpd 即可卸載ftp
4、再使用rpm -qa|grep vsftpd 查看系統是否已刪除ftp,若刪除成功,屏幕上顯示vsftpd的版本
一:安裝vsftpd
查看是否已經安裝vsftpd
rpm -qa | grep vsftpd
如果沒有,就安裝,並設置開機啓動
yum -y install vsftpd
chkconfig vsftpd on
安裝時發現錯誤:
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base
是因爲缺少DNS,解決如下:到/etc目錄下配置resolv.conf加入nameserver IP:
[root@localhost ~]# vi /etc/resolv.conf
#下面地址是福建電信DNS
nameserver 218.85.157.99
管理vsftpd相關命令:
啓動vsftpd: service vsftpd start
停止vsftpd: service vsftpd stop
重啓vsftpd: service vsftpd restart
二、配置防火牆
打開/etc/sysconfig/iptables文件
vi /etc/sysconfig/iptables
安裝完vsftpd後,默認情況下,CentOS的防火牆是不開放ftp服務的,需要添加模塊和開放21端口才能提供ftp訪問。
1.添加ip_conntrack_ftp 模塊
[root@hexuweb101 ~] vi /etc/sysconfig/iptables-config
添加下面一行
IPTABLES_MODULES="ip_conntrack_ftp"
2.打開21端口
[root@hexuweb101 ~] vi /etc/sysconfig/iptables
CentOS 5.x版本添加如下規則
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
CentOS 6.x版本添加如下規則
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
3.重啓iptables使新的規則生效
[root@hexuweb101 ~] service iptables restart
4. 檢查iptables 是否正常
[root@hexuweb101 ~]$service iptables status
5.關閉vi /etc/selinux/config
SELINUX=disabled
SELINUX=disabled
Centos6.x
/etc/init.d/iptables stop
chkconfig iptables off
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
Centos7.x
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
三、配置vsftpd服務器
1.默認的配置文件是/etc/vsftpd/vsftpd.conf,你可以用文本編輯器打開。
vi /etc/vsftpd/vsftpd.conf
2.添加ftp用戶
下面是添加ftpuser用戶,設置根目錄爲/home/wwwroot/ftpuser,禁止此用戶登錄SSH的權限,並限制其訪問其它目錄。
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
改爲
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
3.增加用戶ftpuser,指向目錄/home/wwwroot/ftpuser,禁止登錄SSH權限。
useradd -d /home/ftpuser -g ftp -s /sbin/nologin ftpuser
4.設置用戶口令
passwd ftpuser
5、編輯文件chroot_list:
vi /etc/vsftpd/chroot_list
內容爲ftp用戶名,每個用戶佔一行,如:
ftpuser
john
6、重新啓動vsftpd
service vsftpd restart
另外,如果覺得以後管理ftp用戶名嫌麻煩,可以使用centos官方發佈的腳本管理。地址如下:(未用過)
http://wiki.centos.org/HowTos/Chroot_Vsftpd_with_non-system_users
----------------------------------
出現的錯誤
1、500 OOPS: cannot change directory
解決方法:
在終端輸入命令:
1.setsebool -P ftpd_disable_trans 1
2.service vsftpd restart
就OK了!
原因:這是因爲服務器開啓了selinux,這限制了FTP的登錄。
http://www.linuxidc.com/Linux/2015-10/123848.htm
---以下是有些產品經理需要訪問上傳的html文件,所以用nginx配置提供訪問--------------
1、訪問home目錄下的ftpuser目錄裏面的對應目錄文件,比如http://119.23.1.1/ftpuser/20190421/
2、在nginx.conf 頭部先加上 user root; 不然會報403 Forbidden ,原因是location 裏面配置了root /home/;
user root;
worker_processes 2;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm index.php;
}
location /ftpuser/ {
root /home/;
autoindex on;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}