GVKun编程网logo

CentOS6.5下搭建ftp服务器(三种认证模式:匿名用户、本地用户、虚拟用户)

6

关于CentOS6.5下搭建ftp服务器和三种认证模式:匿名用户、本地用户、虚拟用户的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于centos6.5下vsftp虚拟用户配置、Centos

关于CentOS6.5下搭建ftp服务器三种认证模式:匿名用户、本地用户、虚拟用户的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于centos 6.5下 vsftp 虚拟用户配置、Centos 6.5下安装vsftp本地用户、CentOS 6.5下快速搭建ftp服务器、CentOS 6.5下搭建vsftp服务器等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

CentOS6.5下搭建ftp服务器(三种认证模式:匿名用户、本地用户、虚拟用户)

CentOS6.5下搭建ftp服务器(三种认证模式:匿名用户、本地用户、虚拟用户)

CentOS 6.5下搭建ftp服务器

vsftpd(very secure ftp daemon,非常安全的FTP守护进程)是一款运行在Linux操作系统上的FTP服务程序,不仅完全开源而且免费,此外,还具有很高的安全性、传输速度,以及支持虚拟用户验证等其他FTP服务程序不具备的特点,下面开始搭建:

1、用root 进入系统

2、使用命令 rpm  -qa | grep vsftpd 查看系统是否安装了ftp,若安装了vsftp,使用这个命令会在屏幕上显示vsftpd的版本 

3、如果安装了,可以使用命令 rpm -e vsftpd 即可卸载ftp

4、再使用 rpm  -qa | grep vsftpd 查看系统是否已删除ftp,若删除成功,屏幕上不显示vsftpd的版本

一、安装vsftpd:

查看是否已经安装vsftpd
rpm -qa | grep vsftpd

如果没有,就使用yum安装,并设置开机启动
yum -y install vsftpd

分享图片

 

#设置开机启动
chkconfig vsftpd on

分享图片

 

#查看vsftpd服务是否为开机启动,如下图说明是开机启动

chkconfig --list vsftpd

分享图片

 

#查看vsftp的服务状态

service vsftpd status  或者

/etc/init.d/vsftpd status

 

分享图片

 

管理vsftpd相关命令:

启动 vsftpd:  service vsftpd start

停止 vsftpd:  service vsftpd stop

重启 vsftpd:  service vsftpd restart

 

二、分别配置三种认证模式(匿名用户、本地用户、虚拟用户)参数:

iptables防火墙管理工具默认禁止了FTP传输协议的端口号,因此在正式配置vsftpd服务程序之前,为了避免这些默认的防火墙策略“捣乱”,还需要清空iptables防火墙的默认策略,并把当前已经被清理的防火墙策略状态保存下来:

 

