linux搭建vsftp服务器

1)安装问题html

vsftp属于linux自带的service,所以在安装linux的时候就能够勾选安装,若是当时未安装,后来又须要,那么能够找出原始安装iso文件,提取/Packages路径下面的rpm进行安装,建议不要随便在网上找rpm,由于rpm可能会跟本身的linux不兼容,而报错,好比说是libcrypto.so.4找不到,若是是tar.gz安装make的时候可能会报找不到cap_init,总之就是依赖问题很差解决,所以最好仍是去安装光盘里面找原配的rpm进行安装。若是服务端能访问外网,也建议用yum安装。yum能自动下载安装包之间的依赖包,省去因为依赖包产生的麻烦。linux

2)简单使用(使用/etc/vsftpd/vsftpd.conf的默认配置shell

启动ftp命令:[root@localhost]# service vsftpd start windows

查看ftp状态命令[root@localhost]# service vsftpd status 安全

重启ftp命令[root@localhost]# service vsftpd restart session

关闭ftp命令[root@localhost]# service vsftpd stopapp

默认状况下,只须要把公共文件放在/var/ftp,匿名用户就能够免登陆下载了。socket

3)简要说明下vsftp的相关信息async

/usr/sbin/vsftpd ---- VSFTPD的主程序tcp

/etc/rc.d/init.d/vsftpd ---- 启动脚本

/etc/vsftpd/vsftpd.conf ---- 主配置文件

/etc/pam.d/vsftpd ---- PAM认证文件

/etc/vsftpd.ftpusers ---- 禁止使用VSFTPD的用户列表文件

/etc/vsftpd.user_list ---- 禁止或容许使用VSFTPD的用户列表文件

/var/ftp ---- 匿名用户主目录

/var/ftp/pub ---- 匿名用户的下载目录

4)异常处理

有的文件可能会下载失败,这里如下载dd.conf失败做为例子,

失败的缘由是权限不够,以下,

[root@localhost ftp]# ll
总用量 130640
-rw-r--r--. 1 liyang liyang       379  9月 28 15:40 2.txt
-rw-------. 1 root   root        4567  9月 28 15:38 dd.conf
-rw-------. 1 root   root         125  3月  4 2011 ftpusers
-rw-r--r--. 1 liyang liyang  17473536  9月 28 15:19 help_20140313_v1.0.doc

解决方法是赋权限,之后再下载就正常了。

[root@localhost ftp]# chmod 777 dd.conf

5)经过/etc/vsftpd/vsftpd.conf配置ftp用户进行上传

5.1 ftp的用户帐户是借用了linux系统用户的帐户,根据这个规则,本人建立系统用户ftpadmin,密码为peidian1#,

[root@localhost ayu]# useradd -d /var/common -s /sbin/nologin ftpadmin
[root@localhost ayu]# passwd ftpadmin
更改用户 ftpadmin 的密码 。
新的 密码:
从新输入新的 密码:
passwd: 全部的身份验证令牌已经成功更新。

这里简单注明下密码设置问题,linux的密码安全机制要求密码须要有必定的复杂度,这里就不深刻研究。另外,/sbin/nologin这里是限制了ftpadmin这个用户没有系统登陆的权限,只能用做ftp登陆。最后,-d设置了ftpadmin用户的“家目录”/var/common,若是命令为useradd -s /sbin/nologin ftpadmin,那么“家目录”默认就是/home/ftpadmin

5.2)防火墙iptables)限制访问的问题

关闭iptables服务,执行service iptables stop,再查看是否关闭成功执行service iptables status

5.3)SELinux的问题

须要执行一行命令,[root@localhost]#setsebool -P ftp_home_dir on,而后查看 SELinux 的状态: sestatus -b | grep ftp,确保ftp_home_dir状态为on。重启ftp服务 [root@localhost]# service vsftpd restart,不然会发生500 OOPS child died或者是200 PORT command successful. Consider using PASV.553 Could not create file.问题都是SELinux引发的。

关闭SELinux,vi /etc/sysconfig/selinux,修改成SELINUX=disabled,重启便可,若是不但愿重启那么能够执行setenforce 0,不过这种方式只是本次生效。

配置完SELinux后就能够进行上传操做了。用户名:ftpadmin,密码:peidian1#,上传的路径为/var/common

