CentOS 6.4 i386的学习笔记-003 vsftp 的安装与简单配置

来源:互联网 发布:程序员试用期个人总结 编辑:程序博客网 时间:2024/05/01 02:35

笔记已经上传到百度文库:
CentOS 6.4 i386的学习笔记-003 vsftp 的安装与简单配置.pdf


本篇笔记内容介绍

CentOS 6.4下,通过yum的方式安装vsftpd,并进行简单配置。


第一步:安装软件

[vm20vm20]$su – root

Password: //输入密码后,回车。提示:输入的密码不显示。

[vm20vm20]#yum install vsftpd pam* db4* -y

回车后,一直等到出现下面的Complete!提示,就表示安装成功了。

Complete

[vm20vm20]#


第二步:设置开机启动vsftpd

[vm20vm20]#chkconfig --level 35 vsftpd on


第三步:新建ftp虚拟帐户

[vm20vm20]#useradd ftpuser -s /sbin/nologin

提示:新建的ftpuser虚拟帐户不是用来登录ftp的。


第四步:配置vsftpd.conf

更改配置前,做好原始配置文件的备份,然后再改。


1、新建原始配置文件的备份目录。

[vm20vm20]#mkdir /folder/bak

这样就在/folder文件夹下新建了一个保存全部备份文件的/bak文件夹。


2、备份vsftpd.conf

[vm20vm20]#cp /etc/vsftpd/vsftpd.conf /folder/bak/vsftpd.conf.bak.20130605-etc-vsftpd

简单解释一下cp命令(cp = copy)。

cp命令的使用格式:cp需要备份的文件备份后的文件

因此,这条命令就是把/etc/vsftpd/vsftpd.conf这个文件复制到

/folder/bak这个文件夹下面,同时重新命名这个复制后的文件为

vsftpd.conf.bak.20130605-etc-vsftpd

这个长长的文件名的意思是:

vsftpd.conf .bak .20130605 -etc-vsftpd

原始文件名表示备份备份时间原始文件所在目录(便于恢复)



3、配置vsftpd.conf

修改配置文件之前,先了解一下vi编辑器的简单使用:

i键,进入插入模式,可以修改文件内容,用键盘的上下左右键移动光标;

Esc键,回到命令模式,不可以修改文件内容,支持一定的命令。

在命令模式下,输入:wq就可以保存修改过的文件并退出。

还可以连续两次按快捷键ShiftZ,同样也是保存并退出vi编辑器

Vi编辑器的简单使用就介绍到这里。


提示:在vsftpd.conf这个配置文件中,#表示注释。在vsftpd.conf文件中,被# 注释的行,有的是说明,有的是不需要执行的配置。

现在,开始修改vsftpd.conf这个配置文件。

把配置文件中的相关部分,修改成下面的设置。


[vm20vm20]#vi /etc/vsftpd/vsftpd.conf

#Example config file /etc/vsftpd/vsftpd.conf

#

#The default compiled in settings are fairly paranoid. This samplefile

#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 vsftpdoptions.

#Please read the vsftpd.conf.5 manual page to get a full idea ofvsftpd's

#capabilities.

#

#Allow anonymous FTP? (Beware - allowed by default if you comment thisout).

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 to022,

#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. Thisonly

#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 tocreate

#new directories.

#anon_mkdir_write_enable=YES

#

#Activate directory messages - messages given to remote users whenthey

#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 ownedby

#a different user. Note! Using "root" for uploaded files isnot

#recommended!

#chown_uploads=YES

#chown_username=whoever

#

#The name of log file when xferlog_enable=YES andxferlog_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 whichthe

#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 factignore

#the request. Turn on the below options to have the server actually doASCII

#mangling on files when in ASCII mode.

#Beware that on some FTP servers, ASCII support allows a denial ofservice

#attack (DoS) via the command "SIZE /big/file" in ASCIImode. vsftpd

#predicted this attack and has always been safe, reporting the size ofthe

#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=Welcometo 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 theirhome

#directory. If chroot_local_user is YES, then this list becomes a listof

#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 isdisabled by

#default to avoid remote users being able to cause excessive I/O onlarge

#sites. However, some broken FTP clients such as "ncftp" and"mirror" assume

#the presence of the "-R" option, so there is a strong casefor enabling it.

#ls_recurse_enable=YES

#

#When "listen" directive is enabled, vsftpd runs instandalone 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 IPv4and IPv6

#sockets, you must run two copies of vsftpd with two configurationfiles.

#Make sure, that one of the listen options is commented !!

#listen_ipv6=YES


pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES


#手动添加下面的内容

guest_enable=YES
guest_username=ftpuser
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/vconf

#配置文件到这里就修改完成了

下面的内容,就是简单解释一下相关的设置:


anonymous_enable=YES//不允许匿名用户访问


local_enable=YES//允许本地用户访问


write_enable=YES //允许用户执行写入操作


local_umask=022//文件上传以后的权限掩码


dirmessage_enable=YES//开启活动目录信息


xferlog_enable=YES//开启记录日志功能


connect_from_port_20=YES //设定连接端口为20


xferlog_std_format=YES //设置日志的格式


idle_session_timeout=600//会话超时的时间设置


async_abor_enable=YES//支持异步传输功能


ascii_upload_enable=YES//支持ASCII模式的下载功能


ascii_download_enable=YES //支持ASCII模式的上传功能


ftpd_banner=Welcometo blah FTP service. //FTP登录的欢迎语


chroot_local_user=YES//禁止本地用户登出自己的FTP主目录


chroot_list_enable=YES //不允许FTP用户离开自己的主目录


chroot_list_file=/etc/vsftpd/chroot_list

//如果开启了chroot_list_enable=YES,那么一定要开启这个设

置,这条设置是锁定登录用户只能家目录的位置,如果不开启这

个设置,那么,用户登录时就有错误提示。
提示:/etc/vsftp/chroot_list这个文件本身是不存在的,配置完

成后,需要在/etc/vsftp这个目录下建立chroot_list这个文件,

然后将需要登录的帐户,以一行一个用户名的格式记录到这个文件

里,保存就OK了。


pam_service_name=vsftpd//设定pam服务下vsftpd的验证配置文件名


userlist_enable=YES//拒绝登录用户名单


tcp_wrappers=YES//限制主机对vsftp服务器的访问


guest_enable=YES //设定启用虚拟用户功能


guest_username=ftpuser //
指定虚拟用户的宿主用户


virtual_use_local_privs=YES  //
设定虚拟用户的权限符合他们的宿主用户


user_config_dir=/etc/vsftpd/vconf  //
设定虚拟用户配置文件存放路径


第五步:创建日志文件

[vm20vm20]#touch /var/log/vsftpd.log//创建日志文件

[vm20vm20]#chown ftpuser.ftpuser /var/log/vsftpd.log

//使新创建的vsftpd.log文件,属于ftpuser这个宿主。



第六步:创建虚拟用户文件

[vm20vm20]#mkdir /etc/vsftpd/vconf//新建存放虚拟用户的目录



第七步:新建虚拟用户

[vm20vm20]#touch /etc/vsftpd/vconf/vir_user//新建文件

[vm20vm20]#vi /etc/vsftpd/vconf/vir_user

virftpuser //这一行是用户名

123456789 //这一行是对应的密码

提示:在vir_user这个文件里,第一行(奇数行)是用户名,第二行(偶数行)是用户名对应的密码。如果有其他用户,以此类推。


第八步:生成数据库

[vm20vm20]#db_load -T -t hash -f /etc/vsftpd/vconf/vir_user /etc/vsftpd/vconf/vir_user.db

在相同的文件夹下,生成同名的数据库vir_user.db文件。


第九步:设置数据库和用户文件的访问权限

[vm20vm20]#chmod 600/etc/vsftpd/vconf/vir_user.db

