免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1137 | 回复: 0
打印 上一主题 下一主题

安装vsftp- - [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-23 12:00 |只看该作者 |倒序浏览
                       
1.编译
  cd vsftpd-1.2.1
  make
2.安装前的准备工作
  VSFTPD默认配置中需要“nobody”用户,在系统中添加此用户。如果用户已经 存在,useradd命令有相应提示:
     
  useradd nobody
  useradd: user nobody exists
  VSFTPD默认配置中需要“/usr/share/empty”目录。在系统中添加此目录,如果目录已经存在,mkdir命令有相应提示:
  
  mkdir /usr/share/empty/
  mkdir: cannot create directory '/usr/share/empty': File exists
  VSFTPD提供匿名FTP服务时,需要“ftp”用户和一个有效的匿名用户目录:
  
  mkdir /home/ftp/
  useradd -d /home/ftp ftp
  接下来的操作对于ftp用户是否已经存在都是有用的:
  chown root.root /home/ftp
  chmod og-w /home/ftp
3.安装
  将vsftp安装到/opt目录中:
  mkdir /opt/vsftp/{bin,man}
  mkdir /opt/vsftp/man/{man5,man8}
  cp vsftpd /opt/vsftp/bin/
  cp vsftpd.conf.5 /opt/vsftp/man/man5
  cp vsftpd.8 /opt/vsftp/man/man8
4.复制配置文件
  接下来,复制一个简单的配置文件作为基础供后面修改。
  
  cp vsftpd.conf /etc
  
  如果系统需要PAM验证,则在/etc/pam.d/ 目录下必须有一个ftp文件,才允许本地用户(non-anonymous) 登录VSFTPD。在标准 安装中,可直接拷贝该文件:
  
  cp RedHat/vsftpd.pam /etc/pam.d/ftp
5.运行方式
  vsftp可以通过两种模式运行:standalone 或 inetd 。
  1)采用inetd的方式:
  在/etc/inetd.conf中的 #:OTHER: Other services 部分加入:
  ftp stream tcp nowait root /usr/sbin/tcpd /opt/vsftp/bin/vsftpd
  执行下面命令以告诉inetd重读配置文件:
  
  kill -SIGHUP `pidof inetd`
  2)采用standalone方式:
  修改 /etc/vsftpd.conf文件, 在文件末尾加上如下一行:
  listen=YES
  这句话告诉vsftpd不是使用inetd方式运行的。
