摘要

vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点。vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux、BSD、Solaris、 HP-UNIX等系统上面,是一个完全免费的、开放源代码的ftp服务器软件,支持很多其他的 FTP 服务器所不支持的特征。比如:非常高的安全性需求、带宽限制、良好的可伸缩性、可创建虚拟用户、支持IPv6、速率高等。

vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。(来自百度百科)

安装vsftpd

检测是否已经安装vsftpd。

[root@localhost ~]# rpm -qa | grep vsftpd
[root@localhost ~]#

什么都不显示就没有安装

安装vsftpd

使用yum安装
[root@localhost ~]# yum -y install vsftpd
使用rpm安装
[root@localhost local]# rpm -ivh vsftpd-3.0.2-21.el7.x86_64.rpm 

启动服务

[root@localhost local]# service vsftpd start
Redirecting to /bin/systemctl start vsftpd.service

查看服务状态

[root@localhost local]# service vsftpd status
Redirecting to /bin/systemctl status vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2017-08-30 15:28:18 CST; 15min ago
Process: 4295 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 4296 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─4296 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf 8月 30 15:28:18 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
8月 30 15:28:18 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.
Hint: Some lines were ellipsized, use -l to show in full.

Active: active (running) 启动状态,可以使用

现在我们就可以匿名访问了

vsftpd添加用户

vsftpd添加用户

FTP用户一般是不能登录系统的,只能进入FTP服务器自己的目录中,这是为了安全.这样的用户就叫做虚拟用户了.实际上并不是真正的虚拟用户,只是不能登录SHELL了而已,没能力登录系统.

添加用户命令

/usr/sbin/adduser -d /opt/test_ftp -g ftp -s /sbin/nologin test2

上面的命令是添加一个 名称为 test2的用户。

命令解析:使用命令(adduser)添加test2用户,不能登录系统(-s /sbin/nologin),自己的文件夹在(-d /opt/test_ftp)),属于组ftp(-g ftp).

为该用户设置密码

[root@localhost local]# passwd test2

现在重启服务我们就可以使用test2直接访问我们的 /opttest_ftp目录了

给用户权限上传下载,修改

虽然用户能够进行查看,但是还没有权限上传、下载和修改

授权

[root@localhost local]# chmod 755 /opt/test_ftp

编辑配置文件

一般创建一个ftp 用户,作为管理员只希望它只能访问其自己的所属目录的,是不会让他选择其他目录的。

设置ftp用户的权限

在安装好ftp时,在 /etc/vsftpd目录下可以看到vsftpd的配置文件vsftpd.conf

[root@localhost vsftpd]# vim 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.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
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/xferlog
#
# 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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
# vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误的解决方法
allow_writeable_chroot=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. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then 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
anon_other_write_enable=YES
#anon_root=/opt/test_ftp
#guest_enable=YES
#guest_username=test2
virtual_use_local_privs=YES

用户访问权限及路径限制:

如果 userlist_deny=NO:只允许userlist_file文件中的用户可访问ftp;如果 userlist_deny=YESuserlist_file文件中列举的用户不能通过ftp访问系统。userlist_enable是该功能的开关。我们的系统配置如下:

userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list

把需要登录的用户加入到/etc/vsftpd/user_list文件中,一个用户一行。

如果我们不需要把登陆的用户限制在主目录下需要一下配置:

进入主配置文件中chroot_list_enable=YES

创建用户文件/etc/vsftpd/chroot_list

vim /etc/vsftpd/chroot_list

将不需要限制的用户添加进去,我们只有一个test2,一行一个用户名

ps: 这些用户将能访问全部有权限的文件。

设置权限

[root@localhost vsftpd]# getsebool -a|grep ftp
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
pd_connect_db --> off
▽tpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_home_dir --> off
开启 anon_write 和full_access
[root@localhost vsftpd]# setsebool allow_ftpd_anon_write  1
[root@localhost vsftpd]# setsebool allow_ftpd_full_access 1

重启ftp服务

[root@localhost vsftpd]# service vsftpd restart 

测试

注:测试连接软件是FileZilla,windows访问 ftp://[ip]

update 20170901 使用FileZilla创建中文文件夹Linux乱码

首先出现这个问题的原因是WINDOWS采用的是GBK编码方式,而Linux采用的是UTF-8

首先设置好FileZilla的编码方式为zh_CN

在将 /etc/locale.conf 中的LANG修改为"zh_CN.UTF-8"

[root@localhost ~]# vim /etc/locale.conf
LANG="zh_CN.UTF-8"

这个修改可以有效解决windows客户端使用ftp协议上传中文文件到Linux乱码的问题。

其实最根本的解决方法是客户端上传的文件经过ftp软件能与服务器统一编码方式,具体百度吧c#、java的都有。

博客地址