[vm20vm20]#chmod 600/etc/vsftpd/vconf/vir_user


第十步:修改/etc/pam.d/vsftpd的内容

[vm20vm20]#echo "authrequired pam_userdb.so db=/etc/vsftpd/vconf/vir_user" >/etc/pam.d/vsftpd

[vm20vm20]#echo"account required pam_userdb.so db=/etc/vsftpd/vconf/vir_user">> /etc/pam.d/vsftpd


第十一步:创建登录用户的配置文件

提示:创建的登录用户配置文件的名字要和前面第步里新建的“虚拟用户”的名字相同。

[vm20vm20]#touch /etc/vsftpd/vconf/virftpuser

[vm20vm20]#vi /etc/vsftpd/vconf/virftpuser

文件内容如下:

local_root=/home/virftpuser //虚拟用户的个人目录路径
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=600
data_connection_timeout=120
max_clients=10
max_per_ip=5
local_max_rate=1048576 //
本地用户的最大传输速度,

单位是Byts/s,这里设定为10M



第十二步:新建chroot_list文件

[vm20vm20]#touch /etc/vsftpd/chroot_list

[vm20vm20]#vi /etc/vsftpd/chroot_list

里面就一行,内容是:

virftpuser

提示:这个文件前面已经说过了,需要注意的就是一行只写一个授权登录的用户名。本例中就一个用户,就写一行,如果有10个用户,就需要写10行了。


第十三步:建立虚拟用户目录
如果不建立虚拟用户的个人目录,那么所有的虚拟用户登录后所在的目录都是同一个目录下
[vm20
vm20]#mkdir /home/virftpuser
[vm20vm20]#chown ftpuser.ftpuser /home/virftpuser
[vm20vm20]#chmod 600 /home/virftpuser



vsftpd.conf的配置到这里就完成了,在以后的使用中,如果想添加新的用户,只要在上面的第七步的文件里添加新的用户、第八步重新生成数据库文件、按照第十一步的方法和内容创建新用户的配置文件,就OK了。



第十四步:修改selinux关于vsftp的设置

1、查看selinux的设置

[vm20vm20]#cat /etc/selinux/config

#This file controls the state of SELinux on the system.

#SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=enforcing

#SELINUXTYPE= can take one of these two values:

# targeted - Targeted processes are protected,

# mls - Multi Level Security protection.

SELINUXTYPE=targeted



2、查看selinux中有关FTP的设置状态

[vm20vm20]#getsebool -a | grep ftp

allow_ftpd_anon_write--> off

allow_ftpd_full_access--> off

allow_ftpd_use_cifs--> off

allow_ftpd_use_nfs--> off

ftp_home_dir--> off

ftpd_connect_db--> off

ftpd_use_passive_mode--> off

httpd_enable_ftp_server--> off

tftp_anon_write--> off



3、修改selinux中关于FTP的设置

[vm20vm20]#setsebool -P ftp_home_dir 1

[vm20vm20]#setsebool -P allow_ftpd_full_access 1



4、再次查看selinux中有关FTP的设置状态

[vm20vm20]#getsebool -a | grep ftp

allow_ftpd_anon_write--> off

allow_ftpd_full_access--> on

allow_ftpd_use_cifs--> off

allow_ftpd_use_nfs--> off

ftp_home_dir--> on

ftpd_connect_db--> off

ftpd_use_passive_mode--> off

httpd_enable_ftp_server--> off

tftp_anon_write--> off



5、重启vsftpd服务

[vm20vm20]#service vsftpd restart



第十五步:关闭iptables服务

[vm20vm20]#service iptables stop


经过设置,现在终于可以访问了,呵呵~~


文中所介绍的vsftp的安装与简单配置,目的就是让vsftp先运行起来,有关vsftp的更多的配置,请百度或Google


抛砖引玉,如有错漏,敬请指正。






笔记已经上传到百度文库:
CentOS 6.4 i386的学习笔记-003 vsftp 的安装与简单配置.pdf




(完)20136514:12