红联Linux门户
Linux帮助
当前位置: 红联Linux门户 > Debian

debian下配置vsftp 非虚拟用户

发布时间:2008-04-07 17:28:15来源:红联作者:Axflue
能用到FTP也是在用apache的时候总是在windows下修改好,而又要传到web服务器里.架起来vsftp有会更方便一点!

也是由于只是自己用所以没有做些高难度的动作.

安装vsftp
apt-get install update
apt-get install vsftpd

查看ftp是否启动
netstat -a|grep ftp*
ftp -localhost

控制vsftp是否随系统启动
可以用rcconf这个套件
apt-get install update
然后输入rcconf就可以通过GUI界面管理!
这确实比update-rc.d轻松得多.

首先来看看排除不允许登陆FTP server的用户
这很重要,有些例如root之类的危险帐户一定要排除出去!
在/etc/ftpusers 记录着不允许访问FTP服务器的用户名单.在安装Debian的时候已经默认排除了root 等保证vsftp安全.
下面是我的ftpusers,如果你感觉用虚拟帐户管理麻烦(因为利用它最好的途径是通过MYSQL).可以把所有/etc/passwd下的用户都写到里面,然后在一个一个手动添加!:)
这样只有后来手工添加的帐户可以登陆FTP了
cat /etc/ftpusers
#/etc/ftpusers : list of users disallowed FTP access. See ftpusers(5)
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
nobody

vsftp的日志很重要
vsftp 日志存放在/var/log
可以经常查看一下有没有违法的举动,比如没有获得FTP登陆权限的帐户登陆过FTP server.

管理vsftp系统服务
启动服务 /etc/init.d/./vsftpd start
重启服务 /etc/init.d/./vsftpd restart (我的机器用这个不好用,通常我都是先stop然后start)
停止服务 /etc/init.d/./vsftpd stop

配置以匿名方式登陆只允许下载
这部分只是写出来占点空间,其实我感觉我是用不到的!!!
别看下面黑压压一片,其实也用不了几分钟就修改完了.
在Debian安装好后自然会给你一个vsftpd.conf的模板.
只许手动改几个字母而已.
修改/etc/vsftpd/vsftpd.conf
listen=yes (独立的VSFTPD服务器)*
max_clients=200 (同时允许200个客户连入)
max_per_ip=4 (每个IP最多允许4个进程)
anonymous_enable=yes (允许匿名登陆)
local_enable=NO (禁止本地系统用户)
write_enable=NO (不开放本地用户写权限)
anon_upload_enable=NO (匿名用户上传权限)
anon_mkdir_write_enable=NO (关闭可上传目录并关闭在此目录上传权限)
anon_other_write_enable=NO (关闭匿名帐户的删除权限)
anon_world_readable_ (禁止匿名拥护下载具有全局读取权限的文件)
hide_ids=YES (目录中用户和组信息列取都显示为ftp)
ls_recurse_enable=NO (禁止ls -R 递归查询)
dirmessage_enable=yes (切换目录时,显示目录下.message的内容)
local_umask=022 (FTP上本地的文件权限,默认是077)
connect_form_port_20=yes (启用FTP数据端口的数据连接)*
xferlog_enable=yes (激活上传和下传的日志)
xferlog_std_format=yes (使用标准的日志格式)
ftpd_banner=XXXXX (欢迎信息)
pam_service_name=vsftpd (验证方式)
刚刚安装vsftp匿名用户路径/home/ftp