6.具体配置
当允许匿名用户上传时的上传目录权限设置:
首先将该目录(如uploads)归属于ftp用户,具体权限设置为:无可执行权限时不能进入该目录,无读权限时进入该目录后看不到目录中的内容,无写权 限时不能上传。
7.VSFTPD+MySQL的虚拟用户管理
  
  VSFTPD支持将用户名和口令保存在数据库文件或数据库服务器中。VSFTPD称这种形式的用户为虚 拟用户。相对于FTP的本地 (系统)用户来说,虚拟 用户只是FTP服务器的专有用户,虚拟用户只能访问FTP服务器所提供的资源,这大大增强系统本身的安全性。相对于匿名用 户而言,虚拟用户需要用户名和密 码才能获取FTP服务器中的文件,增加了对用户和下载的可管理性。对于需要提供下载服务,但又不希望所有人都可以匿名下 载;既需要对下载用户进行管理,又 考虑到主机安全和管理方便的FTP站点来说,虚拟用户是一种极好的解决方案。本文介绍如何将VSFTPD的虚拟用户名和密 码保存在MySQL数据库服务器中。
  
  1)创建guest用户
  VSFTPD采用PAM方式验证虚拟用户。由于虚拟用户的用户名/口令被单独保存,因此在验证时,VSFTPD需要用 一个系统用户的身份来读取数据库 文件或数据库服务器以完成验证,这就是VSFTPD的guest用户。这如同匿名用户也需要有一个系统用户ftp一样。当然,我们也可以把guest用 户看成是虚拟用户在系统中的代表。下面在系统中添加vsftpdguest用户,作为VSFTPD的guest:
  useradd -d /home/ftp vsftpdguest
  这里为管理方便,将虚拟用户的家目录设为/home/ftp,与匿名用户相同(可禁止匿名用户登录)。当 虚拟用户登录后,所在位置为就是vsftpdguest的家目录/home/ftp。如果要让虚拟用户登录到其他目录,修改vsftpdguest的自家 目录即可。
  2)设置VSFTPD配置文件
  在/etc/vsftpd.conf文件中,加入以下选项:
  guest_enable=YES
  guest_username=vsftpdguest
  3)将虚拟用户保存在MySQL数据库服务器中
  建立数据库vsftpdvu,表users,字段name和passwd用于保存虚拟用户的用户名和口令,同时增加两个虚拟用户xiaotong和 xiaowang。
  mysql -u root -p
  Enter password:
  mysql>create database vsftpdvu;
  mysql>use vsftpdvu;
  mysql>create table users(name char(16) binary,passwd char(16) binary);
  mysql>insert into users (name,passwd) values ('xiaotong',password('qqmywife'));
  mysql>insert into users (name,passwd) values ('xiaowang',password('ttmywife'));
  mysql>quit
  然后,授权vsftpdguest可以读vsftpdvu数据库的users表。执行以下命令:
  mysql>grant select on vsftpdvu.users to vsftpdguest@localhost identified by 'password';
  mysql>quit
  如果要验证刚才的操作是否成功可以执行下面命令:
  mysql -u vsftpdguest -p password vsftpdvu
  mysql>select * from users;
  如果成功,将会列出xiaotong、xiaowang和加密后的密码
  4)设置MySQL的PAM验证
  这里我们要用到一个利用mysql进行pam验证的开源项目(http://sourceforge.net/projects/pam- mysql/)。首先从网站下载它的程序包pam_myql-0.5.tar.gz。在编译安装之前,要确保mysql- devel包已经安装。然后,执行以下命令:
  tar xvzf pam_mysql-0.5.tar.gz
  cd pam_mysql
  make
  make install
  make install这一步可能会出现错误,那就手动将该目录下生成的pam_mysql.o复制到/lib/security目录下。
  接下来,设置vsftpd的PAM验证文件。打开/etc/pam.d/ftp文件,加入以下内容:
  auth required pam_mysql.o user=vsftpdguest passwd=password host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=2
  account required pam_mysql.o user=vsftpdguest passwd=password host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=2
  上面涉及到的参数,只要对应前面数据库的设置就可以明白它们的含义。这里需要说明的是crypt参数。crypt表示口令字段中口令的加密方式: crypt=0,口令以明文方式(不加密)保存在数据库中;crypt=1,口令使用UNIX系统的DES加密方式加密后保存在数据库中;crypt= 2,口令经过MySQL的password()函数加密后保存。
  5)进一步的虚拟用户设置
  经过以上的步骤,虚拟用户就可以正常使用了。这里介绍进一步的虚拟用户设置。
  首先,介绍虚拟用户的权限设置。
  VSFTPD-1.2.0新添了virtual_use_local_privs参数,当该参数激活(YES)时,虚拟用户使用与本地用户相同的权 限。当此参数关闭(NO)时,虚拟用户使用与匿名用户相同的权限,也就是VSFTPD-1.2.0之前版本对虚拟用户权限的处理方法。这两者种做法相 比,后者更加严格一些,特别是在有写访问的情形下。默认情况下此参数是关闭的(NO)。
  当virtual_use_local_privs=YES时,只需设置write_enable=YES,虚拟用户就可以就拥有写权限。而 virtual_use_local_privs=NO时,对虚拟用户权限的设置就更多一些更严格一些。
  控制虚拟用户浏览目录:如果让用户不能浏览目录,但仍可以对文件操作,那么需要执行以下二个步骤:一,配置文件中, anon_world_readable_only=YES;二,虚拟用户目录的权限改为只能由vsftpdguest操作:
  chown vsftpdguest.vsftpdguest /home/ftp
  chmod 700 /home/ftp
  允许虚拟用户上传文件:
  write_enable=YES
  anon_upload_enable=YES
  允许虚拟用户修改文件名和删除文件:
  anon_other_write_enable=YES
  由于以上选项的设置同样会对匿名用户生效,如果不想匿名用户趁机拥有同样的权限,最好是禁止匿名用户登录。
  其次,由于虚拟用户在系统中是vsftpdguest身份,所以可以访问到系统的其他目录。为了更加安全,我们可以将虚拟用户限制在自家目录下。有两 种做法:一,在配置文件中增加以下选项:
  chroot_local_user=NO
  chroot_list_enable=YES
  chroot_list_file= /etc/vsftpd.chroot_list
  然后,在/etc/vsftpd.chroot_list文件中加入虚拟用户名xiaotong和xiaowang。
  第二种做法,在配置文件中修改:
  chroot_local_user=YES
  经过修改后,虚拟用户登录后其根目录就限制在/home/ftp下,无法访问其他目录。
  6)虚拟用户的个人目录
  大家可以发现,无论是哪个虚拟用户,登录后所在的目录都是/home/ftp,即都是guest_username用户的自家目录。 下面,介绍如何为每个虚拟用户建立自家目录。首先,在主配置文件中加入以下选项:
  user_config_dir=/opt/vsftp/etc/vsftpd_user_conf
  然后,生成/opt/vsftp/etc/vsftpd_user_conf目录,并在该目录下建立与特定虚拟用户同名的文件:
  mkdir /opt/vsftp/etc/vsftpd_user_conf
  cd /opt/vsftp/etc/vsftpd_user_conf
  touch xiaowang
  以上的操作为虚拟用户xiaowang建立了个人配置文件/opt/vsftp/etc/vsftpd_user_conf/xiaowang。接下 来,在 xiaowang的个人配置文件中将xiaowang的自家目录修改为/home/xiaowang,配置选项为:
  local_root=/home/xiaowang
  然后,新建xiaowang目录,并将其所有者设为vsftpdguest:
  mkdir /home/xiaowang
  chown vsftpdguest.vsftpdguest /home/xiaowang
  chmod 600 /home/xiaowang
  经过以上设置,xiaowang登录VSFTPD后,用“pwd”指令就可以发现被自己被定位到自己的“/home/xiaowang”目录。
  从文件系统层次来看,由于“/home/xiaowang”目录的权限是属于vsftpdguest的,所以其他虚拟用户同样也可以访问 xiaowang的自家目录。解决这个问题也很简单,我们只需要让VSFTPD将虚拟用户限制在其自家目录,就可以避免虚拟用户的互相访问。具体做法 参照前面第五步中所述。经过以上设置后,虚拟用户就可以拥有属于自己的目录了。