[[email protected] ~]# iptables -F
[[email protected] ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

vsftpd服务程序的主配置文件(/etc/vsftpd/vsftpd.conf)内容总长度达到123行,但其中大多数参数在开头都添加了井号(#),从而成为注释信息,大家没有必要在注释信息上花费太多的时间。我们可以在grep命令后面添加-v参数,过滤并反选出没有包含井号(#)的参数行(即过滤掉所有的注释信息),然后将过滤后的参数行通过输出重定向符写回原始的主配置文件中:

[[email protected] ~]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_bak
[[email protected] ~]# grep -v "#" /etc/vsftpd/vsftpd.conf_bak > /etc/vsftpd/vsftpd.conf
[[email protected] ~]# cat /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

表11-1中罗列了vsftpd服务程序主配置文件中常用的参数以及作用。

 

表11-1                                     vsftpd服务程序常用的参数以及作用

 

参数 作用
listen=[YES|NO] 是否以独立运行的方式监听服务
listen_address=IP地址 设置要监听的IP地址
listen_port=21 设置FTP服务的监听端口
download_enable=[YES|NO] 是否允许下载文件
userlist_enable=[YES|NO]
userlist_deny=[YES|NO]
设置用户列表为“允许”还是“禁止”操作
max_clients=0 最大客户端连接数,0为不限制
max_per_ip=0 同一IP地址的最大连接数,0为不限制
anonymous_enable=[YES|NO] 是否允许匿名用户访问
anon_upload_enable=[YES|NO] 是否允许匿名用户上传文件
anon_umask=022 匿名用户上传文件的umask值
anon_root=/var/ftp 匿名用户的FTP根目录
anon_mkdir_write_enable=[YES|NO] 是否允许匿名用户创建目录
anon_other_write_enable=[YES|NO] 是否开放匿名用户的其他写入权限(包括重命名、删除等操作权限)
anon_max_rate=0 匿名用户的最大传输速率(字节/秒),0为不限制
local_enable=[YES|NO] 是否允许本地用户登录FTP
local_umask=022 本地用户上传文件的umask值
local_root=/var/ftp 本地用户的FTP根目录
chroot_local_user=[YES|NO] 是否将用户权限禁锢在FTP目录,以确保安全
local_max_rate=0 本地用户最大传输速率(字节/秒),0为不限制

Vsftpd服务程序

vsftpd作为更加安全的文件传输的服务程序,允许用户以三种认证模式登录到FTP服务器上。

 

匿名开放模式:是一种最不安全的认证模式,任何人都可以无需密码验证而直接登录到FTP服务器。

 

本地用户模式:是通过Linu系统本地的账户密码信息进行认证的模式,相较于匿名开放模式更安全,而且配置起来也很简单。但是如果被黑客破解了账户的信息,就可以畅通无阻地登录FTP服务器,从而完全控制整台服务器。

 

虚拟用户模式:是这三种模式中最安全的一种认证模式,它需要为FTP服务单独建立用户数据库文件,虚拟出用来进行口令验证的账户信息,而这些账户信息在服务器系统中实际上是不存在的,仅供FTP服务程序进行认证使用。这样,即使黑客破解了账户信息也无法登录服务器,从而有效降低了破坏范围和影响。

 在Windows系统下可以使用浏览器、CuteFTP软件以及ftp命令(和Linux系统上的ftp命令功能一样)等方式来访问FTP服务器上的资源,在这里我们使用CuteFTP软件。

在CuteFTP软件界面上单击菜单栏上的【文件】—>【新建】—>【FTP站点】,打开如下图所示的对话框,在该对话框的【一般】选项中输入站点标签、FTP主机地址、FTP站点用户名称、FTP站点密码、登录方法;如果登录方法选择【匿名】,则无须输入FTP站点用户名称和FTP站点密码。还有在【类型】选项卡中指定FTP站点的端口号,默认端口为21,然后单击【连接】按钮。

分享图片

分享图片

1.  匿名访问模式:

前文提到,在vsftpd服务程序中,匿名开放模式是最不安全的一种认证模式。任何人都可以无需密码验证而直接登录到FTP服务器。这种模式一般用来访问不重要的公开文件(在生产环境中尽量不要存放重要文件)。

vsftpd服务程序默认开启了匿名开放模式,我们需要做的就是开放匿名用户的上传、下载文件的权限,以及让匿名用户创建、删除、更名文件的权限。需要注意的是,针对匿名用户放开这些权限会带来潜在危险,我们只是为了在Linux系统中练习配置vsftpd服务程序而放开了这些权限,不建议在生产环境中如此行事。表11-2罗列了可以向匿名用户开放的权限参数以及作用。

 

表11-2                                 可以向匿名用户开放的权限参数以及作用

 

参数 作用
anonymous_enable=YES 允许匿名访问模式
anon_umask=022 匿名用户上传文件的umask值
anon_upload_enable=YES 允许匿名用户上传文件
anon_mkdir_write_enable=YES 允许匿名用户创建目录
anon_other_write_enable=YES 允许匿名用户修改目录名称或删除目录

 

 

 

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf
1 anonymous_enable=YES
2 anon_umask=022
3 anon_upload_enable=YES
4 anon_mkdir_write_enable=YES
5 anon_other_write_enable=YES
6 local_enable=YES
7 write_enable=YES
8 local_umask=022
9 dirmessage_enable=YES
10 xferlog_enable=YES
11 connect_from_port_20=YES
12 xferlog_std_format=YES
13 listen=NO
14 listen_ipv6=YES
15 pam_service_name=vsftpd
16 userlist_enable=YES
17 tcp_wrappers=YES

在vsftpd服务程序的主配置文件中正确填写参数,然后保存并退出。还需要重启vsftpd服务程序,让新的配置参数生效。在此需要提醒各位读者,在生产环境中或者在RHCSA、RHCE、RHCA认证考试中一定要把配置过的服务程序加入到开机启动项中,以保证服务器在重启后依然能够正常提供传输服务:

service vsftpd restart    #重启ftp服务

chkconfig vsftpd on #把ftp服务加入到开机启动项中

现在就可以在用Windows下的CuteFTP软件连接到远程的FTP服务器了。在vsftpd服务程序的匿名开放认证模式下,其账户统一为anonymous,密码为空。而且在连接到FTP服务器后,默认访问的是/var/ftp目录。我们可以先到Linux系统下查看是否有/var/ftp目录:

分享图片

 

然后,打开Windows下的CuteFTP软件,输入标签,主机地址,选择匿名登录,单击连接:

 

分享图片

 

分享图片

 

如上图所示,我们已经成功连接上了FTP服务器,我们先来试着在pub文件夹中创建一个文件,系统显示拒绝创建目录!我们明明在前面清空了iptables防火墙策略,而且也在vsftpd服务程序的主配置文件中添加了允许匿名用户创建目录和写入文件的权限啊。先不要着急,往下看。

前文提到,在vsftpd服务程序的匿名开放认证模式下,默认访问的是/var/ftp目录。查看该目录的权限得知,只有root管理员才有写入权限。怪不得系统会拒绝操作呢!下面将目录的所有者身份改成系统账户ftp即可(该账户在系统中已经存在),这样应该可以了吧:

ls -ld /var/ftp/pub

chown -Rf ftp /var/ftp/pub

 

分享图片

 

系统再次报错!尽管我们在使用ftp命令登入FTP服务器后,再创建目录时系统依然提示操作失败,但是报错信息却发生了变化。在没有写入权限时,系统提示“权限拒绝”(Permission denied)所以老师怀疑是权限的问题。但现在系统提示“创建目录的操作失败”(Create directory operation Failed),其实这里是SELinux服务在“捣乱”。

下面使用getsebool命令查看与FTP相关的SELinux域策略都有哪些:

# getsebool -a | grep ftp

分享图片

   

我们可以根据经验(需要长期培养,别无它法)和策略的名称判断出是 ftpd_full_access--> off 策略规则导致了操作失败。接下来修改该策略规则,并且在设置时使用-P参数让修改过的策略永久生效,确保在服务器重启后依然能够顺利写入文件。

注意:在实验课程和生产环境中设置SELinux域策略时,一定记得添加-P参数,否则服务器在重启后就会按照原有的策略进行控制,从而导致配置过的服务无法使用。

# setsebool -P allow_ftpd_full_access=on

分享图片

 现在便可以顺利执行文件创建、修改及删除等操作了。

分享图片

2.  本地用户模式:

相较于匿名开放模式,本地用户模式要更安全,而且配置起来也很简单。如果大家之前用的是匿名开放模式,现在就可以将它关了,然后开启本地用户模式。针对本地用户模式的权限参数以及作用如表11-3所示。

表11-3                                   本地用户模式使用的权限参数以及作用

 

参数 作用
anonymous_enable=NO 禁止匿名访问模式
local_enable=YES 允许本地用户模式
write_enable=YES 设置可写权限
local_umask=022 本地用户模式创建文件的umask值
userlist_deny=YES 启用“禁止用户名单”,名单文件为ftpusers和user_list
userlist_enable=YES 开启用户作用名单文件功能

 

 

 

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf
1 anonymous_enable=NO
2 local_enable=YES
3 write_enable=YES
4 local_umask=022
5 dirmessage_enable=YES
6 xferlog_enable=YES
7 connect_from_port_20=YES
8 xferlog_std_format=YES
9 listen=NO
10 listen_ipv6=YES
11 pam_service_name=vsftpd
12 userlist_enable=YES
13 tcp_wrappers=YES

 

在vsftpd服务程序的主配置文件中正确填写参数,然后保存并退出。还需要重启vsftpd服务程序,让新的配置参数生效。

# service vsftpd restart

按理来讲,现在已经完全可以本地用户的身份登录FTP服务器了。但是在使用root管理员登录后,CuteFTP显示连接不上:

分享图片

分享图片

 

可见,在我们输入root管理员的密码之前,就已经被系统拒绝访问了。这是因为vsftpd服务程序所在的目录中默认存放着两个名为“用户名单”的文件(ftpusersuser_list)。vsftpd服务程序目录中的这两个文件只要里面写有某位用户的名字,就不再允许这位用户登录到FTP服务器上。分别打开 ftpusers 和 user_list 这两个文件,删除里面的root,然后保存并退出。

vim /etc/vsftpd/user_list

 

分享图片

vim /etc/vsftpd/ftpusers

 

分享图片

果然如此!vsftpd服务程序为了保证服务器的安全性而默认禁止了root管理员和大多数系统用户的登录行为,这样可以有效地避免黑客通过FTP服务对root管理员密码进行暴力破解。如果您确认在生产环境中使用root管理员不会对系统安全产生影响,只需按照上面的提示删除掉root用户名即可。我们也可以选择 ftpusersuser_list 文件中没有的一个普通用户尝试登录FTP服务器:

分享图片

 在采用本地用户模式登录FTP服务器后,默认访问的是该用户的家目录,也就是说,访问的是/home/CentOS目录。而且该目录的默认所有者、所属组都是该用户自己,因此不存在写入权限不足的情况。如果想更改访问目录,在 vim /etc/vsftpd/vsftpd.conf 这个文件下输入 local_root=/***/***,路径和文件名,保存并退出。

分享图片

最后记得重启ftp服务
 service vsftpd restart

本文参考自:《Linux就该这么学》    刘遄     著 

centos 6.5下 vsftp 虚拟用户配置

centos 6.5下 vsftp 虚拟用户配置

一:基本知识
1
:虚拟用户:与系统无关联,不能登入系统,只能访问FTP服务器
2:vsftp的服务进程是vsftpd
3:vsftpd的配置文件是/etc/vsftpd/vsftpd.conf.
4:vsftpd的用户文件是/etc/vsftpd/ftpusers
5:vsftpd的用户文件是/etc/vsftpd/user_list
6:推荐使用虚拟用户登入vs-FTP服务器

二、安装vsftp

查看是否安装vsftpd服务

1. [root@localhost~]#chkconfig--list
如果没有安装,安装vsftpd服务

1. [root@localhost~]#yum-yinstallvsftpd

三、配置虚拟用户

1)检查服务器selinux是否开启,如果开启,关闭selinux

1. [root@localhost~]#/usr/sbin/sestatus-v

2. SELinuxstatus:enabled

1.1)关闭selinux方法

