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;
}
--------------------------------------------------
下面为
yum -y install vsftpd
安装时发现错误:
Error: Cannot find a valid baseurl for repo: base 的解决方案
CentOS 6已经随着2020年11月的结束进入了EOL(Reaches End of Life),不过有一些老设备依然需要支持,CentOS官方也给这些还不想把CentOS 6扔进垃圾堆的用户保留了最后一个版本的镜像,只是这个镜像不会再有更新了
更换的Vault源我选了两个,一个是官方的http://vault.centos.org,使用的北美AWS的服务器,海外的话使用这个就可以;还有一个是阿里的http://mirrors.aliyun.com/centos-vault/,国内使用这个不会卡。
首先把fastestmirrors关了
Bash
#编辑
vi /etc/yum/pluginconf.d/fastestmirror.conf
#修改
enable=0
先把之前的repo挪到备份,然后下面两个二选一
Bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
替换为官方Vault源
Bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://static.lty.fun/%E5%85%B6%E4%BB%96%E8%B5%84%E6%BA%90/SourcesList/Centos-6-Vault-Official.repo
国内用户可以替换为阿里云Vault镜像
Bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://static.lty.fun/%E5%85%B6%E4%BB%96%E8%B5%84%E6%BA%90/SourcesList/Centos-6-Vault-Aliyun.repo
如果没有wget的话,请使用SFTP或者直接nano、vi编辑/etc/yum.repos.d/CentOS-Base.repo
里面的东西替换成这两个选一个,国内用第二个阿里,国外建议第一个官方。
懒人专用一键修复:
Bash
sed -i "s|enabled=1|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://www.xmpan.com/Centos-6-Vault-Aliyun.repo
yum clean all
yum makecache