配置本地用户使用FTP server
这部分我感觉还蛮有用,如果懒得通过使用虚拟帐户来进行FTP上传下载修改之类的管理,这个是个简单干净的办法.
修改/etc/vsftpd/vsftpd.conf
Local_enable=YES (本地帐户能够登陆)
Write_enable=NO (本地帐户无权修改和删除文件,我只想简单的利用ftp来管理web server 所以这改为YES,要不让是不能上传文件的)
设置所有本地用户都执行chroot
Chroot_local_user=YES (本地所有帐户都只能在自己的家目录)
设置指定用户执行chroot
Chroot_list_enable=YES (文件中的名单可以调用)
Chroot_list_file=/任意指定路径/vsftpd.chroot_list
注意:vsftpd.chroot_list是没有创建的需要自己添加,要想控制帐户就直接在文件中加帐户即可.
限制本地用户访问FTP
Userlist_enable=yes (用userlistlai限制用户访问)
Userlist_deny=no (名单中的人不允许访问)
Userlist_file=/指定文件存放的路径/(文件放置路径)
注:开启userlist_enable=yes匿名帐户不能登陆
修改pam_service_name=/etc/pam.d/vsftpd (好象只有debian的vsftp很邪门,在这修改成绝对路径本地用户才可以使用,这很重要.)

安全选项
Data_connection_timeout=120 (秒) (数据空闲两分钟断)
Accept_timeout=60 (秒) (客户端空闲1分钟后断)

配置本地组访问FTP
首先创建用户组test和FTP的目录
groupadd ftpadmin (组名是随便区的,只是便于管理以后可以随时cat /etc/group |grep ftpadmin)
mkdir /tmp/test (我直接给用户分配管理/var/www文件,用来管理apache的web目录)
然后创建用户
useradd -G ftpadmin -d /tmp/test -M user1
注:G:用户所在的组 d:指定创建用户的自己目录 M:不建立默认的自家目录,就是在/home下没有自己的目录

我只是为了给自己的web server做文件传输服务,所以只是马马虎虎的做了一个帐户.
useradd -G ftp -d /var/www -M webadmin

接着改变文件夹属于的组和用户
chown webadmin.ftpadmin /var/www 把/var/www改变属主为webadmin
chmod 711 /var/www
我这设置的读取权限是711.也就是文件夹所有者完全权限,同组也就是上面的FTP组和所有人都是可执行权限.
起初大意了一下,习惯性的把www改成750结果在IE测试apache server的时候,告诉我无权读取.之后我查看了www的权限才发现,所有人的权限是0,怪不得打不开网页.呵!

看看谁在登陆了FTP,并停止他的进程
ps -xf |grep ftp
kill 进程号
文章评论

共有 4 条评论

  1. johnson.pan 于 2009-06-19 15:08:52发表:

    帮我看看,如何让本地用户有上传的权限

  2. johnson.pan 于 2009-06-19 15:08:02发表:

    这是我的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.
    #
    #
    # Run standalone? vsftpd can run either from an inetd or as a standalone
    # daemon started from an initscript.
    listen=YES
    #anon_root=/home/ftp
    #tcp_wrappers=YES
    #
    # Run standalone with IPv6?
    # Like the listen parameter, except vsftpd will listen on an IPv6 socket
    # instead of an IPv4 one. This parameter and the listen parameter are mutually
    # exclusive.
    #listen_ipv6=YES
    #
    # 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
    #
    # 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 restrict local users to their home directories. See the FAQ for
    # the possible risks in this before using chroot_local_user or
    # chroot_list_enable below.
    #chroot_local_user=YES
    #
    # 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
    #
    #
    # Debian customization
    #
    # Some of vsftpd's settings don't fit the Debian filesystem layout by
    # default. These settings are more Debian-friendly.
    #
    # This option should be the name of a directory which is empty. Also, the
    # directory should not be writable by the ftp user. This directory is used
    # as a secure chroot() jail at times vsftpd does not require filesystem
    # access.
    secure_chroot_dir=/var/run/vsftpd
    #
    # This string is the name of the PAM service vsftpd will use.
    pam_service_name=vsftpd
    #
    # This option specifies the location of the RSA certificate to use for SSL
    # encrypted connections.
    rsa_cert_file=/etc/ssl/certs/vsftpd.pem

  3. johnson.pan 于 2009-06-19 15:02:16发表:

    我配置好了vsftpd,但是不能上传文件

  4. johnson.pan 于 2009-06-19 13:27:59发表:

    是一篇好的技术文档,值得收藏