LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2662|回复: 12

vsftpd-2.0.1 简单安装及设置[系统用户及nologin用户访问的解决办法]

[复制链接]
发表于 2005-1-8 12:55:11 | 显示全部楼层 |阅读模式
vsftpd-2.0.1 简单安装及设置

vsftpd  2.0.1 增强了安全机制,主要表现用户可以选择自己的用户验证方式。在默认安装的情况下,系统只提供匿名用户访问,即使在配置的时候允许本地用户登入,也成了不可完成的任务。如果才能使本地用户和nologin虚拟用户登录???这是本文所要解决的最基本的问题,其实也是最简单的问题。在 LinuxSir IRC上,有个弟兄问我,说本地用户不能登录 ftp 。为了解答IRC弟兄的疑问,同时也是帮助初学Linux的弟兄,还是简要的写一写,或许还有点用。

一、下载:

您可以下载最新版本的vsftpd 2.0.1,请到 :

ftp://vsftpd.beasts.org/users/cevans/

二、解压:要用到root有户,如果您用普通用户,请切换一下

[beinan@linuxsir soft]$ su
Password:在这里输入您root的密码
[root@linuxsir soft]#
[beinan@linuxsir soft]# tar zxvf vsftpd-2.0.1.tar.gz
[beinan@linuxsir soft]#cd vsftpd-2.0.1
[root@linuxsir vsftpd-2.0.1]#

三、编译和安装

1.说明:首先我们根据说明文档,作者提到如果要编译vsftpd ,首先要编辑一下  builddefs.h 文件。我们来看看他默认的选项都有什么 ?

  1. #ifndef VSF_BUILDDEFS_H
  2. #define VSF_BUILDDEFS_H
  3. #undef VSF_BUILD_TCPWRAPPERS
  4. #define VSF_BUILD_PAM
  5. #undef VSF_BUILD_SSL
  6. #endif /* VSF_BUILDDEFS_H */

复制代码


我们通过上面的可以看到,ftp验证是通过pam方式来验证的,这是一种虚拟用户登录ftp的验证方式。如果您采用了默认的方式安编译,会出现系统账号登录不到ftp的情况,但匿名ftp是能登录的。。

其实vsftpd把pam验证虚拟用户登录,也是一个安全的手段,通过pam方式,本地用户是没有办法登录到ftp上。事实上增强了系统的安全。

但如果我们只是想通过实际存在的系统帐号 nologin 方式来登录ftp ,采用他的默认的配置文件是不行的。我们要重新定义vsftpd 的配置文件  builddefs.h 。

改他的配置文件 builddefs.h中的一行

  1. #define VSF_BUILD_PAM
  2. 改为
  3. #undef VSF_BUILD_PAM
复制代码


2.编译安装:
[root@linuxsir vsftpd-2.0.1]# make ;make install

这样就安装好了。。。
我们查看一下vsftpd的依赖库,通过这些下面的输出,我们能看得出 vsftpd采用的验证方式。

  1. [root@linuxsir vsftpd-2.0.1]# ldd vsftpd
  2.         libcrypt.so.1 => /lib/libcrypt.so.1 (0x0f450000)
  3.         libdl.so.2 => /lib/libdl.so.2 (0x0ffb0000)
  4.         libnsl.so.1 => /lib/libnsl.so.1 (0x0f390000)
  5.         libresolv.so.2 => /lib/libresolv.so.2 (0x0fc10000)
  6.         libutil.so.1 => /lib/libutil.so.1 (0x0ef50000)
  7.         libcap.so.1 => /lib/libcap.so.1 (0x0fd40000)
  8.         libc.so.6 => /lib/tls/libc.so.6 (0x0fd60000)
  9.         /lib/ld.so.1 => /lib/ld.so.1 (0x0ffd0000)
复制代码


如果您采有了 pam验证方式,vsftpd所依赖的库文件是这样的。如果您发现vsftpd所依赖的库有libpam的行,这说明您所编译的还是通过pam验证登录。

  1. [root@linuxsir vsftpd-2.0.1]# ldd vsftpd
  2.         libpam.so.0 => /lib/libpam.so.0 (0x0ea70000)
  3.         libdl.so.2 => /lib/libdl.so.2 (0x0ffb0000)
  4.         libnsl.so.1 => /lib/libnsl.so.1 (0x0f390000)
  5.         libresolv.so.2 => /lib/libresolv.so.2 (0x0fc10000)
  6.         libutil.so.1 => /lib/libutil.so.1 (0x0ef50000)
  7.         libcap.so.1 => /lib/libcap.so.1 (0x0fd40000)
  8.         libc.so.6 => /lib/tls/libc.so.6 (0x0fd60000)
  9.         /lib/ld.so.1 => /lib/ld.so.1 (0x0ffd0000)
复制代码

