CentOS安装FTP服务器

下载ftp

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/vsftpd-3.0.2-28.el7.x86_64.rpm

安装ftp

rpm -ivh vsftpd-3.0.2-28.el7.x86_64.rpm

创建ftp用户

        创建用户完成后,可以查看是否有ftp组,和用户的根目录是否对应。

cat /etc/passwd        查看用户的权限信息

cat /etc/group       查看所有的组 

使用本地现有目录

        使用现有的目录时,会有个警报提示,但是不影响创建用户。

useradd -g ftp -s /sbin/nologin -d /zhangsan  zhangsan

-g : 创建用户时,加入到ftp组中。
-s : 表示创建的用户不能登录到ssh上,(云服务器注意)
    cat /etc/shells    用该指令查看是否存在该类型,如果不存在手动添加,如果不存在也可能会报530的密码错误,在客户端上。


-d : 用户的工作目录

        点击回车后,会有个报警提示,可以忽略

使用自动创建的目录

        使用自动创建目录时,会再/home/下自动生成一个与用户名相同的文件夹

useradd -g ftp -s /sbin/nologin zhangsan

配置FTP

# 备份配置

cp -r /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

# 添加新配置

vim /etc/vsftpd/vsftpd.conf

默认配置文件

目前我的vsftpd: version 3.0.2,默认配置文件是这样的,可以适当对照一下是否相同。(不影响)

# 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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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
#
# 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=NO
#
# 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

字段介绍

匿名用户可以不输入用户名密码访问的,权限较为宽松,此处介绍的是本地用户安装。

anonymous_enable=YES    // 匿名帐户可登陆
local_enable=YES    // 本地帐户可以登陆
write_enable=YES    // 用户通过ftp在服务器上是否有写权限
local_umask=022    // 创建时默认权限。计算方式:文件夹=777-umask,文件=666-umask
anon_upload_enable=YES    // 允许匿名帐户上传
anon_mkdir_write_enable=YES   // 允许匿名帐户创建文件夹

anon_other_write_enable=YES   // 允许匿名帐户删除、重命名
anon_root=/ftp    // 更改匿名帐户根目录,默认为"/var/ftp"。

anon_max_rate=0    // 匿名用户最大传输速率,0为无限。


chown_uploads=YES    // 开启匿名帐户上传自动更改所属功能

chown_username=bob    //属主改为bob

user_config_dir=/etc/vsftpd/users   //用户配置文件路径,在users目录中管理每个用户的权限
idle_session_timeout=600   // 空闲会话超时时间
ascii_upload_enable=YES   // 以ASCII方式上传
ftpd_banner=Welcome to blah FTP service. // 欢迎界面


chroot_list_enable=YES   //当设置为 YES 时,vsftpd 将根据 chroot_list_file 指定的文件来决定哪些用户可以被限制在其主目录中。该文件列出了允许进行 chroot 的用户列表。只有在该文件中列出的用户才会受到 chroot_local_user 的限制。其他用户则不受影响,可以在 FTP 会话中访问整个文件系统。正常情况下都是关闭的NO。
chroot_list_file=/etc/vsftpd.chroot_list      //文件中的用户可以更改根目录,如果上面关闭了,这个可以注释掉。

chroot_local_user=YES        //当设置为 YES 时,vsftpd 会将本地用户限制在其主目录中,即用户只能访问自己的主目录,无法访问整个文件系统。

allow_writeable_chroot=YES    //可以打开在chroot目录限制下进行写入和创建操作的权限。


local_root=/local    // 更改本地帐户根目录为/local,默认为用户主目录~
userlist_enable=YES    // 开启用户列表功能
userlist_deny=YES    // 用户列表文件中所有帐户全拒绝。NO时,只有列表中用户能登陆
userlist_file=/etc/vsftpd.user_list // 用户列表文件

listen_port=1802        //修改默认端口,切记监听端口也得开。

listen_ipv6=NO        //监听IPv6的地址

listen=YES        //监听IPV4地址,切记:与IPV6只能共存一个。
local_max_rate=0    // 本地用户最大传输速率,0为无限
max_clients=0     // 最大客户端连接数,0为无限
pasv_max_port=0    // 客户端端口最大限制,0为无限制
pasv_min_port=0    // 客户端端口最小限制,0为无限制

配置FTP文件

# 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
#设置本地用户只可以访问主目录,不可以访问其他目录
chroot_local_user=YES
#禁用本地用户特权文件
chroot_list_enable=NO
#打开本地用户可以在其主目录中,进行写入、删除、下载操作
allow_writeable_chroot=YES
#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.
#
# 监听IPv4协议,端口号为8021
listen=YES
listen_port=8021
#
# 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 !!a
# 不监听ipv6协议,两个只能共存一个。
listen_ipv6=NO

#ftp默认采用的是pam认证
pam_service_name=vsftpd


#一个简单的防火墙
tcp_wrappers=YES

#开启被动模式
pasv_enable=YES

#设置被动模式的端口限制
pasv_max_port=21110
pasv_min_port=21100

(1)  该配置文件中指向的是/zhangsan目录,切记不要设置成/root(本级目录或者是目录下)。会报如下报错。这里我把zhangsan改成到/目录就可以了。

500 OOPS: cannot change directory:/root/zhangsan

(2)配置文件中设置了文件中的用户无法更改根目录的功能,所以需要创建chroot_list文件,并将zhangsan用户添加进去。

vim /etc/vsftpd/chroot_list

(3)配置文件中设置了用户列表文件,表示只有列表中的用户才能登录,所以需要将zhangsan用户添加到user_list文件中。

(4)此处设置的端口范围是21100-21110,所以需要防火墙放通,云服务器的话也是要开启端口。

(5)如果不想使用默认的21端口,可以在配置文件中修改字段,增加一个listen_port=1802字段。切记需要防火墙放通端口。

启动ftp

# 查看状态

systemctl status vsftpd

# 启动ftp

systemctl start vsftpd

# 重启

systemctl restart vsftpd

# 开机自启

systemctl enable vsftpd

# 关闭开机自启

systemctl disable vsftpd

# 停止

systemctl stop vsftpd

关闭防火墙

vim /etc/selinux/config

SELINUX值改为 disabled

#开启21端口

firewall-cmd --zone=public --add-port=21/tcp --permanent

#开启30000端口

firewall-cmd --zone=public --add-port=21100-21110/tcp --permanent

#刷新配置

firewall-cmd --reload

卸载ftp

rpm -aq vsftpd

rpm -e vsftpd-2.0.5-16.el5_5.1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值