修改/etc/selinux/config 文件, 将SELINUX=enforcing改为SELINUX=disabled, 重启机器即可

2)创建虚拟用户文本文件,添加虚拟用户和密码

1. [root@localhost~]#cd/etc/vsftpd/

2. [root@localhost~]#touchvuser.txt

奇数行是用户名,偶数是密码
比如:
lowkeyman
123456

3)生成虚拟数据库文件(*如果db_load没有安装,yum install db4-utils db4-develdb4-4.3安装才能使用。

1. [root@localhost~]#db_load–T–thash–f/etc/vsftpd/vuser.txt/etc/vsftpd/vuser.db

4)配置PAM文件,目的是对客户端进行验证

编辑/etc/pam.d/vsftpd文件,批注所有内容,后添加:

1. authrequiredpam_userdb.sodb=/etc/vsftpd/vuser

2. accountrequiredpam_userdb.sodb=/etc/vsftpd/vuser

*不能写成db=/etc/vsftpd/vuser.db
5
)修改虚拟数据库文件vuser.db的权限为 700

1. [root@localhost~]#chmod700vuser.db

6)增加一个系统用户vuser ,使用它来对应所有虚拟用户,虚拟用户使用系统用户来访问ftp服务器。

1. [root@localhost~]#mkdir/vsftp

