vps建站教程 CentOS6如何安装配置FTP服务器

苏苏 苏苏
17082
2015-05-04

通过之前的几篇文章,我们都知道了如何配置PHP环境,也知道如何保护我们的vps以及如何绑定多个域名建设多个网站。有时候我们为了让我们的朋友也能用我们的vps建站又不想给他们太多权限,有时候我们想要当个主机商卖卖虚拟空间过过瘾又不想装管理环境,那么就想要装个ftp服务器了。

经过前面的教程,相信大家对管理vps的操作是比较熟悉了,这里我就不在截图了,安装ftp服务器也是比较简单的,相信大家可以轻松学会。

 

一安装环境

1.先检查有没有安装   rpm -q vsftpd
如果没有安装   yum install vsftpd

2.先关闭防火墙进行调试.

service iptables stop

或者一步到位   添加规则允许21端口通行
vi /etc/sysconfig/iptables

添加一条 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

为了让FLASHFXP之类的软件更好的连接服务器,得让VSFTPD支持被动模式才行:

b.防火墙配置开放:

-A INPUT -p tcp --dport 30000:30100 -j ACCEPT
重启防火墙即可
service iptables restart

这时应该可以用 winscp进行 SFTP连接了  ROOT帐户
现在开始设置FTP   默认的已经可以用匿名登录了

二。备份 etc/vsftpd/vsftpd.conf
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

编辑vsftpd.config文件   vi /etc/vsftpd/vsftpd.conf

anonymous_enable=NO
设定不允许匿名用户访问。

为了让FLASHFXP之类的软件更好的连接服务器,得让VSFTPD支持被动模式才行,上面已经开通相应端口防火墙,在最后加入
pasv_enable=YES
pasv_max_port=30100
pasv_min_port=30000
(上面的30000--30100端口号可以是其它的,在此举例)

/usr/sbin/setenforce 0 立刻关闭 SELINUX

#mkdir /tmp/test   //首先创建好目录

#adduser -d /tmp/test -g ftp -s /sbin/nologin test


//-s /sbin/nologin是让其不能登陆系统,-d 是指定用户目录为/tmp/test ,即该账户只能登陆ftp,却不能用做登陆系统用。-g 是指定为FTP用户组

#passwd test

Changing password for user beinan.//接下来会出现让你设置新的密码

**************************************************
【如果要删除用户,用下面代码:
userdel test      //userdel + 用户 即可删除ftp用户】
***********************************************************

有必要的话  设置TEST目录权限

修改/var/www目录属性:
$ chmod -R 777 /var/www 递归地给此目录下所有文件和子目录的读、写、执行权限
$ chgrp -R ftp   /var/www 递归地把此目录及该目录下所有文件和子目录的组属性设置成ftp组

 

三。接着 限制用户目录,不得改变目录到上级

修改/etc/vsftpd/vsftpd.conf
将这两行
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
注释去掉
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

新增一个文件: /etc/vsftpd/chroot_list
内容写需要限制的用户名:
test

重新启动vsftpd

# service vsftpd restart

  

四。最后为了防止服务器由于断电、重启等现象发生,导致ftp进程在开机后未启动,将其添加到开机启动文件中:

(1)找到/etc/rc.local文件

(2)打开该文件,在最后一行添加:service vsftpd start

(3)保存,退出

 

 

附:vsftpd的配置文件说明:
vsftpd.ftpusers:位于/etc目录下。它指定了哪些用户账户不能访问FTP服务器,例如root等。
vsftpd.user_list:位于/etc目录下。该文件里的用户账户在默认情况下也不能访问FTP服务器,仅当vsftpd .conf配置文件里启用userlist_enable=NO选项时才允许访问。
vsftpd.conf:位于/etc/vsftpd目录下。来自定义用户登录控制、用户权限控制、超时设置、服务器功能选项、服务器性能选项、服务器响应消息等FTP服务器的配置。
(1)用户登录控制
anonymous_enable=YES,允许匿名用户登录。
no_anon_password=YES,匿名用户登录时不需要输入密码。
local_enable=YES,允许本地用户登录。
deny_email_enable=YES,可以创建一个文件保存某些匿名电子邮件的黑名单,以防止这些人使用Dos攻击。
    banned_email_file=/etc/vsftpd.banned_emails,当启用deny_email_enable功能时,所需的电子邮件黑名单保存路径(默认为/etc/vsftpd.banned_emails)。
(2)用户权限控制
write_enable=YES,开启全局上传权限。
local_umask=022,本地用户的上传文件的umask设为022(系统默认是077,一般都可以改为022)。
anon_upload_enable=YES,允许匿名用户具有上传权限,很明显,必须启用write_enable=YES,才可以使用此项。同时我们还必须建立一个允许ftp用户可以读写的目录(前面说过,ftp是匿名用户的映射用户账号)。
anon_mkdir_write_enable=YES,允许匿名用户有创建目录的权利。
chown_uploads=YES,启用此项,匿名上传文件的属主用户将改为别的用户账户,注意,这里建议不要指定root账号为匿名上传文件的属主用户!
chown_username=whoever,当启用chown_uploads=YES时,所指定的属主用户账号,此处的whoever自然要用合适的用户账号来代替。
chroot_list_enable=YES,可以用一个列表限定哪些本地用户只能在自己目录下活动,如果chroot_local_user=YES,那么这个列表里指定的用户是不受限制的。
     chroot_list_file=/etc/vsftpd.chroot_list,如果chroot_local_user=YES,则指定该列表(chroot_local_user)的保存路径(默认是/etc/vsftpd.chroot_list)。
