标签:ftps ase port xferlog vsftp服务 param hat 搜索 ice
VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是Very Secure FTP 从此名称可以看出来,编制者的初衷是代码的安全。
安全性是编写VSFTP的初衷,除了这与生俱来的安全特性以外,高速与高稳定性也是VSFTP的两个重要特点。
在速度方面,使用ASCII代码的模式下载数据时,VSFTP的速度是Wu-FTP的两倍,如果Linux主机使用2.4.*的内核,在千兆以太网上的下载速度可达86MB/S。
在稳定方面,VSFTP就更加的出色,VSFTP在单机(非集群)上支持4000个以上的并发用户同时连接,根据Red Hat的Ftp服务器(ftp.redhat.com)的数据,VSFTP服务器可以支持15000个并发用户。
安装vsftp需要用到root权限,尽可能的在root用户下进行安装
切换root权限 sudo su -
1. 检查vsftp是否安装
rpm -qa vsftp [无结果表明没有安装]
2. 安装vsftp
yum install -y vsftpd
[root@m01 ~]# yum install -y vsftpd
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-24.el6 will be installed
--> Finished Dependency Resolution
...
Installed:
vsftpd.x86_64 0:2.2.2-24.el6
Complete! --- 安装完成
3. 创建一个日志文件来记录ftp上传下载的记录
touch /var/log/vsftpd.log
检查vsftp开机启动选项[yum安装后会自动添加开机启动,但是并没有配置,如果需要开机启动则进行配置]
查看开机启动: chkconfig --list|grep vsftpd
[root@m01 ~]# chkconfig --list|grep vsftpd
vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
设置35级别开机启动:
[root@m01 ~]# chkconfig --level 35 vsftpd on
[root@m01 ~]# chkconfig --list | grep vsftpd
vsftpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
3.服务的启动关闭
方式1:
vsftpd安装完成后会默认添加到系统服务和init中 所以可以使用以下方法查看和启动服务
/etc/init.d/vsftpd status | [/etc/init.d/vsftpd {start|stop|restart|try-restart|force-reload|status}] 常用 start|stop|restart 这3个
方式2:
[root@m01 ~]# service vsftpd status [start|stop|restart|try-restart|force-reload|status]
vsftpd is stopped
一般常用 start|stop|restart
start 启动
stop 停止
restart 重新启动
4.vsftp配置权限
了解配置权限之前需要先了解配置文件,如何查看配置文件?
rpm -ql vsftpd 命令可以看到软件安装路径,以及配置文件
重要的配置文件:
/etc/vsftpd/ftpusers ---禁止登录用户的黑名单列表
/etc/vsftpd/user_list ---允许登录的用户白名单列表
/etc/vsftpd/vsftpd.conf ---vftp的重要配置信息
问题:
这里看到两个user,那么ftpusers和user_list两个文件各自的用途是什么?有何关系?
ftpusers 这是一个黑名单用户列表,也就是禁止登录的 比如可以设置 root禁止登录来保证ftp安全
来看下这个配置文件让你更加清晰你在做什么:
[root@m01 ~]# cat /etc/vsftpd/ftpusers
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
这些都是被禁止登录的用户
5. vsftpd.conf 配置文件
这里东西较多,理解就好
先来查看配置并解释:
vim /etc/vsftpd/vsftpd.conf
==========================vsftpd.conf===========================================
# 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
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
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
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
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
#
# 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
====================================================================================
看起来很多,如果解释完过滤出需要配置的 你会发现也没多少
[root@m01 ~]# grep -v "#" /etc/vsftpd/vsftpd.conf 【过滤出的都是默认配置】
anonymous_enable=YES ----匿名用户 yes 为允许 no为拒绝 //不允许匿名用户访问,默认是允许
local_enable=YES ----本地模式是否开启 yes 开机 no 关闭 这里默认即可 不需要修改 就是验证本地用户用的
write_enable=YES ----是否开启写入权限 默认yes
local_umask=022 ----umask值 这是设置权限的掩码,默认即可
dirmessage_enable=YES ----这是登录是否显示进入目录标语 默认即可
xferlog_enable=YES ----日志功能 这个默认开启 日志地址/var/log/vsftpd.log
connect_from_port_20=YES ----默认连接端口 不用改
xferlog_std_format=YES ----用于设置vsftpd的服务日志保存路径,不用改
listen=YES
pam_service_name=vsftpd ----设定pam服务下vsftpdd的验证配置文件名,不用改
userlist_enable=YES ----拒绝登录用户名单,不用改
TCP_wrappers=YES ----限制主机对VSFTP服务器的访问,不用改(通过/etc/hosts.deny和/etc/hosts.allow这两个文件来配置)
配置ftp账户:
1、修改/etc/vsftpd/vsftpd.conf,将底下三行
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
改为
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
2、增加用户ftpuser,指向目录/home/wwwroot/ftpuser,禁止登录SSH权限。
useradd -d /home/wwwroot/ftpuser -g ftp -s /sbin/nologin ftpuser
3、设置用户口令
passwd ftpuser
4、编辑文件chroot_list(内容为ftp用户名,每个用户占一行):
vi /etc/vsftpd/chroot_list
启用pasv模式
pasv_enable=YES #启用被动模式
pasv_min_port=10000 #被动模式使用端口范围
pasv_max_port=10010 #被动模式使用端口范围
第五步、针对第四步开启防火墙端口,如果没有启用pasv模式就可以不用管
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10000:10010 -j ACCEPT
在以上工序完成后,连接ftp时出现了个错误
500 OOPS: vsftpd: cannot locate user specified in ‘ftp_username‘:ftp
经过网络搜索,得到下面的解决办法
在/etc/vsftpd.conf中添加一行ftp_username=nobody就搞定
ftp测试连接
在连接之前要确认是否安装了ftp命令
rpm -qa ftp
没有安装就直接安装
yum install -y ftp
安装完成测试连接ftp服务器
[root@db01 ~]# ftp 10.0.0.61
Connected to 10.0.0.61 (10.0.0.61).
220 (vsFTPd 2.2.2)
Name (10.0.0.61:root): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
# 方法一
# 创建用户 ftpuser 指定 `/home/vsftpd` 目录
useradd -g root -M -d /home/vsftpd -s /sbin/nologin ftpuser
# 设置用户 ftpuser 的密码
passwd ftpuser
# 把 /home/vsftpd 的所有权给ftpuser.root
mkdir /home/vsftpd -p
chown -R ftpuser.root /home/vsftpd
# 方法二
useradd ftpuser -d /home/vsftpd -s /bin/false
chown ftpuser:ftpuser /home/vsftpd -R
# 如果虚拟用户的宿主用户为www,需要这样设置
# www目录是你应用的目录
chown www:www /home/www -R
ftp上传下载操作命令:
bin 二进制传输模式
prompt 上传提示开关 多文件上传建议改为off
mput 上传
mget 下载 上传下载均可以使用* 进行通配
lcd 切换本地目录
cd 切换ftp目录
登录演示:
ftp 10.0.0.61
Connected to 10.0.0.61 (10.0.0.61).
220 (vsFTPd 2.2.2)
Name (10.0.0.61:root): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp>
ftp> ls
227 Entering Passive Mode (10,0,0,61,156,196).
150 Here comes the directory listing.
226 Directory send OK.
标签:ftps ase port xferlog vsftp服务 param hat 搜索 ice
原文地址:https://www.cnblogs.com/superlinux/p/12874943.html