2. [root@localhost~]#useradd-d/var/ftp/pub-s /sbin/nologinvuser

3. [root@localhost~]#chownvuser:vuser/var/ftp/pub

7)修改vsftpd.conf配置文件,使虚拟用户可以访问vsftpd服务器,增加以下参数

修改/etc/vsftpd/vsftpd.conf如下:

anonymous_enable=NO(是否允许匿名登录FTP 服务器,默认设置为YES 允许,即用户可使用用户名ftp 或anonymous 进行ftp 登录,口令为空。如 不允许匿名访问设置为NO)

local_enable=YES(是否允许本地用户登录FTP服务器,默认设置为YES允许,本地用户登录后会进入指定的用户主目录,而匿名用户登录后进入匿名用户的下载目录/var/ftp/pub;设置虚拟账户必须设会YES)

local_umask=022(设置本地用户的文件掩码为缺省022,得到上传文件的初始权限)

#anon_upload_enable=YES(是否允许匿名用户上传文件,须将write_enable=YES,默认设置为YES 允许)

#anon_mkdir_write_enable=YES(是否允许匿名用户创建新文件夹,默认设置为YES允许)

xferlog_enable=YES(默认值为NO如果启用此选项,系统将会维护记录服务器上传和下载情况的日志文件,默认情况该日志文件为/var/log/vsftpd.log,也可以通过下面的xferlog_file 选项对其进行设定)

