注册 登录
星韵地理网 返回首页

追梦人生 http://www.xingyun.org.cn/?2 [收藏] [复制] [分享] [RSS] 有梦追梦,我愿用一生期待。

日志

用Linux架设FTP服务器(4)

已有 433 次阅读2003-12-29 21:08 |个人分类:信息技术

创建“ftp”文件(touch /etc/pam.d/ftp)并加入:

   #%PAM-1.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

   配置“/etc/logrotate.d/ftpd”文件
   配置“/etc/logrotate.d/ftpd”文件使得日志文件每周自动循环更新。

   创建“ftpd”文件(touch /etc/logrorate.d/ftpd)并加入:

   /var/log/xferlog {
   # ftpd doesn‘t handle SIGHUP properly
   nocompress
   }

   配置ftp使其使用inetd超级服务器(用于实现tcp-wrappers)
   tcp-wrappers用来启动和中止ftpd服务。当inetd执行的时候,它会从默认为“/etc/inetd.conf”的配置文件读入配置信息。配置文件中每一行中的项用TAB或空格隔开。

   编辑inetd.conf文件(vi /etc/inetd.conf),加入并验证是否存在下面这一行: ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a

   注意:更新完“inetd.conf”文件之后要发给inetd一个SIGNUP信号,运行下面的命令:

   [root@deep /root]# killall -HUP inetd

   编辑“hosts.allow”文件(vi /etc/hosts.allow)加入这一行:

   in.ftpd: 192.168.1.4 win.openarch.com

   这表示IP地址为“192.168.1.4”并且主机名为“win.openarch.com”的计算机允许访问ftp服务器。

   FTP管理工具
   ftpwho
   ftpwho显示当前连接到ftp服务器上的所有用户。这个命令菜单输出类似“/bin/ps”的输出,其格式为:

   <pid> <time> <tty> <connection details>

   其中<pid>表示ftp daemon用来处理这次文件传输的进程号,<time>表示用户什么时候连接到ftp服务器上,<tty>总是用问号(?)表示因为是通过ftp而不是telnet连接,<connection details>告诉连接是来自哪里、用户是谁以及用户现在在干什么。

   下面是ftpwho输出的一个例子:

   [root@deep]# ftpwho

   Service class openarch:
   5443 ? S 0:00 ftpd: win.openarch.com: admin: IDLE
   - 1 users ( 20 maximum)
   可以看到现在有一个用户登录(最多可以有20个用户同时登录),这个用户的用户名是admin来自win.openarch.com。

   ftpcount
   ftpcount是ftpwho的简化版,只显示登录到ftp服务器的用户数以及最多允许多少个用户登录。下面是一个例子:

   [root@deep]# ftpcount

   Service class openarch - 1 users ( 20 maximum)

   保证ftp服务器的安全

   首先确保已经创建了“/etc/ftpusers”文件,这个文件用来设置不允许哪些用户登录ftp服务器,其中至少要包括:root、bin、daemon、adm、lp、sync、shutdown、halt、mail、news、uucp、operator、games、nobody以及所有Linux发行商在系统中提供的默认帐号。

   如果想禁止匿名ftp服务,把ftp用户从password文件中移去,再用下面的命令确定在系统中没有安装anonftp-version.i386.rpm软件包:

   [root@deep]# rpm -q anonftp.

   upload命令

   在默认情况下,WU-FTPD服务器给所有的guest用户上载的权限。当用户登录的时候,被改变根目录(chroot)到“/home/ftp”就不能访问这个目录之外的地方。但是“/home/ftp”目录中的一些地方还是需要保护,不能让用户随便访问。在我们配置的ftp服务器中为“/home/ftp”目录下的“bin”、“etc”、“dev”和“lib”目录。我们不允许用户上载文件到这些目录。所以我们要为这些目录设置访问权限,可以在“/etc/ftpaccess”文件中设置上载权限。在我们的例子中是这样设置的:

   upload /home/ftp/* / no
   upload /home/ftp/* /etc no
   upload /home/ftp/* /dev no
   upload /home/ftp/* /bin no (require only if you are not using the “--enable-ls” option)
   upload /home/ftp/* /lib no (require only if you are not using the “--enable-ls” option)

   noretrieve命令

   最好禁止某些用户从“/home/ftp”目录下的某些子目录中下载文件,可以用“noretrieve”命令在“/etc/ftpaccess”文件中设置。

   noretrieve /home/ftp/etc
   noretrieve /home/ftp/dev
   noretrieve /home/ftp/bin (require only if you are not using the “--enable-ls” option)
   noretrieve /home/ftp/lib (require only if you are not using the “--enable-ls” option)

   “.notar”文件
   无论是否允许即时的目录打包(on-the-fly tar),都必须保证用户不能打包(tar)禁止上载的目录。在“/home/ftp”目录的每个子目录中都创建“.notar”文件。

   [root@deep]# touch /home/ftp/.notar
   [root@deep]# chmod 0 /home/ftp/.notar
   [root@deep]# touch /home/ftp/etc/.notar
   [root@deep]# chmod 0 /home/ftp/etc/.notar
   [root@deep]# touch /home/ftp/dev/.notar
   [root@deep]# chmod 0 /home/ftp/dev/.notar
   [root@deep]# touch /home/ftp/bin/.notar (require only if you are not using the “--enable-ls” option)
   [root@deep]# chmod 0 /home/ftp/bin/.notar (require only if you are not using the “--enable-ls” option)
   [root@deep]# touch /home/ftp/lib/.notar (require only if you are not using the “--enable-ls” option)
   [root@deep]# chmod 0 /home/ftp/lib/.notar (require only if you are not using the “--enable-ls” option)
   这些长度为0的“.notar”文件会使一些浏览器和ftp代理(proxy)出现混乱,要解决这个问题必须把它们标识为禁止下载。在“/etc/ftpaccess”文件中加入这一行:

   noretrieve .notar

   安装到系统中的文件

   > /etc/ftphosts
   > /etc/ftpusers
   > /etc/ftpaccess
   > /etc/pam.d/ftp
   > /etc/ftpconversions
   > /etc/ftpgroups
   > /etc/logrotate.d/ftpd
   > /usr/bin/ftpcount
   > /usr/bin/ftpwho
   > /usr/man/man1/ftpcount.1
   > /usr/man/man1/ftpwho.1
   > /usr/man/man5/ftpaccess.5
   > /usr/man/man5/ftphosts.5
   > /usr/man/man5/ftpconversions.5
   > /usr/man/man5/xferlog.5
   > /usr/man/man8/ftpd.8
   > /usr/man/man8/ftpshut.8
   > /usr/man/man8/ftprestart.8
   > /usr/sbin/in.ftpd
   > /usr/sbin/ftpshut
   > /usr/sbin/ckconfig
   > /usr/sbin/ftprestart
   > /usr/sbin/xferstats
   > /usr/sbin/wu.ftpd
   > /usr/sbin/in.wuftpd
   > /var/log/xferlog

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|Archiver|小黑屋|星韵百科|星韵地理网 ( 苏ICP备16002021号 )

GMT+8, 2024-5-17 09:49 , Processed in 0.073543 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部