然后我们要复制一些文件过去。。。

[root@linuxsir vsftpd-2.0.1]# cp vsftpd.conf   /etc/vsftpd.confBAK
[root@linuxsir vsftpd-2.0.1]# cp  vsftpd   /usr/sbin
[root@linuxsir vsftpd-2.0.1]# cp  vsftpd /usr/local/sbin/vsftpd

3.配制/etc/vsftpd.conf

1]我们应该养成备份的习惯。
[root@linuxsir vsftpd-2.0.1]# cp /etc/vsftpd.conf /etc/vsftpd.conf

2]下面是最简单的系统用户、虚拟用户[系统用户nologin]、匿名用户登录功能的配置文件。如果您想实现更多的功能,最好看一下他的文档。我们所想实现的,大多还是能实现的。比较简单。。



  1. # Example config file /etc/vsftpd.conf
  2. #
  3. # The default compiled in settings are fairly paranoid. This sample file
  4. # loosens things up a bit, to make the ftp daemon more usable.
  5. # Please see vsftpd.conf.5 for all compiled in defaults.
  6. #
  7. # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
  8. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
  9. # capabilities.
  10. #
  11. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  12. anonymous_enable=YES
  13. #
  14. # Uncomment this to allow local users to log in.
  15. local_enable=YES
  16. #
  17. # Uncomment this to enable any form of FTP write command.
  18. write_enable=YES
  19. #
  20. # Default umask for local users is 077. You may wish to change this to 022,
  21. # if your users expect that (022 is used by most other ftpd's)
  22. local_umask=022
  23. anon_umask=022
  24. #
  25. # Uncomment this to allow the anonymous FTP user to upload files. This only
  26. # has an effect if the above global write enable is activated. Also, you will
  27. # obviously need to create a directory writable by the FTP user.
  28. anon_upload_enable=YES
  29. #
  30. # Uncomment this if you want the anonymous FTP user to be able to create
  31. # new directories.
  32. anon_mkdir_write_enable=YES
  33. #
  34. # Activate directory messages - messages given to remote users when they
  35. # go into a certain directory.
  36. dirmessage_enable=YES
  37. #
  38. # Activate logging of uploads/downloads.
  39. xferlog_enable=YES
  40. #
  41. # Make sure PORT transfer connections originate from port 20 (ftp-data).
  42. connect_from_port_20=YES
  43. #
  44. # If you want, you can arrange for uploaded anonymous files to be owned by
  45. # a different user. Note! Using "root" for uploaded files is not
  46. # recommended!
  47. #chown_uploads=YES
  48. #chown_username=whoever
  49. #
  50. # You may override where the log file goes if you like. The default is shown
  51. # below.
  52. #xferlog_file=/var/log/vsftpd.log
  53. #
  54. # If you want, you can have your log file in standard ftpd xferlog format
  55. #xferlog_std_format=YES
  56. #
  57. # You may change the default value for timing out an idle session.
  58. #idle_session_timeout=600
  59. #
  60. # You may change the default value for timing out a data connection.
  61. #data_connection_timeout=120
  62. #
  63. # It is recommended that you define on your system a unique user which the
  64. # ftp server can use as a totally isolated and unprivileged user.
  65. #nopriv_user=ftpsecure
  66. #
  67. # Enable this and the server will recognise asynchronous ABOR requests. Not
  68. # recommended for security (the code is non-trivial). Not enabling it,
  69. # however, may confuse older FTP clients.
  70. #async_abor_enable=YES
  71. #
  72. # By default the server will pretend to allow ASCII mode but in fact ignore
  73. # the request. Turn on the below options to have the server actually do ASCII
  74. # mangling on files when in ASCII mode.
  75. # Beware that turning on ascii_download_enable enables malicious remote parties
  76. # to consume your I/O resources, by issuing the command "SIZE /big/file" in
  77. # ASCII mode.
  78. # These ASCII options are split into upload and download because you may wish
  79. # to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
  80. # without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
  81. # on the client anyway..
  82. #ascii_upload_enable=YES
  83. #ascii_download_enable=YES
  84. #
  85. # You may fully customise the login banner string:
  86. #ftpd_banner=Welcome to blah FTP service.
  87. #
  88. # You may specify a file of disallowed anonymous e-mail addresses. Apparently
  89. # useful for combatting certain DoS attacks.
  90. #deny_email_enable=YES
  91. # (default follows)
  92. #banned_email_file=/etc/vsftpd.banned_emails
  93. #
  94. # You may specify an explicit list of local users to chroot() to their home
  95. # directory. If chroot_local_user is YES, then this list becomes a list of
  96. # users to NOT chroot().
  97. #chroot_list_enable=YES
  98. # (default follows)
  99. #chroot_list_file=/etc/vsftpd.chroot_list
  100. #
  101. # You may activate the "-R" option to the builtin ls. This is disabled by
  102. # default to avoid remote users being able to cause excessive I/O on large
  103. # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
  104. # the presence of the "-R" option, so there is a strong case for enabling it.
  105. #ls_recurse_enable=YES
  106. check_shell=NO

