热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS系统下安装vsFTPd并配置虚拟用户

基本配置环境如下:1.ftp用户的home目录:/data/ftp2.所有虚拟用户的local_root目录,都放在/data/wwwroot/这里.这里为了方便,目录名和虚拟用户名一样,当然也可以不一样的3.允许登录用户文件:/etc/vsftpd/chroot_list

基本配置环境如下:

1.ftp用户的home目录:/data/ftp
2.所有虚拟用户的local_root目录,都放在/data/wwwroot/这里.这里为了方便,目录名和虚拟用户名一样,当然也可以不一样的
3.允许登录用户文件:/etc/vsftpd/chroot_list

==========================================

1.安装vsftpd

#yum -y install vsftpd

可用service vsftpd start 命令查看是否安装成功

设置CentOS vsftpd自启动

#chkconfig --level 35 vsftpd on

2.配置vsftpd.conf文件

#vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO 是否允许匿名用户访问
#chroot_list_enable=YES   限定用户不可以离开主目录
#chroot_list_file=/etc/vsftpd/chroot_list

chroot_local_user=YES
//这里为了方便,直接默认情况下将所有用户都锁定在自己的目录里,如果不写这一行的话,就需要启用上面的两行,以后添加新账户的时候需要将用户添加到chroot_list_file来,来进行锁定用户在自己的目录里,参考:http://blog.haohtml.com/archives/857

local_enable=YES/NO 本地用户是否可以访问 注:如果为NO
则所有虚拟用户都将不能访问原因:虚拟用户访问在主机上其实是以本地用户访问的
pam_service_name=vsftpd pam认证文件名 在/etc/pam.d/vsftpd

guest_enable=YES 启用虚拟用户功能
guest_username=ftpadmin 指定虚拟用户的宿主用户 ?centos
里面已经有内置的ftp用户了,这里我们使用重新创建的用户(注:此用户在chroot_list_file=/etc/vsftpd/chroot_list文件里所指定的用户)

user_config_dir=/etc/vsftpd/vuser_conf
设置虚拟用户个人vsftp的服务配置文件所在目录

vsftpd用户没有办法修改文件的权限的权限(chmod),加上这两行就可以了http://blog.haohtml.com/archives/7852
virtual_use_local_privs=YES
chmod_enable=YES

创建虚拟用户配置文件目录

#mkdir /etc/vsftpd/vuser_conf
#mkdir /etc/vsftpd/chroot_list 

四.在认证文件chroot_list里添加vsftpd虚拟用户所对应的本地系统用户

创建vsftpd运行用户ftpadmin,在创建前请确认是否有/data目录,没有的话创建一个,或者最后创建这个目录,把权限分配一下也可以(这里为了配合web使用,并没有使用默认的ftp:ftp用户)

#/usr/sbin/useradd -d /data/ftp -g www -s /sbin/nologin
ftpadmin
#passwd ftpadmin

这里说明一下,如果您在前面vsftpd.conf文件里使用的是chroot_local_user=YES指令的话,则下面的一步操作可以直接跳过去,否则需要把ftpadmin写到chroot_list文件里才可以.

将ftpadmin添加到/etc/vsftpd/chroot_list文件中

#vi /etc/vsftpd/chroot_list
ftpadmin

五.创建虚拟用户并生成虚拟用户db文件
安装相应的库

#yum -y install db4-utils

添加虚拟用户,(奇数行为用户名 ,偶数行为密码)

#vi /etc/vsftpd/vftpuser.txt
zz
aaaaa
ftp1
zzzzz

生成db文件

#db_load -T -t hash -f /etc/vsftpd/vftpuser.txt
/etc/vsftpd/vftpuser.db

六.生成认证文件文件

#vi /etc/pam.d/vsftpd
auth required pam_userdb.so db=/etc/vsftpd/vftpuser
account required pam_userdb.so db=/etc/vsftpd/vftpuser

如果使用的是64位系统,要增加以下两句:

auth required /lib64/security/pam_userdb.so
db=/etc/vsftpd/vftpuser
account required /lib64/security/pam_userdb.so
db=/etc/vsftpd/vftpuser

注:这里db=/etc/vsftpd/vftpuser 中的vftpuser 是你生成的虚拟用户的db文件.

/etc/pam.d/vsftpd文件里的默认内容可以先注释掉.添加上面两行内容.

七.创建每个虚拟用户的配置文件(配置文件所在目录为/etc/vsftpd/vuser_conf,用户必须为vftpuser.txt中的用户)
这里假如添加的虚拟用户名为zz,创建的文件是以虚拟ftp用户为文件名

# vi /etc/vsftpd/vuser_conf/zz
local_root=/data/wwwroot/zzftp(虚拟用户的根目录根据实际修改)
write_enable=YES (可写)
download_enable=YES
anon_world_readable_Only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
listen_port=

创建ftp虚拟用户目录,并给虚拟ftp用户目录修改权限