connect_from_port_20=YES(设定 FTP 服务器将启用FTP数据端口的连接请求,端口20为ftp-data数据传输,21 为连接控制端口)

#chown_uploads=YES(设定是否允许改变上传文件的属主,与下面一个设定项配合使用)

#chown_username=whoever(设置想要改变的上传文件的属主,如果需要,则输入一个系统用户名,例如可以把上传的文件都改成root 属主。whoever任何人)

#xferlog_file=/var/log/xferlog(设定系统维护记录FTP 服务器上传和下载情况的日志文件,/var/log/vsftpd.log是默认的,也可以另设其它)

xferlog_std_format=YES

idle_session_timeout=600(设置数据传输中断间隔时间,此语句表示空闲的用户会话中断时间为600秒,即当数据传输结束后,用户连接FTP服务器的时间不应超过600秒,可以根据实际情况对该值进行修改)

#data_connection_timeout=120(设置数据连接超时时间,该语句表示数据连接超时时间为120秒,可根据实际情况对其修改)

#nopriv_user=ftpsecure(运行 vsftpd 需要的非特权系统用户,缺省是nobody)

#async_abor_enable=YES

#ascii_upload_enable=YES

#ascii_download_enable=YES

#ftpd_banner=Welcome to blah FTP service.

#deny_email_enable=YES

#banned_email_file=/etc/vsftpd/banned_emails

#chroot_list_enable=YES(设置为 NO 时,用户登录FTP 服务器后具有访问自己目录以外的其他文件的权限,设置为 YES时,用户被锁定在自己的宿主目录中,vsftpd 将在下面 chroot_list_file 选项值的位置寻找 chroot_list 文件,此文件需用户建立,再将需锁定在自己宿主目录的用户列入其中,每行一个用户)

# (default follows)

#chroot_list_file=/etc/vsftpd/chroot_list(此文件需自己建立,被列入此文件的用户,在登录后将不能切换到自己目录以外的其他目录,由 FTP 服务器自动地 chrooted 到用户自己的home 目录下,使得 chroot_list 文件中的用户不能随意转到其他用户的FTP home 目录下,从而有利于FTP 服务器的安全管理和隐私保护)

listen=YES(如果设置为YES,则 vsftpd 将以独立模式运行,由vsftpd 自己监听和处理连接请求)

#listen_ipv6=YES(设定是否支持IPV6

pam_service_name=vsftpd(设置 PAM 外挂模块提供的认证服务所使用的配置文件名,即/etc/pam.d/vsftpd 文件,此文件中file=/etc/vsftpd/ftpusers 字段,说明了PAM 模块能抵挡的帐号内容来自文件/etc/vsftpd/ftpusers 中)

userlist_enable=YES(此选项默认值为NO,则不启用user_list文件;若此项设为YES ,则启用user_list 文件,而如果同时设置了 userlist_deny=YES ,则 user_list 文件中的用户将不允许登录FTP 服务器,甚至连输入密码提示信息都没有,直接被FTP 服务器拒绝,如果userlist_deny=NO,将则只允许user_list文件中的用户登陆FTP服务器)

userlist_deny=YES(若已启用userlist_enable项,此项默认为YES,则阻止user_list 文件中的用户登录FTP 服务器;反之,则只允许user_list文件中的用户登录)

tcp_wrappers=YES(表明服务器使用tcp_wrappers作为主机访问控制方式)

write_enable=NO(决定是否允许一些FTP命令去更改文件系统。包括上传文件,删除文件,新增目录,删除目录)

download_enable=NO(决定是否允许下载文件,如果设为NO,下载请求将返回“permission denied”)

guest_enable=YES(如果启用,所有的非匿名用户登录时将被视为游客,其名字将被映射为guest_username里所指定的名字。采用虚拟用户必须设置该选项)

