linux环境下搭建FTP服务

本篇文章详细介绍了如何搭建ftp服务器,讲述了一种相对安全的一种配置方案。笔者在CentOS7.6操作系统上进行了实操,完成了配置,一切顺利,希望这篇文章能给初次安装ftp的你,一点小小的帮助!

一、安装

现在ftp安装包,最好是使用rpm包进行安装,因为简单、快捷、方便。
这里使用的是:vsftpd-3.0.2-25.el7.x86_64.rpm
传送门:https://pan.baidu.com/s/1wb_jAcvP0t4rAWh9mPO9Ww

安装的方式有两种:
(1)yum安装

yum -y install vsftpd

(2)手动安装
先将文件包上传到服务器上,再查询系统是否安装ftp

rpm -qa|grep vsftpd

若查询结果为空,则表示没有安装;若查询结果有相关文件显示,则说明已经安装完成。

如果没有安装继续进行安装

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

二、启动

启动ftp

systemctl start vsftpd

查看状态

systemctl status vsftpd

结果:

● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-01-08 16:36:41 CST; 13s ago
  Process: 20246 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 20247 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─20247 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Jan 08 16:36:41 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
Jan 08 16:36:41 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.

三、配置

(一)查看vsftp配置文件

cat /etc/vsftpd/vsftpd.cnf

原件内容如下:

# 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

(二)修改原文件

vi /etc/vsftp/vsftpd.conf

1、关闭匿名登录。

将anonymous_enable的值改为NO

anonymous_enable=NO

2、设置chroot

将chroot取消注释,使配置文件中关于chroot语句生效
修改后的状态:

#chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list

修改后的作用是:仅允许用户访问限定的目录,其余目录均无访问权限。

为了更好的理解chroot的作用,这里有篇文章或许可以帮到你 :)

传送门:https://blog.csdn.net/weixin_43968988/article/details/103894867

(三)编辑choroot_list文件

touch /etc/vsftpd/chroot_list
vi /etc/vsftpd/chroot_list

增加

ftpuser

(四)增加用户

在本次操作中,只允许/home/ftp文件夹可以被ftp用户访问,因此需要对用户设定权限。
使用命令:

useradd -d /home/ftp -s /sbin/nologin userftp

后缀的命令,作用是不允许使用Telnet登录,仅允许ftp端口登录。

-s /sbin/nologin

(五)设置密码

设置密码命令:

passwd userftp

输入密码:

new password:123456
Retype password:123456

出现如下提示可以不予理会。

BAD PASSWORD: The password is shorter than 8 characters

(六)文件授权

chown -R userftp:userftp /home/ftp
chmod 755 /home/ftp

(七)修改密码

查看已经存在的用户,注意要找到自己创建的ftp用户

cat /etc/passwd

使用修改密码命令

passwd userftp

接着输入新的账号密码即可。

(八)重启ftp

systemctl restart vsftpd

四、验证

验证的方式有两种。
(1)浏览器输入网址:ftp://192.168.1.10
连接成功后,输入用户名和密码即可访问指定目录

(2)通过ftp工具连接
输入
主机名:192.168.1.10
端口号:21
用户名:userftp
密码123456
连接成功即可!

五、注意事项

都按照文章上面的提示完成以后,如果连接不上,应该就是网络的问题了。
1、明确21端口是否打开?
2、防火墙是否放行21端口?
3、网络是否正常?
4、and so on…

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值