#mkdir -p /data/wwwroot/zzftp
#chown -R ftpadmin:www /data/wwwroot/zzftp
#chmod -R 775 /data/wwwroot/zzftp

注意上面的目录权限值是775,因为和web一块使用,这里ftpadmin也是www一个组的,所以要有组用户的权限才可以.

七.重启vsftpd

#service vsftpd restart

#setsebool ftpd_disable_trans 1

八.测试虚拟用户

# ftp192.168.1.107

Connected to 192.168.1.107.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as anauthentication type

Name (192.168.1.107:root): zz

331 Please specify the password.

Password:

500 OOPS: cannot
changedirectory:/data/wwwroot/zzftp

Login failed.

ftp>

查看方法

# getenforce

Enforcing   如果出现(Enforcing )

关闭方法:
#setenforce 0       (0|1 
开|关)

或者

setsebool ftpd_disable_trans 1

命令也可以.

这时,你也可以用flashxp软件来测试一下,包括文件和文件夹的权限的变更,上传和删除,重命名命令之类的.

注意:这里目前只有两个虚拟用户,如果要添加新的虚拟用户的话,需要先在/etc/vsftpd/vftpuser.txt里添加,然后再重新用"#db_load -T -t hash -f /etc/vsftpd/vftpuser.txt /etc/vsftpd/vftpuser.db"命令重新生成db库.不过可以写成一个shell来解决这个问题的.

如果登录的时候出现" 500 OOPS: reading non-root config file"错误,只需要将在user_conf/下的配置文件owner改为root 即可.有次我重装安装vsftpd.将上次的配置文件下载到本机上,装好vsftpd,直接将配置覆盖了一下.出现这个问题了.大家以后要注意一下.

为了后面的测试,这们这里上传一个blog程序wordpress.

九.测试web站点

至此为此我们已经把vsftp方面做的差不多了,下面我们来用这个ftp目录来做为网站的根目录,测试一下.这里我用的是Nginx的.如果您用的是apache或者其它类的,请根据实际情况来修改.

这里我采用的是nginx的include指令来添加虚拟主机站点配置信息的,比较的灵活,参考:http://blog.haohtml.com/archives/6203

在/usr/local/nginx/conf/nginx.conf文件里添加了一行 include /usr/local/nginx/conf/vhost/*.conf; (注意不要忘记最后的分号)这样添加虚拟主机站点配置文件时,只需要在/usr/local/nginx/conf/vhost/ 目录里创建一个以.conf为扩展名的文件即可.

vi /usr/local/nginx/conf/vhost/www.haohtml.com.conf

server {

listen 80 default;
server_name www.haohtml.com;
root /data/wwwroot/zzftp;

location / {
index index.php index.html index.shtml;
}

location ~ \.php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param 
SCRIPT_FILENAME  /data/wwwroot/zzftp$fastcgi_script_name;
include       
fastcgi_params;
}

#log...

}

配置内容如上.

十.测试站点

#/usr/local/php/sbin/php-fpm start
#/usr/local/nginx/sbin/nginx -t //测试配置是否正确
#killall nginx
#/usr/local/nginx/sbin/nginx

在浏览器里打开http://www.haohtml.com就会看到这样的页面

对于CentOS5.5下安装NGINX+MYSQL+PHP+MEMCACHE的方法请参考:http://blog.haohtml.com/archives/6051

/etc/vsftpd/vsftpd.conf文件:

# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd whith two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
chroot_local_user=YES
guest_enable=YES
guest_username=ftpadmin
user_config_dir=/etc/vsftpd/vuser_conf
virtual_use_local_privs=YES
chmod_enable=YES

对于我的vsftpd配置文件见:vsftpd.conf


推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 一句话解决高并发的核心原则
    本文介绍了解决高并发的核心原则,即将用户访问请求尽量往前推,避免访问CDN、静态服务器、动态服务器、数据库和存储,从而实现高性能、高并发、高可扩展的网站架构。同时提到了Google的成功案例,以及适用于千万级别PV站和亿级PV网站的架构层次。 ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
  • 本文介绍了在无法联网的情况下,通过下载rpm包离线安装zip和unzip的方法。详细介绍了如何搜索并下载合适的rpm包,以及如何使用rpm命令进行安装。 ... [详细]
  • 负载均衡_Nginx反向代理动静分离负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第二部分
    nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 本文介绍了关于apache、phpmyadmin、mysql、php、emacs、path等知识点,以及如何搭建php环境。文章提供了详细的安装步骤和所需软件列表,希望能帮助读者解决与LAMP相关的技术问题。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • CentOS 7部署KVM虚拟化环境之一架构介绍
    本文介绍了CentOS 7部署KVM虚拟化环境的架构,详细解释了虚拟化技术的概念和原理,包括全虚拟化和半虚拟化。同时介绍了虚拟机的概念和虚拟化软件的作用。 ... [详细]
author-avatar
麦豪小仙
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有