附:英文安装文档
INSTALL
=======
This file details how to build and install / run vsftpd from the vsftpd distribution .tar.gz file.
Step 1) Build vsftpd.
Switch to the directory created when you unpacked the vsftpd .tar.gz file. e.g.:
cd vsftpd-1.1.2
edit "builddefs.h" to handle compile-time settings (tcp_wrappers build, etc).
Just type "make" (and mail me to fix it if it doesn't build ;-).
This should produce you a vsftpd binary. You can test for this, e.g.:
[chris@localhost vsftpd]$ ls -l vsftpd
-rwxrwxr-x 1 chris chris 61748 Sep 27 00:26 vsftpd
Step 2) Satisfy vsftpd pre-requisites
2a) vsftpd needs the user "nobody" in the default configuration. Add this user in case it does not already exist. e.g.:
[root@localhost root]# useradd nobody
useradd: user nobody exists
2b) vsftpd needs the (empty) directory /usr/share/empty in the default configuration. Add this directory in case it does not already exist. e.g.:
[root@localhost root]# mkdir /usr/share/empty/
mkdir: cannot create directory `/usr/share/empty': File exists
2c) For anonymous FTP, you will need the user "ftp" to exist, and have a valid home directory (which is NOT owned or writable by the user "ftp").
The following commands could be used to set up the user "ftp" if you do not have one:
[root@localhost root]# mkdir /var/ftp/
[root@localhost root]# useradd -d /var/ftp ftp
(the next two are useful to run even if the user "ftp" already exists).
[root@localhost root]# chown root.root /var/ftp
[root@localhost root]# chmod og-w /var/ftp
Step 3) Install vsftpd config file, executable, man page, etc.
Running "make install" will try to copy the binary, man pages, etc. to somewhere sensible.
Or you might want to copy these things by hand, e.g.:
cp vsftpd /usr/local/sbin/vsftpd
cp vsftpd.conf.5 /usr/local/man/man5
cp vsftpd.8 /usr/local/man/man8
"make install" doesn't copy the sample config file. It is recommended you do this:
cp vsftpd.conf /etc
Step 4) Smoke test (without an inetd).
vsftpd can run standalone or via an inetd (such as inetd or xinetd). You will typically get more control running vsftpd from an inetd. But first we will run it without, so we can check things are going well so far.
Edit /etc/vsftpd.conf, and add this line at the bottom:
listen=YES
This tells vsftpd it will NOT be running from inetd.
Right, now let's try and run it!
Log in as root.
Make sure you are not running other FTP servers (or vsftpd will not be able to use the FTP port, 21).
Run the binary from wherever you put it, e.g.:
[root@localhost root]# /usr/local/sbin/vsftpd &
[1] 2104
If all is well, you can now connect! e.g.:
[chris@localhost chris]$ ftp localhost
Connected to localhost (127.0.0.1).
220 (vsFTPd 1.1.1)
Name (localhost:chris): ftp
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (127,0,0,1,229,133)
150 Here comes the directory listing.
d--x--x--x 2 0 0 4096 Jan 14 2002 bin
d--x--x--x 2 0 0 4096 Apr 21 20:52 etc
drwxr-xr-x 2 0 0 4096 Apr 21 20:52 lib
drwxr-sr-x 2 0 50 4096 Jul 26 22:58 pub
226 Directory send OK.
ftp>
Step 5) Run from an inetd of some kind (optional - standalone mode is now recommended)
You may want to run the binary from an inetd of some kind, because this can give you extra features - e.g. xinetd has a lot of settings. (Note that vsftpd's inbuilt listener covers most of the more useful xinetd settings).
5a) If using standard "inetd", you will need to edit /etc/inetd.conf, and add a line such as:
ftp stream tcp nowait root /usr/sbin/tcpd /usr/local/sbin/vsftpd
(Make sure to remove or comment out any existing ftp service lines. If you don't have tcp_wrappers installed, or don't want to use them, take out the /usr/sbin/tcpd part).
inetd will need to be told to reload its config file:
kill -SIGHUP `pidof inetd`
5b) If using "xinetd", you can follow a provided example, by looking at the file EXAMPLE/INTERNET_SITE/README. Various other examples show how to leverage the more powerful xinetd features.
Step 6) Set up PAM for local logins (optional)
If you are running vsftpd on a PAM enabled machine, you will need to have a /etc/pam.d/ftp file present, otherwise non-anonymous logins will fail. [NOTE - if you have an older version of PAM, that file might be /etc/pam.conf]
For a standard setup, you can just copy a provided example file:
cp RedHat/vsftpd.pam /etc/pam.d/ftp
Step 7) Customize your configuration
As well as the above three pre-requisites, you are recommended to install a config file. The default location for the config file is /etc/vsftpd.conf.
There is a sample vsftpd.conf in the distribution tarball. You probably want to copy that to /etc/vsftpd.conf as a basis for modification, i.e.:
cp vsftpd.conf /etc
The default configuration allows neither local user logins nor anonymous uploads. You may wish to change these defaults.


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/22249/showart_159259.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP