0
点赞
收藏
分享

微信扫一扫

linux安装vsftpd

慕犹清 2022-04-05 阅读 133

linux安装vsftpd

安装vsftpd作为附件上传和下载服务


文章目录


一、vsftpd是什么?

vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux, BSD, Solaris, HP-UX 以及 IRIX 上面。它支持很多其他的 FTP 服务器不支持的特征。

二、使用步骤

1.安装

检查服务器是否已经安装FTP
rpm -qa | grep vsftpd
如果已存在则先卸载
yum remove vsftpd
我这里是新的服务器	所以就直接安装vsftpd 
yum install vsftpd -y

在这里插入图片描述

安装成功

在这里插入图片描述

2.配置

设置用户的信息和权限
解释一下这句命令
添加一个用户名为qingdgj的用户属于root组 
登录的时候默认进入/home/ftp目录
不能通过shell登录只能 通过ftp登录
useradd -g root -d /home/ftp-s /sbin/nologin qingdgj
给这个用户设置密码
passwd qingdgj
输入的密码是不会在页面上显示的

在这里插入图片描述

设置文件夹权限(注意用户名)

在这里插入图片描述

修改配置文件
vim /etc/vsftpd/vsftpd.conf
这里给出一份说明
#配置信息  需要修改服务器ip和端口号
#是否允许匿名用户访问
anonymous_enable=NO
#是否允许本地用户登录FTP
local_enable=YES
#是否允许登陆用户有写权限,默认值为 YES。
write_enable=YES
#匿名用户上传文件的umask值
local_umask=022
dirmessage_enable=YES
#是否启用上传/下载日志记录。如果启用,则上传与下载的信息将被完整纪录在 xferlog_file 所定义的档案中。
xferlog_enable=YES
#端口监听
port_enable=YES
#指定 FTP使用 20端口进行数据传输,默认值为 YES。
connect_from_port_20=YES
#若启用此选项,所有的 FTP请求和响应都会被记录到日志中,默认日志文件在/var/log/vsftpd.log。
#启用此选项时,xferlog_std_format不能被激活。这个选项有助于调试。默认值为 NO。
xferlog_std_format=YES
#设置是否启用 ASCII 模式上传数据。默认值为 NO。
ascii_upload_enable=YES
#设置是否启用 ASCII 模式下载数据。默认值为 NO。
ascii_download_enable=YES
ls_recurse_enable=YES
#设置 FTP服务器建立连接所监听的端口,默认值为 21。
listen=YES
#设置 FTP服务器建立连接所监听的端口,默认值为 21。
listen_port=xxx端口号
pam_service_name=vsftpd
##设置用户列表为“允许”还是“禁止”操作  当在/etc/vsftpd.conf中设置了userlist_deny=NO时,仅仅允许/etc/vsftpd.user_list中指定的用 户访问FTP服务器。
userlist_deny=NO
#设置用户列表为“允许”还是“禁止”操作
userlist_enable=YES
##设置用户列表
userlist_file=/etc/vsftpd/user_list
#被动模式开关
pasv_enable=YES
#被动模式最小端口
pasv_min_port=xxx端口号
#被动模式最大端口
pasv_max_port=xxx端口号
#本地在公网ip
pasv_address=服务器ip
pasv_addr_resolve=YES
#匿名用户的最大传输速率(字节/秒),0为不限制
anon_max_rate=512000
#本地用户最大传输速率(字节/秒),0为不限制
local_max_rate=512000
#允许ip变化  防止 425 Security: Bad IP connecting.
pasv_promiscuous=YES

在这里插入图片描述

配置修改好之后启动ftp服务
systemctl start vsftpd.service
查看ftp服务状态

在这里插入图片描述

用ftp工具连接一下  可以成功连接 上传和下载文件

在这里插入图片描述
在这里插入图片描述

3.可能出现的问题

-------------------------------------------------------------
命令:	USER qingdgj
响应:	331 Please specify the password.
命令:	PASS ***********
响应:	530 Login incorrect.
错误:	严重错误: 无法连接到服务器
-------------------------------------------------------------

第一种情况:selinux的ftp设置

这里centos6和centos7是不一样的 
如果selinux是开启的 则要设置
#查看selinux中ftp的相关配置
sestatus -b | grep ftp
如果显示 ftp_home_dir  off 则需要打开
#selinux设置(这里给出centos7设置方法)
sudo setsebool -P tftp_home_dir 1
如果不想设置也可以关闭selinux

第二种情况:可能是防火墙的原因

可以选择关闭防火墙 或者开启对应的端口
# ftp被动模式 端口
firewall-cmd --zone=public --add-port=起始端口-结束端口/tcp --permanent
# ftp登录端口
firewall-cmd --zone=public --add-port=xxx端口/tcp --permanent
# 购买的云服务器
如果是阿里云、腾讯云的服务器 需要在安全组里面开启对应的规则

第三种情况:pam.d设置问题

在前面的ftp配置的时候设置了 pam_service_name=vsftpd 这个属性
我们只要把 pam_shells.so 改成pam_nologin.so即可

在这里插入图片描述

4.建议

建议在修改原来的配置文件时都对原来的配置文件进行一下备份,以防操作不当引起的问题。
这里提供一份原版配置(版本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.
# 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


总结

	安装ftp服务容易遇到一些小问题,上面列举的是比较常见的几种情况,
希望能对大家有所帮助。感谢你的阅读。
举报

相关推荐

0 条评论