nopriv_user=ftpsecure,指定一个安全用户账号,让FTP服务器用作完全隔离和没有特权的独立用户。这是vsftpd系统推荐选项。
async_abor_enable=YES,强烈建议不要启用该选项,否则将可能导致出错!
ascii_upload_enable=YES;ascii_download_enable=YES,默认情况下服务器会假装接受ASCⅡ模式请求但实际上是忽略这样的请求,启用上述的两个选项可以让服务器真正实现ASCⅡ模式的传输。
注意:启用ascii_download_enable选项会让恶意远程用户们在ASCⅡ模式下用“SIZE/big/file”这样的指令大量消耗FTP服务器的I/O资源。
这些ASCⅡ模式的设置选项分成上传和下载两个,这样我们就可以允许ASCⅡ模式的上传(可以防止上传脚本等恶意文件而导致崩溃),而不会遭受拒绝服务攻击的危险。
(3)用户连接和超时选项
idle_session_timeout=600,可以设定默认的空闲超时时间,用户超过这段时间不动作将被服务器踢出。
data_connection_timeout=120,设定默认的数据连接超时时间。
(4)服务器日志和欢迎信息
dirmessage_enable=YES,允许为目录配置显示信息,显示每个目录下面的message_file文件的内容。
ftpd_banner=Welcome to blah FTP service,可以自定义FTP用户登录到服务器所看到的欢迎信息。
xferlog_enable=YES,启用记录上传/下载活动日志功能。
xferlog_file=/var/log/vsftpd.log,可以自定义日志文件的保存路径和文件名,默认是/var/log/vsftpd.log。
anonymous_enable=YES 允许匿名登录local_enable=YES 允许本地用户登录
write_enable=YES 开放本地用户写权限
local_umask=022 设置本地用户生成文件的掩码为022
#anon_upload_enable=YES 此项设置允许匿名用户上传文件
#anon_mkdir_write_enable=YES 开启匿名用户的写和创建目录的权限
dirmessage_enable=YES 当切换到目录时,显示该目录下的.message隐藏文件的内容
xferlog_enable=YES 激活上传和下载日志
connect_from_port_20=YES 启用FTP数据端口的连接请求
#chown_uploads=YES 是否具有上传权限. 用户由chown_username参数指定。
#chown_username=whoever 指定拥有上传文件权限的用户。此参数与chown_uploads联用。
#xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES 使用标准的ftpd xferlog日志格式
#idle_session_timeout=600 此设置将在用户会话空闲10分钟后被中断
#data_connection_timeout=120 将在数据连接空闲2分钟后被中断
#ascii_upload_enable=YES 启用上传的ASCII传输方式
#ascii_download_enable=YES 启用下载的ASCII传输方式
#ftpd_banner=Welcome to blah FTP service 设置用户连接服务器后显示消息
#deny_email_enable=NO 此参数默认值为NO。当值为YES时,拒绝使用banned_email_file参数指定文件中所列出的e-mail地址用户登录。
#banned_email_file=/etc/vsftpd.banned_emails 指定包含拒绝的e-mail地址的文件.
#chroot_list_enable=YES 设置本地用户登录后不能切换到自家目录以外的别的目录
#chroot_list_file=/etc/vsftpd.chroot_list
#ls_recurse_enable=YES
pam_service_name=vsftpd 设置PAM认证服务的配置文件名称,该文件存放在/etc/pam.d/
userlist_enable=YES 此项配置/etc/vsftpd.user_list中指定的用户也不能访问服务器,若添加userlist_deny=No,则仅仅/etc/vsftpd.user_list文件中的用户可以访问,其他用户都不可以访问服务器。如过userlist_enable=NO,userlist_deny=YES,则指定使文件/etc/vsftpd.user_list中指定的用户不可以访问服务器,其他本地用户可以访问服务器。
listen=YES 指明VSFTPD以独立运行方式启动
tcp_wrappers=YES 在VSFTPD中使用TCP_Wrappers远程访问控制机制,默认值为YES

  


#***********************************************************************
#附 vsftpd.conf 配置,完整版
#***********************************************************************
# Example config file /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=YES
#
# 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

#######################################################################

 


vps 绑定域名:http://www.138vps.com/jzjc/81.html

vps 安全:http://www.138vps.com/vpsjc/73.html

vps 配置php环境:http://www.138vps.com/jzjc/71.html



特别申明: 若无说明,文章均为原创,转载时请注明本文地址,谢谢合作!

本站仅为分享信息,绝对不是推荐,所有内容均仅代表个人观点,读者购买风险自担。如果你非要把风险推苏苏头上,不要这么残忍,好吗?
本站保证在法律范围内您的个人信息不经由本站透露给任何第三方。
所有网络产品均无法保证在中国任何地区,任何时间,任何宽带均有相同的访问体验,那种号称某机房绝不抽风的不是骗子就是呵呵.
任何IDC都有倒闭和跑路的可能,备份永远是最佳选择,服务器也是机器,不勤备份是对自己极不负责的表现.

加入群1:569839985

欢迎IDC提交优惠信息或者测试样机,提交信息请Eamil至admin#138vps.com,苏苏不保证一定会进行发布。

但请IDC留意以下内容:
无官方正式首页、无可用联络方式暂不发布;
曾经有过倒闭和跑路经历者重开不到6个月不做发布;
从本日起(2016-07-18)不接受任何形式的免费赞助和VPS馈赠,不接受任何评测报告的投稿,不接受任何付费发布和付费删除评论,所有IDC若有必要提交测试样机,请在7日后自行删除。
公告
欢迎加入qq群:569839985
本站诚换友情链接。在您的网站加上本站的友情链接后发邮件到 admin#138vps.com, 苏苏会自行审核,一周内会上线您的友情链接。
要求:建站一年以上,百度权重1,收录数量不低于一千。
请尽量使用 PayPal 进行交易,PayPal 对资金的保护政策更照顾买家。
年度爆文