免费注册 查看新帖 |

Chinaunix

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

[FTP] 请教vsftp服务问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-25 23:55 |只看该作者 |倒序浏览
我用readhat 9.0下装的VSFTP可是总是不能登陆,我的配置方安是参考下面的:

目前,VSFTPD的最新版本是1.2.0版。官方下载地址为ftp://vsftpd.beasts.org/users/cevans/vsftpd-1.2.0.tar.gz。在安装前,需要先做以下准备工作:

  VSFTPD默认配置中需要“nobody”用户。在系统中添加此用户,如果用户已经存在,useradd命令有相应提示。
  [root@hpe45 root]# useradd nobody
  useradd: user nobody exists

  VSFTPD默认配置中需要“/usr/share/empty”目录。在系统中此目录,如果目录已经存在,mkdir命令有相应提示。
  [root@hpe45 root]# mkdir /usr/share/empty/
  mkdir: cannot create directory '/usr/share/empty': File exists

  VSFTPD提供匿名FTP服务时,需要“ftp”用户和一个有效的匿名目录。
  [root@hpe45 root]# mkdir /var/ftp/
  [root@hpe45 root]# useradd -d /var/ftp ftp
  接下来的操作对于ftp用户是否已经存在都是有用的。
  [root@hpe45 root]# chown root.root /var/ftp
  [root@hpe45 root]# chmod og-w /var/ftp

  以上准备工作完成后,我们就可以开始编译源代码了。假定我们下载的vsftpd-1.2.0.tar.gz在/root目录,执行以下命令:
  [root@hpe45 root]# tar zxvf vsftpd-1.2.0.tar.gz
  [root@hpe45 root]# cd vsftpd-1.2.0
  [root@hpe45 vsftpd-1.2.0]# make
  [root@hpe45 vsftpd-1.2.0]# make install

  上面的“make install”命令将编译好的二进制文件、手册等复制到相应目录。在RHL9上,可能需要手动执行以下复制:
  [root@hpe45 vsftpd-1.2.0]# cp vsftpd /usr/local/sbin/vsftpd
  [root@hpe45 vsftpd-1.2.0]# cp vsftpd.conf.5 /usr/local/share/man/man5
  [root@hpe45 vsftpd-1.2.0]# cp vsftpd.8 /usr/local/share/man/man8

  接下来,我们复制一个简单的配置文件作为基础供后面修改。
  [root@hpe45 vsftpd-1.2.0]# cp vsftpd.conf /etc
  [root@hpe45 vsftpd-1.2.0]# cp RedHat/vsftpd.pam /etc/pam.d/ftp
  复制PAM验证文件,以允许本地用户登录VSFTPD。
  [root@hpe45 vsftpd-1.2.0]# cp RedHat/vsftpd.pam /etc/pam.d/ftp

  二、创建guest用户

  VSFTPD采用PAM方式验证虚拟用户。由于虚拟用户的用户名/口令被单独保存,因此在验证时,VSFTPD需要用一个系统用户的身份来读取数据库文件或数据库服务器以完成验证,这就是VSFTPD的guest用户。这正如同匿名用户也需要有一个系统用户ftp一样。当然,我们也可以把guest用户看成是虚拟用户在系统中的代表。下面在系统中添加vsftpdguest用户,作为VSFTPD的guest。
  [root@hpe45 vsftpd-1.2.0]# useradd vsftpdguest
  当虚拟用户登录后,所在的位置为vsftpdguest的自家目录/home/vsftpdguest。如果要让虚拟用户登录到/var/ftp等其他目录,修改vsftpdguest的自家目录即可。

  三、设置VSFTPD配置文件

  在/etc/vsftpd.conf文件中,加入以下选项:
  guest_enable=YES
  guest_username=vsftpdguest

  然后执行以下命令,让VSFTPD在后台运行:
  [root@hpe45 vsftpd-1.2.0]# /usr/local/sbin/vsftpd &

  四、将虚拟用户保存在MySQL数据库服务器中

  我们建立数据库vsftpdvu,表users,字段name和passwd用于保存虚拟用户的用户名和口令,同时增加两个虚拟用户xiaotong和xiaowang。

  [root@hpe45 vsftpd-1.2.0]# mysql -p
  mysql>;create database vsftpdfly;
  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表。执行以下命令:
  [root@hpe45 vsftpd-1.2.0]# mysql -u root mysql -p
  mysql>;grant select on vsftpdvu.users to vsftpdguest@localhost identified by 'i52serial0';
  mysql>;quit

  如果要验证刚才的操作是否成功可以执行下面命令:
  [root@hpe45 vsftpd]#mysql -u vsftpdguest -pi52serial0 vsftpdvu
  mysql>;select * from users;
  如果成功,将会列出xiaotong、xiaowang和加密后的密码

  五、设置MySQL的PAM验证

  这里我们要用到一个利用mysql进行pam验证的开源项目(http://sourceforge.net/projects/pam-mysql/)。首先从网站下载它的程序包pam_myql-0.5.tar.gz,复制到/root目录中。在编译安装之前,要确保mysql-devel的RPM包已经安装在你的机器上,如果没有请从RHL安装光盘中安装该包。然后,执行以下命令:
  [root@hpe45 root]#tar xvzf pam_mysql-0.5.tar.gz
  [root@hpe45 root]#cd pam_mysql
  [root@hpe45 pam_mysql]#make
  [root@hpe45 pam_mysql]#make install
  make install这一步可能会出现错误,那只好手动将该目录下生成的pam_mysql.o复制到/lib/security目录下。
  接下来,我们要设置vsftpd的PAM验证文件。打开/etc/pam.d/ftp文件,加入以下内容:
  auth required pam_mysql.o user=vsftpdguest passwd=i52serial0 host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=2
  account required pam_mysql.o user=vsftpdguest passwd=i52serial0 host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=2
  上面涉及到的参数,只要对应前面数据库的设置就可以明白它们的含义。这里需要说明的是crypt参数。crypt表示口令字段中口令的加密方式:crypt=0,口令以明文方式(不加密)保存在数据库中;crypt=1,口令使用UNIX系统的DES加密方式加密后保存在数据库中;crypt=2,口令经过MySQL的password()函数加密后保存。

  六、进一步的虚拟用户设置

  经过以上的步骤,虚拟用户就可以正常使用了。这里介绍进一步的虚拟用户设置。首先,介绍虚拟用户的权限设置。

  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操作:
  [root@hpe45 root]# chown vsftpdguest.vsftpdguest /home/vsftpdguest
  [root@hpe45 root]# chmod 700 /home/vsftpdguest
  允许虚拟用户上传文件:
  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/vsftpdguest下,无法访问其他目录。

  七、虚拟用户的个人目录

  大家可以发现,无论是哪个虚拟用户,登录后所在的目录都是/home/vsftpdguest,即都是guest_username用户的自家目录。下面,介绍如何为每个虚拟用户建立自家目录。首先,在主配置文件中加入以下选项:
  user_config_dir=/etc/vsftpd/vsftpd_user_conf
  然后,生成/etc/vsftpd/vsftpd_user_conf目录,并在该目录下建立与特定虚拟用户同名的文件:
  [root@hpe45 root]# mkdir /etc/vsftpd/vsftpd_user_conf
  [root@hpe45 root]# cd /etc/vsftpd/vsftpd_user_conf
  [root@hpe45 vsftpd_user_conf]# touch xiaowang
  以上的操作为虚拟用户xiaowang建立了个人配置文件/etc/vsftpd/vsftpd_user_conf/xiaowang。接下来,在xiaowang的个人配置文件中将xiaowang的自家目录修改为/home/xiaowang,配置选项为:
  local_root=/home/xiaowang
  然后,新建xiaowang目录,并将权限设为vsftpdguest:
  [root@hpe45 vsftpd_user_conf]# mkdir /home/xiaowang
  [root@hpe45 vsftpd_user_conf]# chown vsftpdguest.vsftpdguest ./xiaowang
  [root@hpe45 vsftpd_user_conf]# chmod 600 /home/xiaowang
  经过以上设置,xiaowang登录VSFTPD后,用“pwd”指令就可以发现被自己被定位到自己的“/home/xiaowang”目录。
  从文件系统层次来看,由于“/home/xiaowang”目录的权限是属于vsftpdguest的,所以其他的虚拟用户同样也可以访问xiaowang的自家目录。解决这个问题也很简单,我们只需要让VSFTPD负责将虚拟用户限制在其自家目录,就可以避免虚拟用户的互相访问。具体做法参照前面第六步中所述,这里不再赘述。经过以上设置后,虚拟用户就可以拥有属于自己的目录了。

论坛徽章:
0
2 [报告]
发表于 2005-09-25 23:56 |只看该作者

请教vsftp服务问题?

# 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=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 turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file" in
# ASCII mode.
# These ASCII options are split into upload and download because you may wish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#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
guest_enable=YES
guest_username=vsftpdguest
#pam_service_name=ftp
#userlist_enable=YES
#enable for standalone mode
listen=YES
#tcp_wrappers=YES
"/etc/vsftpd/vsftpd.conf" 111L, 4186C written
[root@ns ~]# vi /etc/vsftpd/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=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 turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file" in
# ASCII mode.
# These ASCII options are split into upload and download because you may wish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#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
guest_enable=YES
guest_username=vsftpdguest
pam_service_name=ftp

#enable for standalone mode
listen=YES

tcp_wrappers=YES

论坛徽章:
0
3 [报告]
发表于 2005-09-25 23:59 |只看该作者

请教vsftp服务问题?

cat /etc/pam.d/ftp
#%PAM-1.0
auth required pam_mysql.so user=vsftpdguest passwd=12345 host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=0

account required pam_mysql.so user=vsftpdguest passwd=12345 host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=0
auth       required     /lib/security/pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
auth       required     /lib/security/pam_pwdb.so shadow nullok
auth       required     /lib/security/pam_shells.so
account    required     /lib/security/pam_pwdb.so
session    required     /lib/security/pam_pwdb.so

错误信息是
ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 2.0.3)
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): vsftpdguest
530 This FTP server is anonymous only.
Login failed.
总是这样,要不就是说跟IPV4不能邦定.
搞了几天了还是没有搞定,
大家帮忙看看.谢谢

论坛徽章:
0
4 [报告]
发表于 2005-09-26 00:23 |只看该作者

请教vsftp服务问题?

你配置的是使用虚拟用户的ftp,用户保存在mysql数据库中
所以不能用这个系统中做为guest用户的vsftpdguest 来登录

IPV4不能邦定是因为21端口已经被占用了,要么是你的系统有其他服务占了,要么是你之前启动了vsftpd,没有停就又启了一次
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP