[Linux] 简单搭建校园FTP-----LINUX篇

 

今天跟同学们说下怎么搭建校园FTP,以此来加强校内资源流通,在这个网络状况让人抓狂的今天,相信很有必要。。。   大家看了帖子就可以搭建自己的FTP了,希望到时候成功的同学可以把你们的FTP贡献出来。。。
      其实搭建一个简单的FTP是没什么难度的,再新的新手看完帖子相信都能自己作出来自己的FTP,所以请耐心看下去。。。下面教程开始
      linux本来就是为服务器而生的,所以拿linux来做服务器最好不过了,同时linux下面的FTP客户端也很丰富,今天要介绍的就是最出名的一款:vsftpd,这款软件使用简单并且功能强大,可能令新手不适应的是没有GUI,但是文字配置感觉更简单,更好玩!
      第一:下载并且安装vsftpd软件,ubuntu下面在终端执行
  1. sudo apt-get install vsftpd
复制代码
,等待片刻就下载并且安装完成了,并且默认已经启动服务且加入了自启动,下面就可以开始配置vsftpd了!

      第二:配置vsftpd,在终端输入
  1. sudo gedit /etc/vsftpd.conf
复制代码
便会打开配置文件,如下图


下面贴出来我的配置文件:(以#开头的为注释,可以忽略,整个直接复制替换掉你的就可以了)
  1. # Example config file /etc/vsftpd.conf
  2. #
  3. # The default compiled in settings are fairly paranoid. This sample file
  4. # loosens things up a bit, to make the ftp daemon more usable.
  5. # Please see vsftpd.conf.5 for all compiled in defaults.
  6. #
  7. # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
  8. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
  9. # capabilities.
  10. #
  11. #
  12. # Run standalone?  vsftpd can run either from an inetd or as a standalone
  13. # daemon started from an initscript.
  14. listen=YES
  15. anon_max_rate=81920
  16. #
  17. # Run standalone with IPv6?
  18. # Like the listen parameter, except vsftpd will listen on an IPv6 socket
  19. # instead of an IPv4 one. This parameter and the listen parameter are mutually
  20. # exclusive.
  21. #listen_ipv6=YES
  22. #
  23. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  24. anonymous_enable=YES
  25. #
  26. # Uncomment this to allow local users to log in.
  27. #local_enable=YES
  28. #
  29. # Uncomment this to enable any form of FTP write command.
  30. #write_enable=YES
  31. #
  32. # Default umask for local users is 077. You may wish to change this to 022,
  33. # if your users expect that (022 is used by most other ftpd's)
  34. #local_umask=022
  35. #
  36. # Uncomment this to allow the anonymous FTP user to upload files. This only
  37. # has an effect if the above global write enable is activated. Also, you will
  38. # obviously need to create a directory writable by the FTP user.
  39. #anon_upload_enable=YES
  40. #
  41. # Uncomment this if you want the anonymous FTP user to be able to create
  42. # new directories.
  43. #anon_mkdir_write_enable=YES
  44. #
  45. # Activate directory messages - messages given to remote users when they
  46. # go into a certain directory.
  47. dirmessage_enable=YES
  48. #
  49. # If enabled, vsftpd will display directory listings with the time
  50. # in  your  local  time  zone.  The default is to display GMT. The
  51. # times returned by the MDTM FTP command are also affected by this
  52. # option.
  53. use_localtime=YES
  54. #
  55. # Activate logging of uploads/downloads.
  56. xferlog_enable=YES
  57. #
  58. # Make sure PORT transfer connections originate from port 20 (ftp-data).
  59. connect_from_port_20=YES
  60. #
  61. # If you want, you can arrange for uploaded anonymous files to be owned by
  62. # a different user. Note! Using "root" for uploaded files is not
  63. # recommended!
  64. #chown_uploads=YES
  65. #chown_username=whoever
  66. #
  67. # You may override where the log file goes if you like. The default is shown
  68. # below.
  69. xferlog_file=/var/log/vsftpd.log
  70. #
  71. # If you want, you can have your log file in standard ftpd xferlog format.
  72. # Note that the default log file location is /var/log/xferlog in this case.
  73. #xferlog_std_format=YES
  74. #
  75. # You may change the default value for timing out an idle session.
  76. #idle_session_timeout=600
  77. #
  78. # You may change the default value for timing out a data connection.
  79. #data_connection_timeout=120
  80. #
  81. # It is recommended that you define on your system a unique user which the
  82. # ftp server can use as a totally isolated and unprivileged user.
  83. #nopriv_user=ftpsecure
  84. #
  85. # Enable this and the server will recognise asynchronous ABOR requests. Not
  86. # recommended for security (the code is non-trivial). Not enabling it,
  87. # however, may confuse older FTP clients.
  88. #async_abor_enable=YES
  89. #
  90. # By default the server will pretend to allow ASCII mode but in fact ignore
  91. # the request. Turn on the below options to have the server actually do ASCII
  92. # mangling on files when in ASCII mode.
  93. # Beware that on some FTP servers, ASCII support allows a denial of service
  94. # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
  95. # predicted this attack and has always been safe, reporting the size of the
  96. # raw file.
  97. # ASCII mangling is a horrible feature of the protocol.
  98. #ascii_upload_enable=YES
  99. #ascii_download_enable=YES
  100. #
  101. # You may fully customise the login banner string:
  102. #ftpd_banner=Welcome to blah FTP service.
  103. #
  104. # You may specify a file of disallowed anonymous e-mail addresses. Apparently
  105. # useful for combatting certain DoS attacks.
  106. #deny_email_enable=YES
  107. # (default follows)
  108. #banned_email_file=/etc/vsftpd.banned_emails
  109. #
  110. # You may restrict local users to their home directories.  See the FAQ for
  111. # the possible risks in this before using chroot_local_user or
  112. # chroot_list_enable below.
  113. #chroot_local_user=YES
  114. #
  115. # You may specify an explicit list of local users to chroot() to their home
  116. # directory. If chroot_local_user is YES, then this list becomes a list of
  117. # users to NOT chroot().
  118. #chroot_local_user=YES
  119. #chroot_list_enable=YES
  120. # (default follows)
  121. #chroot_list_file=/etc/vsftpd.chroot_list
  122. #
  123. # You may activate the "-R" option to the builtin ls. This is disabled by
  124. # default to avoid remote users being able to cause excessive I/O on large
  125. # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
  126. # the presence of the "-R" option, so there is a strong case for enabling it.
  127. #ls_recurse_enable=YES
  128. #
  129. #
  130. # Debian customization
  131. #
  132. # Some of vsftpd's settings don't fit the Debian filesystem layout by
  133. # default.  These settings are more Debian-friendly.
  134. #
  135. # This option should be the name of a directory which is empty.  Also, the
  136. # directory should not be writable by the ftp user. This directory is used
  137. # as a secure chroot() jail at times vsftpd does not require filesystem
  138. # access.
  139. secure_chroot_dir=/var/run/vsftpd/empty
  140. #
  141. max_clients=600
  142. max_per_ip=500
  143. # This string is the name of the PAM service vsftpd will use.
  144. pam_service_name=vsftpd
  145. #
  146. # This option specifies the location of the RSA certificate to use for SSL
  147. # encrypted connections.
  148. rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
复制代码

     我的FTP文件配置情况:只允许匿名用户访问,且只有读取的权限,这样做是最安全的,管理服务器本地完成就好了;最大连接数为600个IP,每个IP的限制线程为500;保存日志文件到/var/log/vsftpd.log,方便查看!  这样的配置基本就能满足要求了,需要更复杂的配置可以自己找男人(man),命令
  1. man vsftpd
复制代码
  

    第三:挂载自己想要共享给别人的目录到/srv/ftp,命令为
  1. sudo mount --bind XXXX  /srv/ftp/XXXX
复制代码
比如:
  1. sudo mount --bind /media/software/Ubuntu  /srv/ftp/Ubuntu
复制代码
  ,这样就可以挂载自己的目录到你的FTP服务器家目录了!如图:


      这样基本就可以了,你可以重启下你的vsftpd服务再进下你的FTP服务器看下,重启vsftpd命令为
  1. sudo /etc/init.d/vsftpd restart
复制代码
,现在你可以进下FTP就可以看到你挂载进去的目录了,FTP地址为:ftp://XXX.XXX.XXX.XXX 其中后面的XXX.XXX.XXX.XXX为你自己的IP!

      第四(增强):其实FTP已经搭配完成了,剩下的就是做点能让FTP更方便的事,比如开机自动挂载自己的目录到FTP家目录并且重启vsftpd服务,下面贴出我的脚本:
  1. #!/bin/bash
  2. sudo mount --bind /media/software/Ubuntu  /srv/ftp/Ubuntu
  3. sudo mount --bind /media/music/免费FTP /srv/ftp/Windows
  4. sudo /etc/init.d/vsftpd restart
复制代码

       同学们可以保存下来,保存名为ftp放到主目录,并且加上可执行权限,命令:
  1. sudo chmod +x ftp
复制代码
,这样就能作为程序执行了!接着把这个脚本加入到开机自起,但是直接加入是不可以的,因为执行权限是sudo,普通用户开机登录是并不能挂载,这里还得用到上一篇帖子里面让瑞捷开机自动人证的方法开启免输sudo密码的方法,方法如下:
在终端里面输入命令
  1. sudo vi
  2. /etc/sudoers
复制代码
  会在终端里面打开一个文本文件,按住键盘上的向下方向键,到最好一行,然后摁一下a,进入编辑模式,然后把最后一行的%admin ALL=(ALL)改为%admin ALL=(ALL) NOPASSWD: NOPASSWD: ALL   这时候按一下Esc键退出编辑模式,然后输入下面命令::wq!  这个命令表示强制写入和退出,因为sudoers文件属性是只读的,这也是为什么用vi来编辑而不用gedit,因为vi可以编辑只读文件。注意!一定不要妄想给sudoers加上可写权限,因为一旦你这样做,将无法使用sudo!(昨天我就自作聪明的把权限改成了777,结果差点系统挂了,幸好原来开启了root用户。。。)

到了这里剩下的就好办了,接着:系统-----首选项----启动应用程序----添加:名称ftp 命令:
  1. sudo /home/xsj/ftp
复制代码

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值