zoukankan      html  css  js  c++  java
  • 【转载】debian上快速搭建ftp

    转载自:http://suifengpiaoshi.diandian.com/post/2012-05-05/17955899

    搭建ftp

    包括搭建ftp服务器和ftp客户端

    本文以debian上搭建vsftp为例,展示如何允许一个本地用户名用ftp客户端登录。
    因为匿名用户登录的方式比较简单,就不讨论了。注意conf文件的配置就好了。

    下面开始:

    一、建立ftp服务器

    先来段引用:

    华丽的分割线
    *************************************************************************

    安装vsftp

    apt-get install vsftpd

    配置/etc/vsftpd.conf

    # 服务器以standalong模式运行,这样可以进行下面的控制
    listen=YES
    # 接受匿名用户
    anonymous_enable=YES
    # 匿名用户login时不询问口令
    no_anon_password=YES
    # 接受本地用户
    local_enable=YES
    # 可以上传(全局控制).若想要匿名用户也可上传则需要设置anon_upload_enable=YES,
    # 若想要匿名用户可以建立目录则需要设置anon_mkdir_write_enable=YES.这里禁止匿
    # 名用户上传,所以不设置这两项.
    write_enable=YES
    # 本地用户上传文件的umask
    local_umask=022
    # 如果设为YES,匿名登入者会被允许上传目录的权限,当然,匿名使用者必须要有对上
    # 层目录的写入权。
    anon_upload_enable=YES
    # 定义匿名登入的使用者名称。默认值为ftp
    ftp_username=ftp
    # 如果设为YES,匿名登入者会被允许新增目录,当然,匿名使用者必须要有对上层目录
    # 的写入权。
    anon_mkdir_write_enable=YES
    # 为YES则进入目录时显示此目录下由message_file选项指定的文本文件
    # (,默认为.message)的内容
    dirmessage_enable=YES
    # 本地用户login后所在目录,若没有设置此项,则本地用户login后将在他的home目录
    # (/etc/passwd的第六个字段)中.匿名用户的对应选项是anon_root
    # local_root=/home
    anon_root=/home/ftp/
    # 使用上传/下载日志,日志文件默认为/var/log/vsftpd.log,可以通过xferlog_file
    # 选项修改
    xferlog_enable=YES
    # Make sure PORT transfer connections originate from port 20 (ftp-data).
    connect_from_port_20=YES
    # 日志使用标准xferlog格式
    xferlog_std_format=YES
    # You may change the default value for timing out a data connection.
    data_connection_timeout=120
    # 关闭本地用户chroot()
    chroot_local_user=NO
    # 设置为yes则下面的控制有效。
    # 开启要设置chroot()用户项.
    chroot_list_enable=YES
    # (default follows)
    # 指定要设置chroot()的特定用户文件
    chroot_list_file=/etc/vsftpd.chroot_list
    # 若设置为YES则记录在userlist_file选项指定文件(默认是/etc/vsftpd.user_list)
    # 中的用户无法login,并且将检察下面的userlist_deny选项
    userlist_enable=YES
    # 若为NO,则仅接受记录在userlist_file选项指定文件(默认是/etc/vsftpd.user_list)
    # 中的用户的login请求.若为YES则不接受这些用户的请求.
    userlist_deny=NO
    # 注意!!!vsftpd还要检察/etc/vsftpd.ftpusers文件,记录在这个文件中的用户将
    # 无法login!!
    # 匿名用户的传输比率(b/s)
    anon_max_rate=512000
    # 本地用户的传输比率(b/s)
    local_max_rate=1024000
    # 可接受的最大client数目
    max_clients=100
    # 每个ip的最大client数目
    max_per_ip=5
    # This option should be the name of a directory which is empty.  Also, the
    # directory should not be writable by the ftp user. This directory is used
    # as a secure chroot() jail at times vsftpd does not require filesystem access.
    secure_chroot_dir=/var/run/vsftpd
    # This string is the name of the PAM service vsftpd will use.
    pam_service_name=vsftpd

    tcp_wrappers=YES

    # This option specifies the location of the RSA certificate to use for SSL
    # encrypted connections.
    rsa_cert_file=/etc/ssl/certs/vsftpd.pem
    # 每一个联机,都能以独立的process 来呈现.
    setproctitle_enable=YES
    # 若是启动,所有匿名上传数据的拥有者将被更换为chown_username当中所设定的使用
    # 者。这样的选项对于安全及管理,是很有用的。
    chown_uploads=YES
    # 这里可以定义当匿名登入者上传档案时,该档案的拥有者将被置换的使用者名称。预
    # 设值为root。
    chown_username=root

    下面继续配置其他相关

    增加用户名一堆(都属于ftpuser组的)

    groupadd ftpuser
    mkdir /home/john/
    useradd -g ftpuser john
    passwd john

    补充/etc/passwd 中缺漏的/bin/bash

    比如

    john:x:1001:1001::/home/john:

    增加为

    john:x:1001:1001::/home/john:/bin/bash

    否则很可能shell无法解析命令。

    更改文件所有者以及权限

    chown -v -R john:ftpuser /home/john/
    chmod -v -R 700 /home/john/

    给ftpuser组所有用户共享一个文件夹,做一个连接

    ln -v -s /home/ftpuser/ /home/john/ftpuser

    在每个用户的文件夹中设置.message做欢迎界面

    编辑/etc/vsftpd.user_list 填写所有可以ftp的用户,包括匿名anonymous

    编辑/etc/vsftpd.chroot_list 填写不准进入上层目录的用户名

    给/home/ftp/中允许匿名写的目录修改权限。

    chmod -v 777 /home/ftp/temp/

    做两个定时工作 crontab -e 在里面写

    0,10,20,30,40,50 * * * * chmod 555 /home/ftp/incoming/*
    # 每10分钟修改一次/home/ftp/incoming/ 中的权限
    0 4 * * 1 rm -rf /home/ftp/incoming/temp/*
    # 每星期一凌晨4点清空/home/ftp/incoming/temp/文件夹
    0 5 10 * * /sbin/reboot
    # 每个月10日凌晨5点重新启动电脑

    重启vsftp

    /etc/init.d/vsftpd restart

    好了,ftp服务器做好了。

    *************************************************************************
    华丽的分割线

    上面的文字仅仅是为了增长见识,因为按照上面的方式做后,似乎还少了什么?
    对了,我一开始就说了是允许一个本地用户(名)用ftp客户端登录。
    那么就根据需要,说一些要修改的地方了。

    1. 先给出我的vsftp配置文件(/etc/vsftpd.conf)中需要修改的内容:

    # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
    # 我不允许匿名登录
    anonymous_enable=NO
    #
    # Uncomment this to allow local users to log in.
    # 允许本地用户通过ftp登录
    local_enable=YES
    #
    # Uncomment this to enable any form of FTP write command.
    # 允许ftp客户端写操作,即上传文件
    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
    # I need the same group share, so just umask group "others"
    # 这步其实是为了方便我自己在debian多用户的环境下,懒得修改组共享的权限。可以不修改。
    # umask=007的意思是创建文件时,屏蔽others组用户的所有权限,
    # 可以参考《Unix环境高级编程》相关章节的介绍。
    local_umask=007

    ......

    # You may restrict local users to their home directories.  See the FAQ for
    # the possible risks in this before using chroot_local_user or
    # chroot_list_enable below.
    #chroot_local_user=YES
    #
    # 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_local_user=YES
    #chroot_list_enable=YES
    # 将ftp客户端限制在其登录起始目录,不允许cd到上层目录,这是出于安全的考虑。
    # 我可不希望ftp客户端看到太多的东西。
    # 说明一下:chroot()的目的是为了将用户的根目录锁定到某个目录,
    # 让用户感觉到自己的顶层目录就是根目录,但其实那只是真正的linux文件系统中的某个子目录罢了。
    chroot_local_user=YES
    # 下行是表明我不想使用禁止ftp用户列表。
    # 该列表(chroot_list_file=/etc/vsftpd.chroot_list)记录了哪些本地用户可以cd到上层目录。
    # 我可没那么多闲工夫写这个额外的配置文件,所以索性不实现该列表好了。
    chroot_list_enable=NO
    # (default follows)
    #chroot_list_file=/etc/vsftpd.chroot_list
    #

    2. 先给出我的vsftp另一个配置文件(/etc/ftpusers)中需要修改的内容:

    # /etc/ftpusers: list of users disallowed FTP access. See ftpusers(5).

    root
    daemon
    bin
    sys
    sync
    games
    man
    lp
    mail
    news
    uucp
    nobody
    xing
    windy

    这个文件用于禁止里面的用户使用ftp登录服务器。
    从上面可以看到root、xing等重要用户都被禁用了,这样做是为避免高权限的用户使用ftp。
    而用于测试ftp客户端登录的foolsmile用户没有在里面,下面马上就会介绍到。

    二、使用ftp客户端登录

    这里回头说说我搭建ftp的初衷,其实是为了用我的defy手机(android)上传文件到我的电脑(debian)上。
    那么测试也在defy上展开:

    首先得有ftp客户端工具,我这里使用ES文件浏览器中自带的ftp客户端功能,因为我手机上没有安装“终端”。
    输入ip(比如192.168.1.102),输入port(默认21),输入用户名foolsmile,密码******,
    点击“登录”。
    ok

  • 相关阅读:
    mysql主从复制+读写分离
    lnmp平台菜鸟入门级笔记
    Shell编程
    Shell编程之--“grep-awk-sed” 基础用法汇总
    Nginx
    LB负载均衡之Nginx-Proxy
    LB(Load balance)负载均衡集群-LVS
    HA(High available)-Keepalived高可用性集群(双机热备)单点实验
    HA(High available)--Heartbeat高可用性集群(双机热备)
    linux -小记(3) 问题:linux 安装epel扩展源报错
  • 原文地址:https://www.cnblogs.com/pengdonglin137/p/3249040.html
Copyright © 2011-2022 走看看