linux上搭建ftp服务器的更多相关文章

  1. CentOS Linux上搭建PPPoE服务器及拨号设置

    CentOS Linux上搭建PPPoE服务器及拨号设置 搭建PPPoE,成功了的话,就觉得超级简单,在CentOS Linux更是5步左右就能搞定. 1.安装pppoe,安装完成后,会有pppoe- ...

  2. linux上构建ftp服务器

    linux上构建ftp服务器 服务器搭建 https://help.aliyun.com/knowledge_detail/60152.html,可以参考这篇博文. 配置文件详解 进入/etc/vsf ...

  3. 【转】Linux环境搭建FTP服务器与Python实现FTP客户端的交互介绍

    Linux环境搭建FTP服务器与Python实现FTP客户端的交互介绍 FTP 是File Transfer Protocol(文件传输协议)的英文简称,它基于传输层协议TCP建立,用于Interne ...

  4. linux上搭建ftp

    linux上搭建ftp 重要 解决如何搭建ftp         解决用户指定访问其根目录         解决访问ftp超时连接         解决ftp主动连接.被动连接的问题 1.安装ftp ...

  5. linux上搭建ftp、vsftp, 解决访问ftp超时连接, 解决用户指定访问其根目录,解决ftp主动连接、被动连接的问题

    linux上搭建ftp 重要 解决如何搭建ftp         解决用户指定访问其根目录         解决访问ftp超时连接         解决ftp主动连接.被动连接的问题 1.安装ftp ...

  6. Linux上的ftp服务器vsftpd之配置满天飞--设置匿名用户访问(不弹出用户名密码框)以及其他用户可正常上传

    一.问题背景 没事谁折腾这鬼玩意哦...还不是因为bug. 我们的应用,用户头像是存在ftp上的.之前的ftp服务器是一台windows,我们后台服务器程序收到用户上传头像的请求时,会用一个ROOT/ ...

  7. 【转】【FTP】之windows8.1上搭建FTP服务器方法

    参考地址:<windows8.1上搭建FTP服务器方法>

  8. linux系统搭建ftp服务器及创建用户使用

    linux 系统下搭建ftp服务器 ftp是什么 FTP是 File Transfer Protocol 文件传输协议的英文名称,用于在Internet上控制文件的双向传输. 同时它也是一个应用程序. ...

  9. 如何在windows上搭建ftp服务器

    FTP(File Transfer Protocol)是TCP/IP网络上两台计算机传送文件的协议,使得主机间可以共享文件.目前有很多软件都能实现这一功能,然而windows自带的IIS就可以帮助你搭 ...

随机推荐

  1. API创建员工支付方式

    DECLARE ln_method_id PAY_PERSONAL_PAYMENT_METHODS_F.PERSONAL_PAYMENT_METHOD_ID%TYPE; ln_ext_acc_id P ...

  2. FFmpeg API 变更记录

    最近一两年内FFmpeg项目发展的速度很快,本来是一件好事.但是随之而来的问题就是其API(接口函数)一直在发生变动.这么一来基于旧一点版本的FFmpeg的程序的代码在最新的类库上可能就跑不通了. 例 ...

  3. Android性能优化之Splash页应该这样设计

    目前SplashActivity的设计 目前市场上的应用在启动时基本上都会先启动一个SplashActivity,作为一个欢迎界面,为什么这样设计呢? 个人总结有三个优点: 1.可以给用户更好的体验 ...

  4. 深入浅出Java Dom4j读取XML

    在以前自己使用的xml较少,只是了解其很强大,现在可算是在DRP中,真正的开始使用它了,以前只是简单的理解xml,xml即可扩展标记语言,简单的使用,具体是什么?怎么用?还是一直让自己期待的. 首先来 ...

  5. 【一天一道LeetCode】#86. Partition List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  6. 【一天一道LeetCode】#82. Remove Duplicates from Sorted List II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  7. Demand Side Platform

    DSP特点: DSP不是从网络媒体那里包买广告位,也不是采用CPD(Cost Per Day)的方式获得广告位:而是从广告交易平台(AdExchange)来通过实时竞价的方式获得对广告进行曝光的机会, ...

  8. C语言实现万年历

    给出你想知道的年份,便可以计算出该年对应的每个月每个日所对应的星期数,是不是感觉很好玩 ? #include <stdio.h> #include<stdlib.h> long ...

  9. (NO.00001)iOS游戏SpeedBoy Lite成形记(五)

    在GameScene.m中添加matchRun的实现: -(void)matchRun{ CCLOG(@"%@ invoke!",NSStringFromSelector(_cmd ...

  10. Linux下ipconfig分析及C语言实现

    在linux下使用ifconfigl命令能很方便的查看网卡与网线是否连通,运行ifconfig eth0命令大致输出如下: # ifconfig eth0 eth0 Link encap:Ethern ...