guest_username=vuser(设置当游客进入后,其将会被映射的名字。这里设置为“vuser”,即虚拟用户登陆ftp后被映射的本地用户名)

virtual_use_local_privs=YES(虚拟用户和本地用户权限相同。很重要,保证虚拟用户有和映射的本地用户相同的权限)

chroot_local_user=YES(设置虚拟用户被锁定在自己的宿主目录中。)

user_config_dir=/etc/vsftpd/user_config(定义用户配置文件的目录)

上表中标红的参数为重要的修改项,每项参数都在其后面的括号中有简单的说明。当然还有其他的很多参数来配置VSFTPD,这里不一一例句,附录中将会进行统一的说明。



1. guest_enable=YES####激活虚拟账户

2. guest_username=vuser####把虚拟账户绑定为系统账户vuser

3. pam_service_name=vsftpd####使用PAM验证

8)设置虚拟用户的主配置文件,编辑vsftpd.conf文件,添加:

1. user_config_dir=/etc/vsftpd/vsftpd_user_conf

9)建立vsftpd_user_conf

1. [root@localhost~]#mkdir/etc/vsftpd/vsftpd_user_conf

10)设置虚拟用户配置文件,与虚拟账户同名

1. [root@localhost~]#touch/etc/vsftpd/vsftpd_user_conf/lowkeyman

11)编辑虚拟账户lowkeyman的配置文件lowkeyman,是虚拟账户lowkeyman获得相应的权限

1. anon_world_readable_only=NO###浏览FTP目录和下载

2. anon_upload_enable=YES###允许上传

3. anon_mkdir_write_enable=YES###建立和删除目录

4. anon_other_write_enable=YES####改名和删除文件

5. local_root=/var/ftp/pub####指定虚拟用户在系统用户下面的路径,限制虚拟用户的家目录,虚拟用户登录后的主目录。

Centos 6.5下安装vsftp本地用户

Centos 6.5下安装vsftp本地用户

Centos 6.5下安装vsftp------本地用户

准备工作:

检查防火墙和selinux,并关闭;

service iptables stop c6的版本用这个;如果要用,就开启2021端口;

chkconfig iptables off ;

sestatus先查看selinux的状态,

如果不是disable可用vi/etc/selinux/config

   将SELINUX=XXX -->XXX 代表级别

    改为SELINUX=disabled

Selinux关闭要重启下,reboot;

Setenforce 0 临时设置为中等级别

Getenforce 获取selinux当前的设置;

一: FTP安装

1:安装 :

rpm�Cqa |grep ftp 先查看有没有装;

yum�Cy install ftp vsftpd*

yum�Cy install pam //安全验证;

2、配置FTP参数

1、)修改/etc/vsftpd/vsftpd.conf相关参数。

ch确保该配置文件中,存在以下信息。注意要将配置项前面的#去掉,配置才生效。

anonymous_enable=NO //是否接受匿名用户访问

local_enable=YES //是否接受本地用户

local_umask=022//本地账户的权限掩码

write_enable=YES //是否可以上传,写操作, 全局

anon_upload_enable=YES //匿名用户是否可以上传

anon_mkdir_write_enable=YES //匿名用户是否可以建目录

ascii_upload_enable=YES //管控是否可用ASCII模式上传

ascii_download_enable=YES //管控是否可用ASCII模式下载

dirmessage_enable=YES//进入目录是否显示消息

xferlog_enable=YES//是否开启xferlog日志功能

connect_from_port_20=YES//使用主动模式连接,启用20端口

ftpd_banner=Welcome to blah FTP service.//欢迎语

listen=YES//是否监听端口,;

chroot_list_enable=YES//是否启用本地账户列表

# (default follows)

chroot_list_file=/etc/vsftpd/chroot_list //列表文件路径

//自己在/vsftpd下面新建一个chroot_list,加入要用的账户;

spacer.gif

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES //是否启用tcp_wrappers

pasv_enable=YES #//是否启用被动模式连接,默认为被动;

#pasv_promiscuous=YES #//混合模式;

#listen_port=2134 #//监听入站FTP请求的端口号,指定端口;

pasv_max_port=5999

pasv_min_port=5900

dual_log_enable=YES //表明启用了双份日志。在用xferlog文件记录服务器上传下载情况的同时,vsftpd_log_file所指定的文件,即/var/log/vsftpd.log,也将用来记录服务器的传输情况