复制代码


说明一下:

这个配置文件是通过xinetd的方式启动vsftpd的,也就是说配置好vsftpd.conf 。要重新启动一下xinetd

[root@linuxsir beinan]#/etc/init.d/xinetd  restart

当然要确保在 /etc/xinetd.d目录中存在vsftpd 这个文件,如果没有,要复制一个过去。

[root@linuxsir vsftpd-2.0.1]# cp xinetd.d/vsftpd    /etc/xinetd.d

如果您xinetd模式启动不感兴趣,想通过standalone 来启动,还得进行如下操作。注意vsftpd服务器,在两种模式启动中,只能选一种方式。

在配置文件最后加一行。

listen=YES

还要删除 /etc/xinetd.d/目录中的vsftpd文件,如果通过 standalone  模式启动vsftpd服务器,还得运行命令。

[root@linuxsir vsftpd-2.0.1]#  vsftpd&

4.添加有户测试:

  1. [root@linuxsir beinan]# useradd -d /opt/bnnb -g ftp -s /sbin/nologin bnnb
  2. [root@linuxsir beinan]# passwd bnnb 设置密码
  3. Changing password for user bnnb.
  4. New UNIX password: 输入密码
  5. Retype new UNIX password:   再输入一次
  6. passwd: all authentication tokens updated successfully.
复制代码

上面我建了一个帐号,用户名是bnnb ,不允许bnnb通过shell登录到系统,只能用于ftp登录。如果您发现bnnb这个帐号没有家目录。还需要执行下面的命令。
[root@linuxsir beinan]# mkdir /opt/bnnb
[root@linuxsir beinan]# chown -R bnnb:ftp /opt/bnnb

所有的都做好了,我们来验证是不是vsftpd可以用了。。

  1. [beinan@linuxsir vsftpd-2.0.1]$ lftp bnnb@localhost
  2. 口令:
  3. lftp bnnb@localhost:~> ls
  4. lftp bnnb@localhost:~> mkdir testdir
  5. mkdir 成功, 建立 `testdir'
  6. lftp bnnb@localhost:~> ls
  7. drwxr-xr-x    2 501      50           4096 Jan 08 04:51 testdir
  8. lftp bnnb@localhost:~>

复制代码


如果我们想让匿名用户有上传的权限,只是把上面的配置文件打开匿名写入还不够 ,还要设置匿名用户家目录的权限,也就是要用写权限

首先看一下/etc/passwd 中是否有ftp用户,他的用户目录一般是/var/ftp 或者 /home/ftp ,如果这两个中的任何一下就可以了。 当然您可以改动这些目录,来适合自己的需要。

比如 是 /var/ftp

因为 vsftpd 是为了安全需要,不能把/var/ftp目录不能把所有的权限打开。。所以这时我们要建一个目录,或者利用他本身自带的目录 pub也可。。如果没有pub目录,我们可以自己建一个。。

  1. [root@S31 var]# ls -lh  | grep ftp
  2. drwxr-xr-x   3 root    root    4.0K  8月 11 03:24 ftp
  3. [root@S31 var]# cd ftp/
  4. [root@S31 ftp]# ls -lh
  5. drwxr-xr-x  2 root root 4.0K  8月 11 03:24 pub
  6. [root@S31 ftp]# ls -lh
  7. drwxr-xr-x  2 root root 4.0K  8月 11 03:24 pub
  8. [root@S31 ftp]# chmod  -R 777 pub/
  9. [root@S31 ftp]# ls -lh
  10. drwxrwxrwx  2 root root 4.0K  8月 11 03:24 pub

复制代码



  1. 匿名ftp测试

  2. [beinan@S31 beinan]$ lftp 192.168.1.31
  3. lftp 192.168.1.31:~> ls
  4. drwxrwxrwx    3 0        0            4096 Jan 12 05:36 pub
  5. lftp 192.168.1.31:/> cd pub/
  6. lftp 192.168.1.31:/pub> ls
  7. drwxrwxrwx    2 14       50           4096 Jan 12 05:32 sun
  8. -rw-r--r--    1 14       50          28075 Jan 12 05:36 zh.po
  9. lftp 192.168.1.31:/pub> put beinan.gif
  10. 4915 bytes transferred
  11. lftp 192.168.1.31:/pub> ls
  12. -rw-r--r--    1 14       50           4915 Jan 12 05:38 beinan.gif
  13. drwxrwxrwx    2 14       50           4096 Jan 12 05:32 sun
  14. -rw-r--r--    1 14       50          28075 Jan 12 05:36 zh.po
  15. lftp 192.168.1.31:/pub>
复制代码

成功!

祝兄弟们好运,如果您认为这个简单的功能还不能满足您的需要,请参见置顶的帖子,我以前有写一个详细的。
发表于 2005-1-8 13:37:39 | 显示全部楼层
我是新来的,潜水了好几天了,这是第一篇帖子,谢谢南北兄的这种无私的精神,感动ING,向你致敬!!!
发表于 2005-1-8 19:18:17 | 显示全部楼层
谢谢北南老大~~~~~~~~
发表于 2005-1-9 11:02:57 | 显示全部楼层
北南的新作品
好东东
发表于 2005-1-10 21:25:17 | 显示全部楼层
请问这个问题如何解决?

root@LinuxFans vsftpd-2.0.1 # make install
if [ -x /usr/local/sbin ]; then \
        install -m 755 vsftpd /usr/local/sbin/vsftpd; \
else \
        install -m 755 vsftpd /usr/sbin/vsftpd; fi
if [ -x /usr/local/man ]; then \
        install -m 644 vsftpd.8 /usr/local/man/man8/vsftpd.8; \
        install -m 644 vsftpd.conf.5 /usr/local/man/man5/vsftpd.conf.5; \
elif [ -x /usr/share/man ]; then \
        install -m 644 vsftpd.8 /usr/share/man/man8/vsftpd.8; \
        install -m 644 vsftpd.conf.5 /usr/share/man/man5/vsftpd.conf.5; \
else \
        install -m 644 vsftpd.8 /usr/man/man8/vsftpd.8; \
        install -m 644 vsftpd.conf.5 /usr/man/man5/vsftpd.conf.5; fi
install: 无法创建一般文件‘/usr/local/man/man8/vsftpd.8’: 没有那个文件或目录
install: 无法创建一般文件‘/usr/local/man/man5/vsftpd.conf.5’: 没有那个文件或目录
make: *** [install] 错误 1


解决:自己照着Makefile手动复制.
发表于 2005-2-2 06:18:19 | 显示全部楼层
我这里出现的问题:为了方便,我就直接加了bnnb这个用户名.
[awang@MagicLinux~]ftp localhost
Connected to MagicLinux.
220 (vsFTP 2.0.2)
530 Please login with USER and PASS
530 Please login with USER and PASS
KERBEROS_V4 rejicter as an authentication type
Name (localhost:awang):bnnb
331 Please specify the password.
Password:
500 OOPS: cap_set_proc
Login failed.
Remote system type is login.
ftp>ls
215 UNIX Type: L8
Passive mode address scan failure. Shouldn't happen!
ftp>
郁闷啊,天都快亮了。。。。。。一晚上了。。。。。
回复 支持 反对

使用道具 举报

发表于 2005-2-2 09:22:02 | 显示全部楼层
echo /bin/nologin >> /etc/shells
就能让没有shell的用户登陆了,范不着那么麻烦
回复 支持 反对

使用道具 举报

发表于 2005-2-4 23:48:30 | 显示全部楼层
以前没有看准,谢谢啦.
回复 支持 反对

使用道具 举报

发表于 2005-5-12 14:16:42 | 显示全部楼层

vsftp 系统普通用户,不能连接~

不知道问什么?谢谢指点~

错误提示:
[R] Retry attempt Aborted
[R] Connecting to 192.168.0.76 -> IP=192.168.0.76 PORT=21
[R] Connected to 192.168.0.76
[R] 220 (vsFTPd 1.1.3)
[R] USER upload
[R] 331 Please specify the password.
[R] PASS (hidden)
[R] 530 Login incorrect.
[R] Connection failed
[R] Delaying for 120 seconds before reconnect attempt #1




  # Standalone mode
  listen=YES
  max_clients=200
  max_per_ip=4
  # Access rights
  anonymous_enable=no
  local_enable=YES
  write_enable=NO
  anon_upload_enable=NO
  anon_mkdir_write_enable=NO
  anon_other_write_enable=NO
  # Security
  anon_world_readable_only=YES
  connect_from_port_20=YES
  hide_ids=YES
  pasv_min_port=50000
  pasv_max_port=60000
  # Features
  xferlog_enable=YES
  ls_recurse_enable=NO
  ascii_download_enable=NO
  async_abor_enable=YES
  # Performance
  one_process_model=no
  idle_session_timeout=120
  data_connection_timeout=300
  accept_timeout=60
  connect_timeout=60
  anon_max_rate=50000
  chroot_list_enable=YES
  # (default follows)
  chroot_list_file=/etc/chroot_list
回复 支持 反对

使用道具 举报

发表于 2005-5-16 12:08:21 | 显示全部楼层
up~~~~~~~~~~~~~~~~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表