5.4)上传文件字符集编码的问题(文件名带中文上传后乱码问题)

Windows的字符集编码是GBK/GB18030,而Linux使用utf8编码,所以在上传带有中文字符文件名的文件时,就会发生文件名乱码的问题。建议不要为此去修改linux的字符集编码,由于“全盘颠覆”的话的会得不偿失。解决方案是用ftp客户端工具,客户端工具代理上传下载规定编码为UTF8就不会出现乱码的问题。

给出FlashFXP下载地址:http://pan.baidu.com/s/1hqvYQwO

点击“链接”按钮便可连上,能够在log信息栏看到字符集编码默认为UTF8,不须要另外设置,以下,

5.5)ftp用户(如ftpadmin)上传文件到匿名下载目录的问题

这里须要特别注意,若是仅仅把匿名访问目录设置为/var/common,那么会出现匿名访问时被强制要求输入用户名/密码的状况,通过本人的不断尝试总结出一种方法来(暂时没法解释缘由),但能够实现权限用户ftp上传到匿名访问目录的效果。

1.用root用户建立一个目录/var/ftpcommon

2.执行chown ftpadmin:ftpadmin /var/ftpcommon,也就是将路径/var/ftpcommon的全部者由root转给ftpadmin

3.配置匿名访问目录和权限用户访问目录为/var/ftpcommon,附上本人配置好的/etc/vsftpd/vsftpd.conf,其实也就是在默认配置增长了

anon_root=/var/ftpcommon
local_root=/var/ftpcommon
chroot_local_user=YES

,完整配置以下,

# 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
#
# Activate logging of uploads/downloads.
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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
anon_root=/var/ftpcommon
local_root=/var/ftpcommon
chroot_local_user=YES
#
# 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 with 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

对配置的说明:

# 禁止匿名用户anonymous登陆
anonymous_enable=YES

# 容许本地用户登陆
local_enable=YES
# 让登陆的用户有写权限(上传,删除)
write_enable=YES

更改匿名用户和登陆用户(这里主要用于ftpadmin)默认目录,

anon_root=/var/ftpcommon

local_root=/var/ftpcommon

chroot_local_user=YES

anon_root表示匿名用户登陆到ftp时的默认目录,local_root表示使用本地用户登陆到ftp时的默认目录,chroot_local_user表示限制登陆用户登陆后只能访问本身的“家目录”,而这里全部用户的家目录都被统一设置为/var/ftpcommon这里有一篇帖子助于了解关于chroot_local_user:http://blog.csdn.net/bluishglc/article/details/42398811

5.6)用cmd命令行访问ftp有助于排错,ftp访问失败时,windows客户端错误提示信息远远不如cmd命令提示全面

准确,经常使用cmd访问ftp命令以下,

1.登陆命令,输入"ftp 210.10.3.61"或者输入"ftp"回车,再输入"open 210.10.3.61"

2.匿名登陆,输入"anonymous",要求输入密码时直接敲回车;权限用户登陆,输入用户名/密码

3.查看文件列表,输入"dir",查看本地文件列表请输入"!dir"

4.上传,输入"put 文件名";下载,输入"get 文件名"

5.切换路径输入"cd 路径名" 


除了本博客提到的这些,vsftp还有可配置匿名用户上传但不能删除的,还可配置虚拟ftp用户,而后能用mount挂载的方式,这些有待进一步研究,使用cmd命令行去进行ftp的get和put操做也是有意思的,这些也须要记录,可是目前时间有限。http://jingyan.baidu.com/article/0bc808fc8778ee1bd485b93b.html

http://www.linuxeden.com/html/netadmin/20120101/118712.html

http://www.linuxidc.com/Linux/2010-03/24798.htm(mount挂载??)

http://www.jbxue.com/article/2928.html

http://blog.chinaunix.net/uid-28898468-id-4273229.html

添加chroot_list:http://blog.sina.com.cn/s/blog_4b93170a0100mdm3.html

比较全:http://blog.sina.com.cn/s/blog_715b47c50101k1bx.html

http://andyzhao.blog.51cto.com/794987/183617

iptables??http://www.open-open.com/lib/view/open1413513821934.html

pasv?http://my.oschina.net/weisky/blog/305280

相关文章
相关标签/搜索