#chroot_local_user=YES //是否禁锢本地账户根目录,默认为No

#local_root=/ftp目录 //本地账户访问FtP根路径;一般不用

#最后去#号和文字,当全部做完时#chroot_local_user=YES

//本地目录锁定在自家目录中此(参数只需要在文件服务器上配置)

2、)通过root用户访问FTP功能

注释掉 vim/etc/vsftpd/ftpusers(黑名单)中的root; #root

注释掉 vim/etc/vsftpd/user_list(白名单)中的root ; #root

注:userlist_deny=yes则为黑名单,=N0,则为白名单;-àuser_list

3、)启动与关闭FTP服务

启动命令#service vsftpd start

关闭命令#service vsftpd stop

重启命令#service vsftpd restart

4、)修改登录用户限制

/etc/pam.d/vsftpd 文件中的 auth required pam_shells.so注释掉因为此文件对登录用户进行了限制 : vim /etc/pam.d/vsftpd

# authrequired pam_shells.so

5、)设置FTP服务 自动启动

方法一:

[root@cti-m ~]#chkconfig vsftpd on ; chkconfig �Caddtelnet

[root@cti-m ~]#service vsftpd restart

[root@cti-m ~]#chkconfig �Clist vsftpd

方法二:

把service vsftpd start 加入/etc/rc.local即可。

6、)创建、配置FTP目录权限 (如果没有目录的情况下)

#mkdir /ftpserver (如果是上传的文件服务器,就不要再建了)

#chmod -R 777 /ftpserver

7、)创建ftp帐号,访问FTP

[root@hzhost]#groupadd fileftp

[root@hzhost]#useradd-G fileftp(用户组) -d /fileserver(目录)-s /bin/bash admin

[root@hzhost]#passwd admin

/bin/bash,是可以访问shell的用户,/bin/nologin是不能访问的账户;

下面这些只能在在文件服务器上配置(如是同一个地方,就一起建,有报提示,没事)

useradd -g fileftp-d /fileserver/1 -s /bin/bash admin1

passwd admin1

将username加到user_list文件;vim/etc/vsftpd/user_list;

spacer.gif

查看cat/etc/passwd ; 修改用:usermod �Cd /根目录绝对路径 admin

spacer.gif

Cat /etc/group; 修改用:usermod �CG 附加组 admin

spacer.gif

如果目录只给一个用户用的话,可以这样设置:

chown admin:fileftp ftpserver-R

然后开启本地账户的禁锢;重启服务

chroot_local_user=YES (如果禁锢了,反而不行,就再关掉)

local_root=/home/cmsuploader 指定目录;一般不指定;

测试:

现在用帐号admin访问FTP,就相当于访问服务器上的/fileserver目录,可进行上传下载文件。(运行cmd) 或打开我的电脑,用地址栏测试下:

spacer.gif

spacer.gif

admin对应 /ftpserver 目录

admin1对应 /ftpserver/1 目录

然后用浏览器测试:

spacer.gif

spacer.gif

如果是主动模式请修改配置:

spacer.gif


附: cmd下的ftp 测试:

spacer.gif

命令有:ftp,open close dirls,put get,mkdir rmdir,delete ..bye 等;

PUT -----get 举例: 默认系统用户的家目录;

spacer.gif

spacer.gif


9. lcd D:\ftpin
/*定位本地默认文件夹。这里的lcd命令类似于平时命令行下的cd*/

spacer.gif

然后就可以上传下载东西的;

10. !dir
/*查看本地文件夹中的文件及目录*/

spacer.gif

ftp://test:test123@121.40.191.88:21 直接访问地址

CentOS 6.5下快速搭建ftp服务器

CentOS 6.5下快速搭建ftp服务器

CentOS6.5下快速搭建ftp服务器

1、用root 进入系统

2、使用命令 rpm -qa|grep vsftpd 查看系统是否安装了ftp,若安装了vsftp,使用这个命令会在屏幕上显示vsftpd的版本

3、使用命令rpm -e vsftpd 即可卸载ftp

4、再使用rpm -qa|grep vsftpd 查看系统是否已删除ftp,若删除成功,屏幕上显示vsftpd的版本

一:安装vsftpd

查看是否已经安装vsftpd
rpm -qa | grep vsftpd

如果没有,就安装,并设置开机启动
yum -y install vsftpd
chkconfig vsftpd on

