zoukankan      html  css  js  c++  java
  • ubuntu16.04搭建ftp服务器

      哎呀呀呀晕晕晕晕晕晕!先来叹气一波,花费了一天的时间

      环境:虚拟机

      搭建原因:虚拟机上挂载U盘失败后就想到了使用ftp文件上传下载,于是行动

      搭建过程:ubuntu安装ftp很简单:

          

    sudo apt-get update 
    
    sudo apt-get install vsftpd
    
    [vsftpd --version 检测是否安装]

         ftp配置是很有学问的,必须要强调的是如果你的ftp服务无法启动,十有八九就是配置文件的配置错误

         配置参考如下:

      

    listen=NO
    listen_ipv6=YES
    
    # Allow anonymous FTP? (Disabled by default).
    anonymous_enable=NO
    
    # 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
    
    # Activate directory messages - messages given to remote users when they
    # go into a certain directory.
    dirmessage_enable=YES
    #
    # If enabled, vsftpd will display directory listings with the time
    # in  your  local  time  zone.  The default is to display GMT. The
    # times returned by the MDTM FTP command are also affected by this
    # option.
    use_localtime=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
    
    # 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.
    # Note that the default log file location is /var/log/xferlog in this case.
    xferlog_std_format=YES
    
    
    # You may fully customise the login banner string:
    ftpd_banner=Welcome to FTP service.
    
    
    # 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().
    # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
    # the user does not have write access to the top level directory within the
    # chroot)
    chroot_local_user=YES
    chroot_list_enable=YES
    # (default follows)
    chroot_list_file=/etc/vsftpd.chroot_list
    
    # 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/empty
    #
    # This string is the name of the PAM service vsftpd will use.
    # pam_service_name=vsftpd
    pam_service_name=ftp
    
    # This option specifies the location of the RSA certificate to use for SSL
    # encrypted connections.
    rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
    rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
    ssl_enable=NO
    
    #
    # Uncomment this to indicate that vsftpd use a utf8 filesystem.
    utf8_filesystem=YES
    上面的配置文件中,我不是很熟悉,我挑一些我稍微知道的讲。
    
    listen=NO不了解,我查看了很多博客,这个设置的是YES,但是我设置成YES,登陆直接被拒绝。
    anonymous_enable=NO拒绝匿名登陆
    write_enable=YES设置可以上传文件,这个设置看需要个人需要
    xferlog_enable=YES开启日志记录
    xferlog_file=/var/log/vsftpd.log设置日志文件路径
    xferlog_std_format=YES设置日志格式为标准输出
    connect_from_port_20=YES绑定20端口
    ftpd_banner=Welcome to FTP service.欢迎语句,在使用shell时可以看到
    下面这几个的设置比较重要:
    
    chroot_local_user=YES
    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd.chroot_list 
    上面的这几个配置实现的功能是:用户被限制在自己的主目录下。用户名单来源于/etc/vsftpd.chroot_list。 
    具体可以参考:http://blog.csdn.net/bluishglc/article/details/42398811
    一个重要的配置
    
    pam_service_name=ftp原配置中为vsftpd,ubuntu用户需要更改成ftp
    关于编码:
    
    utf8_filesystem=YES 
    不知道这项有没有起作用,上传的文件不乱码,用浏览器打开是乱码(浏览器编码问题?),使用windows自带的文件资源管理器是没有乱码的,使用filezila乱码。
    创建用户:
    
    mkdir /home/username
    sudo useradd username -g ftp -d /home/username -m username
    sudo passwd username's password
    mkdir /home/username/pub
    chmod 777 -R /home/username/pub新建一个pub目录用于存放文件,并且赋予全部访问权限
    usermod -s /sbin/nologin username限制用户username只能通过ftp登陆,而不能直接登陆服务器
    
    重要的一点:
    
    新建/etc/vsftpd.chroot_list将username放进去
    启动vsftpd或者重启
    
    systemctl start vsftpd或者service vsftpd start
    systemctl restart vsftpd或者service vsftpd restart
    登陆:
    
    在windows的文件资源管理器或者在浏览器中打开ftp://your_server_ip输入账号密码,即可用登陆。浏览器中只能查看,文件操作如新建等需要在window的文件资源管理器中或者filezila中进行。

    测试 

      使用filezilla等工具

      

    现在在windows下打开cmd窗口,执行命令:

    ftp [你的linux机器的ip地址]
    • 1

      linux下查看ip地址的命令为:

    ifconfig
    • 1

      执行完ftp命令后,如果连接成功,会让你输入用户名和密码,输入我们刚刚添加的用户uftp的用户名和密码即可: 
      image_1b6e2jfpi1okq1obiiajsdg3ebm.png-18.4kB

      命令pwd和lcd分别可以查看远程linux下和本地windows下的当前目录: 
       
      image_1b6e2lanng2bk8611i3ns21emb13.png-9.2kB 
       
      现在在linux下的目录/home/uftp下新建文件test_ftp_download.txt,在windows下的家目录(我的为C:Users40696)下新建文件test_ftp_upload.txt,分别用来测试下载和上传功能: 
      

    下载文件使用命令:get [文件名]
    上传文件使用命令:put [文件名]
    • 1
    • 2

       
      image_1b6e2td69155h1cr71bsod5b14u91g.png-26.8kB

        

  • 相关阅读:
    Jmeter 调试接口用例怎么判断提取的上一个接口返回值是正确的?
    Jmeter 加密处理方法
    Apache Ignite 学习
    jmeter 中 浮点数计算精度问题
    httprunner 使用总结
    oh-my-zsh 安装及使用
    内置装饰器二:@property
    内置装饰器一:@classmethod、@staticmathod
    python实现列表的排序
    Mac git简易使用
  • 原文地址:https://www.cnblogs.com/YangJieCheng/p/8252577.html
Copyright © 2011-2022 走看看