当前位置:首页>网络学院>服务器>Ftp服务器教程>文章内容

用Linux架设FTP服务器(2)

[ 来源:www.it55.com | 作者: | 时间:2007-06-29 | 收藏 | 推荐 ] 【


  为FTP站点的用户建立没有shell的帐号
    首先,创建一个新的用户,这个用户被允许连接到ftp服务器上。因为要有“chroot”的环境,这个帐号不同于正常的用户帐号,不能受访问限制。“chroot”使用户产生这样的感觉好像自己已经在文件系统的最顶层了。
    第一步
    用下面的命令在“/etc/passwd”文件中创建用户。对于每个允许访问ftp服务器的新用户都要重复这个步骤。
    [root@deep]# mkdir /home/ftp
    [root@deep]# useradd -d /home/ftp/ftpadmin/ -s /dev/null ftpadmin > /dev/null 2>&1
    [root@deep]# passwd ftpadmin
    Changing password for user ftpadmin
    New UNIX password:
    Retype new UNIX password:
    passwd: all authentication tokens updated successfully

http://www.it55.com/

    第二步
    编辑“/etc/shells”文件并加入一个空shell,如:null。这个假的shell可以限制用户对ftp服务器的访问。
    [root@deep]# vi /etc/shells
  
    /bin/bash
    /bin/sh
    /bin/ash
    /bin/bsh
    /bin/tcsh
    /bin/csh
    /dev/null ? This is our added no existent shell
   第三步
    现在编辑“/etc/passwd”文件,手工加上“/./”把“/home/ftp”目录和“/ftpadmin”目录分开,用户“ftpadmin”会自动转到(chdir)“/ftpadming”目录下。在“passwd”文件中每添加一个ftp用户都要重复这个步骤。
    编辑“passwd”文件(vi /etc/passwd),把下面这一行改为:
    ftpadmin:x:502:502::/home/ftp/ftpadmin/:/dev/null
    改为:
    ftpadmin:x:502:502::/home/ftp/./ftpadmin/:/dev/null
    帐号为“ftpadmin”,这这个帐号的家目录有一些奇怪。第一部分“/home/ftp/”表示“chroot”时作为根目录的目录。被点号分开的“/ftpadmin”表示当登录ftp服务器的时候会自动转到这个目录。“/dev/null”这个空shell不允许“ftpadmin”像正常用户那样登录。经过这些改变,“ftpadmin”用户用的不是真正的shell而是伪shell,这样访问ftp服务器就受到限制。 创建一个“chroot”用户环境
45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn

  先要创建一个简单的根文件系统(root file system),包含有足够的文件,如果二进制程序、口令文件,等等。当用户登录的时候,Unix就可以改变根文件系统(chroot)。注意一下,如果编译的时候象上面那样加上“--enable-ls”参数,“/home/ftp/bin”和“/home/ftp/lib”两个目录就可以不要了,因为WU-FTP会用自己带的“ls”。不过我们还是介绍一下旧的方法,也就是把“/bin/ls”拷贝到“/home/ftp/bin”(chroot之后就是“/bin”)目录下,然后把相关的运行库拷贝到“/home/ftp/lib”目录下。
    第一步
    创建改变根文件系统(chrooted)环境所需要的所有的目录:
    [root@deep]# mkdir /home/ftp/dev
    [root@deep]# mkdir /home/ftp/etc
    [root@deep]# mkdir /home/ftp/bin (require only if you are not using the “--enable-ls” option)
    [root@deep]# mkdir /home/ftp/lib (require only if you are not using the “--enable-ls” option)
   第二步
    把新目录的权限设成0511:
    [root@deep]# chmod 0511 /home/ftp/dev
    [root@deep]# chmod 0511 /home/ftp/etc
    [root@deep]# chmod 0511 /home/ftp/bin (require only if you are not using the “--enable-ls” option)
http://www.it55.com/

    [root@deep]# chmod 0511 /home/ftp/lib (require only if you are not using the “--enable-ls” option)
    上面这些“chmod”命令把chrooted之后的“dev”、“etc”、“bin”和“lib”目录设置成超级用户“root”可读、可执行,用户组和所有用户可执行。
    第三步
    把“/bin/ls”文件拷贝到“/home/ftp/bin”目录下,并把“ls”的权限改为0111(不运行用户改变这个文件)。
    [root@deep]# cp /bin/ls /home/ftp/bin (require only if you are not using the “--enable-ls” option)
    [root@deep]# chmod 0111 /bin/ls /home/ftp/bin/ls (require only if you are not using the “--enable-ls” option)
    第四步
    找到“ls”程序所需的共享库:
    [root@deep]# ldd /bin/ls (require only if you are not using the “--enable-ls” option)
    libc.so.6 => /lib/libc.so.6 (0x00125000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00110000)
    把共享库拷贝到“/home/ftp/lib”目录下:
    [root@deep]# cp /lib/libc.so.6 /home/ftp/lib/ (require only if you are not using the “--enable-ls” option) 45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn
    [root@deep]# cp /lib/ld-linux.so.2 /home/ftp/lib/ (require only if you are not using the “--enable-ls” option)
  注意:如果想用Linux的“ls”程序而不是用WU-ftpd自带的“ls”(编译时加上“--enable-ls”参数),才需要第三和第四步。
  
    第五步
    创建“/home/ftp/dev/null”文件:
    [root@deep]# mknod /home/ftp/dev/null c 1 3
    [root@deep]# chmod 666 /home/ftp/dev/null
  
    第六步
    把“group”和“passwd”文件拷贝到“/home/ftp/etc”目录下,然后再改变这两个文件。
    [root@deep]# cp /etc/passwd /home/ftp/etc/
    [root@deep]# cp /etc/group /home/ftp/etc/
    编辑“passwd”文件(vi /home/ftp/etc/passwd)把除了“root”和允许使用ftp的用户之外的所有其它项删掉。这对于改变根文件系统的环境很重要,改变之后的“passwd”文件会是象下面这样的:

(编辑:IT资讯之家 www.it55.com

返回顶部
共2页: 上一页 1 [2] 下一页  

网友评论

[以下评论为网友观点,不代表本站。请自觉遵守互联网相关政策法规,所有连带责任均有评论者自负。]
[不超过250字]

图片文章