安装时发现错误:

Loaded plugins: fastestmirror,refresh-packagekit,security
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base

是因为缺少DNS,解决如下:到/etc目录下配置resolv.conf加入nameserver IP:
[root@localhost ~]# vi /etc/resolv.conf

#下面地址是福建电信DNS
nameserver 218.85.157.99

管理vsftpd相关命令:

启动vsftpd: service vsftpd start

停止vsftpd: service vsftpd stop

重启vsftpd: service vsftpd restart

二、配置防火墙

打开/etc/sysconfig/iptables文件
vi /etc/sysconfig/iptables

在REJECT行之前添加如下代码
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

保存和关闭文件,重启防火墙
service iptables start

三、配置vsftpd服务器

1.默认的配置文件是/etc/vsftpd/vsftpd.conf,你可以用文本编辑器打开。
vi /etc/vsftpd/vsftpd.conf

2.添加ftp用户

下面是添加ftpuser用户,设置根目录为/home/wwwroot/ftpuser,禁止此用户登录SSH的权限,并限制其访问其它目录。
#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

3.增加用户ftpuser,指向目录/home/wwwroot/ftpuser,禁止登录SSH权限。
useradd -d /home/wwwroot/ftpuser -g ftp -s /sbin/nologin ftpuser

4.设置用户口令
passwd ftpuser

5、编辑文件chroot_list:
vi /etc/vsftpd/chroot_list

内容为ftp用户名,每个用户占一行,如:

peter
john

6、重新启动vsftpd
service vsftpd restart

另外,如果觉得以后管理ftp用户名嫌麻烦,可以使用centos官方发布的脚本管理。地址如下:(未用过)

http://wiki.centos.org/HowTos/Chroot_Vsftpd_with_non-system_users

----------------------------------

出现的错误

1、500 OOPS: cannot change directory
解决方法:

在终端输入命令:

1.setsebool -P ftpd_disable_trans 1

2.service vsftpd restart

就OK了!
原因:这是因为服务器开启了selinux,这限制了FTP的登录。

本文永久更新链接地址http://www.linuxidc.com/Linux/2015-10/123848.htm

CentOS 6.5下搭建vsftp服务器

CentOS 6.5下搭建vsftp服务器

VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是Very Secure FTP 从此名称可以看出来,编制者的初衷是代码的安全。
下面说说在CentOS 6.5_64位系统下安装VSFTP步骤
1.查看linux系统版本和内核信息
[root@vmware1 ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@vmware1 ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
2.关闭防火墙和selinux。
[root@vmware1 ~]# /etc/init.d/iptables stop
[root@vmware1 ~]# chkconfig iptables off
[root@vmware1 ~]# setenforce 0
3.安装vsftp软件包。
[root@vmware1 ~]# yum install -y vsftpd
先备份vsftpd的默认配置文件;
[root@vmware1 ~]# cd /etc/vsftpd/
[root@vmware1 vsftpd]# cp vsftpd.conf vsftpd.conf.bak
4.清空vsftpd.cong默认的内容。
root@vmware1 vsftpd]# >vsftpd.conf
5.修改后的内容为:
[root@vmware1 vsftpd]# cat 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.
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

11.重启vsftpd,然后查看端口是否开启。
[root@vmware1 ~]# service vsftpd restart
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定]

这样就可以用系统原有用户进行登陆了
[root@vmware1 ~]# netstat -anpt | grep vsftpd
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 2191/vsftpd
12.在本地ftp服务器登陆测试。
[root@vmware1 ~]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): lhc
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (127,1,149,179).
150 Here comes the directory listing.
226 Directory send OK.
ftp> mkdir hello
257 "/hello" created
ftp> dir
227 Entering Passive Mode (127,141,105).
150 Here comes the directory listing.
drwxr-xr-x 2 500 500 4096 Jan 16 15:27 hello
226 Directory send OK.
到此为止,VSFTP搭建完成,实验结束。

今天关于CentOS6.5下搭建ftp服务器三种认证模式:匿名用户、本地用户、虚拟用户的分享就到这里,希望大家有所收获,若想了解更多关于centos 6.5下 vsftp 虚拟用户配置、Centos 6.5下安装vsftp本地用户、CentOS 6.5下快速搭建ftp服务器、CentOS 6.5下搭建vsftp服务器等相关知识,可以在本站进行查询。

本文标签: