|
|
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 文件。我们来看看他默认的选项都有什么 ?
- #ifndef VSF_BUILDDEFS_H
- #define VSF_BUILDDEFS_H
- #undef VSF_BUILD_TCPWRAPPERS
- #define VSF_BUILD_PAM
- #undef VSF_BUILD_SSL
- #endif /* VSF_BUILDDEFS_H */
复制代码
我们通过上面的可以看到,ftp验证是通过pam方式来验证的,这是一种虚拟用户登录ftp的验证方式。如果您采用了默认的方式安编译,会出现系统账号登录不到ftp的情况,但匿名ftp是能登录的。。
其实vsftpd把pam验证虚拟用户登录,也是一个安全的手段,通过pam方式,本地用户是没有办法登录到ftp上。事实上增强了系统的安全。
但如果我们只是想通过实际存在的系统帐号 nologin 方式来登录ftp ,采用他的默认的配置文件是不行的。我们要重新定义vsftpd 的配置文件 builddefs.h 。
改他的配置文件 builddefs.h中的一行
- #define VSF_BUILD_PAM
- 改为
- #undef VSF_BUILD_PAM
复制代码
2.编译安装:
[root@linuxsir vsftpd-2.0.1]# make ;make install
这样就安装好了。。。
我们查看一下vsftpd的依赖库,通过这些下面的输出,我们能看得出 vsftpd采用的验证方式。
- [root@linuxsir vsftpd-2.0.1]# ldd vsftpd
- libcrypt.so.1 => /lib/libcrypt.so.1 (0x0f450000)
- libdl.so.2 => /lib/libdl.so.2 (0x0ffb0000)
- libnsl.so.1 => /lib/libnsl.so.1 (0x0f390000)
- libresolv.so.2 => /lib/libresolv.so.2 (0x0fc10000)
- libutil.so.1 => /lib/libutil.so.1 (0x0ef50000)
- libcap.so.1 => /lib/libcap.so.1 (0x0fd40000)
- libc.so.6 => /lib/tls/libc.so.6 (0x0fd60000)
- /lib/ld.so.1 => /lib/ld.so.1 (0x0ffd0000)
复制代码
如果您采有了 pam验证方式,vsftpd所依赖的库文件是这样的。如果您发现vsftpd所依赖的库有libpam的行,这说明您所编译的还是通过pam验证登录。
- [root@linuxsir vsftpd-2.0.1]# ldd vsftpd
- libpam.so.0 => /lib/libpam.so.0 (0x0ea70000)
- libdl.so.2 => /lib/libdl.so.2 (0x0ffb0000)
- libnsl.so.1 => /lib/libnsl.so.1 (0x0f390000)
- libresolv.so.2 => /lib/libresolv.so.2 (0x0fc10000)
- libutil.so.1 => /lib/libutil.so.1 (0x0ef50000)
- libcap.so.1 => /lib/libcap.so.1 (0x0fd40000)
- libc.so.6 => /lib/tls/libc.so.6 (0x0fd60000)
- /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]、匿名用户登录功能的配置文件。如果您想实现更多的功能,最好看一下他的文档。我们所想实现的,大多还是能实现的。比较简单。。
- # 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=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
- anon_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
- 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.添加有户测试:
- [root@linuxsir beinan]# useradd -d /opt/bnnb -g ftp -s /sbin/nologin bnnb
- [root@linuxsir beinan]# passwd bnnb 设置密码
- Changing password for user bnnb.
- New UNIX password: 输入密码
- Retype new UNIX password: 再输入一次
- 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可以用了。。
- [beinan@linuxsir vsftpd-2.0.1]$ lftp bnnb@localhost
- 口令:
- lftp bnnb@localhost:~> ls
- lftp bnnb@localhost:~> mkdir testdir
- mkdir 成功, 建立 `testdir'
- lftp bnnb@localhost:~> ls
- drwxr-xr-x 2 501 50 4096 Jan 08 04:51 testdir
- lftp bnnb@localhost:~>
复制代码
如果我们想让匿名用户有上传的权限,只是把上面的配置文件打开匿名写入还不够 ,还要设置匿名用户家目录的权限,也就是要用写权限
首先看一下/etc/passwd 中是否有ftp用户,他的用户目录一般是/var/ftp 或者 /home/ftp ,如果这两个中的任何一下就可以了。 当然您可以改动这些目录,来适合自己的需要。
比如 是 /var/ftp
因为 vsftpd 是为了安全需要,不能把/var/ftp目录不能把所有的权限打开。。所以这时我们要建一个目录,或者利用他本身自带的目录 pub也可。。如果没有pub目录,我们可以自己建一个。。
- [root@S31 var]# ls -lh | grep ftp
- drwxr-xr-x 3 root root 4.0K 8月 11 03:24 ftp
- [root@S31 var]# cd ftp/
- [root@S31 ftp]# ls -lh
- drwxr-xr-x 2 root root 4.0K 8月 11 03:24 pub
- [root@S31 ftp]# ls -lh
- drwxr-xr-x 2 root root 4.0K 8月 11 03:24 pub
- [root@S31 ftp]# chmod -R 777 pub/
- [root@S31 ftp]# ls -lh
- drwxrwxrwx 2 root root 4.0K 8月 11 03:24 pub
复制代码
- 匿名ftp测试
- [beinan@S31 beinan]$ lftp 192.168.1.31
- lftp 192.168.1.31:~> ls
- drwxrwxrwx 3 0 0 4096 Jan 12 05:36 pub
- lftp 192.168.1.31:/> cd pub/
- lftp 192.168.1.31:/pub> ls
- drwxrwxrwx 2 14 50 4096 Jan 12 05:32 sun
- -rw-r--r-- 1 14 50 28075 Jan 12 05:36 zh.po
- lftp 192.168.1.31:/pub> put beinan.gif
- 4915 bytes transferred
- lftp 192.168.1.31:/pub> ls
- -rw-r--r-- 1 14 50 4915 Jan 12 05:38 beinan.gif
- drwxrwxrwx 2 14 50 4096 Jan 12 05:32 sun
- -rw-r--r-- 1 14 50 28075 Jan 12 05:36 zh.po
- lftp 192.168.1.31:/pub>
复制代码
成功!
祝兄弟们好运,如果您认为这个简单的功能还不能满足您的需要,请参见置顶的帖子,我以前有写一个详细的。 |
|