vsftpd 的安装配置使用----FTP服务器搭建

我用的是源代码安装
vsftpd需要使用nobody来作为运行者,一般已经存在
#useradd nobody

安装时需要/usr/share/empty/作为临时目录,一般已经存在
#mkdir /usr/share/empty/

解压
#tar zxvf vsftpd-2.0.4.tar.gz
#cd vsftpd-2.0.4

编译
#make
#make install

如果make install没有安装文件,你可能需要手动执行下面的命令
#cp vsftpd /usr/local/sbin/vsftpd
#cp vsftpd.conf.5 /usr/local/man/man5
#cp vsftpd.8 /usr/local/man/man8
#cp vsftpd.conf /etc
#cp vsftpd.xinetd /etc/xinetd.d/vsftpd
重启xinetd
#/etc/rc.d/init.d/xinetd restart
安装完毕

配置
设置为独立启动模式
安装完成后,vsftp是默认随xinetd一起启动,最好改成独立启动(我就是吃了这个亏,但是觉得没事,懒得改,导致后来配置总不成功,浪费了好多时间)。打开/etc/xinetd.d/vsftpd文件,把disable=no改成yes,
#vi /etc/xinetd.d/vsftpd

再在/etc/vsftpd.conf文件的最后添加listen=yes,
#vi /etc/vsftpd.conf

这样就改成了STANDALONE独立模式。

现在我们手动启动一下vsftp
因为xinetd已经启动了vsftpd,而vsftpd设置成了stardalone模式,
所以,先停止xinetd服务, 
#service xinetd stop
或者
#/etc/init.d/xinetd stop

然后后台执行启动ftp服务
#/usr/local/sbin/vsftpd &

(记得把xinetd服务启动/etc/init.d/xinetd start)


配置本地用户登录

现在的vsftp已经可以使用了,但是只允许匿名用户登录(默认配置),这和我们的目标还有点距离,我们要让本地用户ftpdemo可以FTP登录。

关闭匿名用户登录
出于安全性的考虑,我们不允许匿名用户使用ftp,修改/etc/vsftpd.conf
#vi /etc/vsftpd.conf

找到anonymous_enable项,取消注释,并把值改成no。重启vsftp看看,这下匿名用户不能登录了。

让本地用户登录,先修改配置
local_enable=YES
write_enable=YES
local_umask=022

使本地用户能登录FTP。按照上面的源码安装配置我们的FTP还不能让本地用户登
录,因为缺少一个认证PAM文件,在源码目录下有一个RedHat/vsftpd.pam认证文
件,把它复制到/etc/pam.d/ftp。
#cp RedHat/vsftpd.pam /etc/pam.d/ftp


测试一下,假设有一个本地用户test,登录FTP:
#ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 1.2.1)
Name (127.0.0.1:root): test
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
看来情况很好:)


新建系统用户ftpdemo
#useradd -s /sbin/nologin -d /var/vhosts/www.gzfyw.com ftpdemo
-s /sbin/nologin 表示用户只能FTP登录,不能登录系统
-d /var/vhosts/www.gzfyw.com 表示用户主目录,即登录后的默认目录,根据实际情况修改成你需要的路径
如果上面的这条命令拷贝后执行出错的话,建议你手动敲入,我就碰到过这种情况

安全起见,马上给ftpdemo设置密码
#passwd ftpdemo

修改ftp目录的所属者
#chown -R ftpdemo:ftpdemo /var/vhosts/www.gzfyw.com

如果你都执行正确的话,那现在ftpdemo可以FTP登录了。开心啊。。。

限制用户权限
再用一会,你又会发现有另外一个问题,ftpdemo可以返回到ftp主目录的上级目录,这太不安全了,要把ftp用户禁止在自己的目录里,不让他们乱跑,接下来做这个事情,
如果需要将用户限制在自己的home文件夹中
在/etc/vsftpd.conf中,找到修改或者添加如下两行
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
然后修改/创建/etc/vsftpd.chroot_list文件,在里面加入你想要限制的用户的用户名,比如你的用户名ftpdemo
kill掉vsftp进程,再重启vsftp,看到了吗,这下ftpdemo看不到ftp主目录外的其他目录,不能到处乱跑了,呵呵。

最后一次,把vsftp添加到开机启动项
打开/etc/rc.local,在文件尾增加一行
/usr/local/sbin/vsftpd &
另外:我使用chkconfig vsftpd on总添加不成功

补充:
登录后,发现FTP客户端的时间和服务器的时间不一样
原因是vsftpd默认使用GMT作为其时间,所以可能会导致与系统时间不一致(系统时间不是GMT)
解决方案:在vsftpd.conf文件中增加一行
use_localtime=yes

相关命令:
重启xinetd服务
/etc/init.d/xinetd restart
查看启动的ftp进程id
ps -ef | grep ftp
杀掉ftp进程
kill 123
在后台启动vsftp
/usr/local/sbin/vsftpd &
查看自启动项
chkconfig --list
新增用户
useradd -s /sbin/nologin -d /var/vhosts/www.gzfyw.com ftpdemo
passwd ftpdemo
chown -R ftpdemo:ftpdemo /var/vhosts/www.gzfyw.com
vi /etc/vsftpd.chroot_list

附:/etc/vsftpd.conf
# Example config file /etc/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=NO
#
# 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
#
# 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/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#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_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

listen=yes
use_localtime=yes

 注意 用户认证的问题,不通过认证,是没有办法登陆的。


使本地用户能登录FTP。按照上面的源码安装配置我们的FTP还不能让本地用户登
录,因为缺少一个认证PAM文件,在源码目录下有一个RedHat/vsftpd.pam认证文
件,把它复制到/etc/pam.d/ftp。
#cp RedHat/vsftpd.pam /etc/pam.d/ftp

 

 

 

 

 

 

(5) 配置PAM文件
vi /etc/pam.d/vsftp
插入如下最后两行
auth       required    pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required    pam_stack.so service=system-auth
auth       required    pam_shells.so
account    required    pam_stack.so service=system-auth
session    required    pam_stack.so service=system-auth

auth       required     /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

account    required     /lib/security/pam_userdb.so
db=/etc/vsftpd/vsftpd_login

(6)建立虚拟用户访问的目录
useradd -d /home/ftpsite virtual
chmod 700 /home/ftsite/

(7)生成测试文件
su - virtual -c "echo hello >;/home/ftpsite/test_file"
(配置vsftpd.conf
内容如下
#example /etc/vsftpd/vsftpd.conf
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
one_process_model=NO
chroot_local_user=YEs
ftpd_banner=This FTP server is virtual user only.
guest_enable=YES
guest_username=virtual
pam_service_name=vsftpd

(9)登录测试

# ftp 127.0.0.1
Connected to 127.0.0.1.
220 This FTP server is virtual user only.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): tom
331 Please specify the password.
Password:
500 OOPS: priv_sock_get_result
Login failed.
421 Service not available, remote server has closed connection
ftp>;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值