首页 运维 正文
用Proftpd构建Ttp服务器

 2022-10-23    366  

proftpd构建ftp服务器:

  FTP服务被广泛的应用着,常见的,一些大学、组织、机构等等,都有通过FTP服务器向外发布数据…但在这里,我们将要构建的FTP服务器将主要针对 用于用户更新自己的网站。也就是说,让用户(root除外)只可以访问自己的Web目录(本站前面介绍的HTTP服务器构建中以public_html为 例)。

用Proftpd构建Ttp服务器

  另外,为了避免通过平文传输时,数据被截获,从而泄漏隐私与密码,我们采用TLS方式,加密FTP传输过程中的数据,以确保安全。

  (构建FTP服务器,您将有多种选择,比如通过vsftpd等等FTP服务器软件。但ProFTPD在一些方面,更能够符合我们的实际条件,尤其对于ADSL方式接入网络的服务器,ProFTPD能够很好的应对不断变化的IP地址造成的问题。)

  安装 ProFTPD

  由于ProFTPD不存在于CentOS中yum的官方库中,所以用yum安装ProFTPD需要定义非官方的库。请先确认相应非官方库文件的存在。

  [root@sample~]#ls-l/etc/yum.repos.d/dag.repo ←确认相应库文件的存在性 
  •   -rw-r--r--1rootroot143Oct121:33/etc/yum.repos.d/dag.repo ←确认其存在(否则不能通过yum安装ProFTPD)
  •   如果以上,dag.repo文件不存在,则不能通过yum安装ProFTPD,需要定义非官方库。定义非官方库的方法请见 “CentOS的下载、安装及初始环境设置”一节中yum的相关设置。而且,在此前提下也要保证所定义的dag.repo文件的语法的正确性。

      然后,通过yum来在线安装ProFTPD。

      [root@sample~]#yum-yinstallproftpd ←安装ProFTPD 
  •   SettingupInstallProcess
  •   Settinguprepositories
  •   Readingrepositorymetadatainfromlocalfiles
  •   ReducingDagRPMRepositoryforRedHatEnterpriseLinuxtoincludedpackagesonly
  •   Finished
  •   Parsingpackageinstallarguments
  •   ResolvingDependencies
  •   -->Populatingtransactionsetwithselectedpackages.Pleasewait.
  •   --->Downloadingheaderforproftpdtopackintotransactionset.
  •   proftpd-1.2.10-10.2.el4.r100%|=========================|15kB00:00
  •   --->Packageproftpd.i3860:1.2.10-10.2.el4.rfsettobeupdated
  •   -->Runningtransactioncheck
  •   DependenciesResolved
  •   =============================================================================

      PackageArchVersionRepositorySize 
  •   =============================================================================

      Installing: 
  •   proftpdi3861.2.10-10.2.el4.rfdag699k
  •   TransactionSummary
  •   =============================================================================

      Install1Package(s) 
  •   Update0Package(s)
  •   Remove0Package(s)
  •   Totaldownloadsize:699k
  •   DownloadingPackages:
  •   (1/1):proftpd-1.2.10-10.100%|=========================|699kB00:03
  •   RunningTransactionTest
  •   FinishedTransactionTest
  •   TransactionTestSucceeded
  •   RunningTransaction
  •   Installing:proftpd#########################[1/1]
  •   Installed:proftpd.i3860:1.2.10-10.2.el4.rf
  •   Complete!
  • #p#

      配置 ProFTPD

      然后,通过修改相应配置文件配置ProFTPD。

      [root@sample~]#vi/etc/proftpd.conf ←修改ProFTPD的配置文件 
  •   ServerType       standalone ←找到这一行,在行首添加“#”
  •   ↓
  •   #ServerType       standalone ←变为此状态,不使用常驻模式
  •   #ServerType      inetd ←找到这一行,去掉行首的“#”
  •   ↓
  •   ServerType      inetd ←变为此状态,通过超级服务器来启动ProFTPD
  •   DefaultRoot       ~!adm ←找到这一行,将“!adm”改为“/public_html!wheel”
  •   ↓
  •   DefaultRoot       ~/public_html!wheel ←变为此状态,使除wheel组用户的根目录为public_html
  •   找到TLS设置的语句群,如下:

      #TLS 
  •   #Explainedathttp://www.castaglia.org/proftpd/modules/mod_tls.html
  •   —————————————————————-

      #TLSEngine        on 
  •   #TLSRequired       on
  •   #TLSRSACertificateFile   /usr/share/ssl/certs/proftpd.pem
  •   #TLSRSACertificateKeyFile /usr/share/ssl/certs/proftpd.pem
  •   #TLSCipherSuite      ALL:!ADH:!DES
  •   #TLSOptions        NoCertRequest
  •   #TLSVerifyClient      off
  •   ##TLSRenegotiate     ctrl3600data512000requiredofftimeout300
  •   #TLSLog          /var/log/proftpd/tls.log
  •   —————————————————————-

      ↓将以上水平线间部分的语句,每行行首的“#”都去掉,变为下面水平线间的状态:

      —————————————————————-

      TLSEngine         on 
  •   TLSRequired        on ←只允许TLS方式的连接(如果将on改为off,普通方式也被允许)
  •   TLSRSACertificateFile    /usr/share/ssl/certs/proftpd.pem
  •   TLSRSACertificateKeyFile  /usr/share/ssl/certs/proftpd.pem
  •   TLSCipherSuite       ALL:!ADH:!DES
  •   TLSOptions         NoCertRequest
  •   TLSVerifyClient       off
  •   #TLSRenegotiate      ctrl3600data512000requiredofftimeout300
  •   TLSLog           /var/log/proftpd/tls.log
  •   —————————————————————-

      然后在配置文件的末尾填如下几行:

      ExtendedLog       /var/log/proftpd/access.logWRITE,READdefault ←记录连接日志到相应日志文件 
  •   ExtendedLog       /var/log/proftpd/auth.logAUTHauth ←记录认证日志到相应日志文件
  •   MasqueradeAddress   digeast.no-ip.info ←定义服务器域名
  •   PassivePorts       5000050030 ←为PASV模式连接时指定端口号(1024以后存在的任意端口号)
  •   然后,为服务器建立证书。
  •   [root@sample~]#cd/usr/share/ssl/certs ←进入相应的目录
  •   [root@samplecerts]#makeproftpd.pem ←建立服务器证书
  •   umask77;\
  •   PEM1=`/bin/mktemp/tmp/openssl.XXXXXX`;\
  •   PEM2=`/bin/mktemp/tmp/openssl.XXXXXX`;\
  •   /usr/bin/opensslreq-newkeyrsa:1024-keyout$PEM1-nodes-x509-days365-out$PEM2;\
  •   cat$PEM1>proftpd.pem;\
  •   echo"">>proftpd.pem;\
  •   cat$PEM2>>proftpd.pem;\
  •   rm-f$PEM1$PEM2
  •   Generatinga1024bitRSAprivatekey
  •   .........++++++
  •   ............++++++
  •   writingnewprivatekeyto'/tmp/openssl.sG3126'
  •   —–

      CountryName(2lettercode)[GB]:CN ←输入国家简写 
  •   StateorProvinceName(fullname)[Berkshire]:HeiLongJiang ←输入省份
  •   LocalityName(eg,city)[Newbury]:Harbin ←输入城市
  •   OrganizationName(eg,company)[MyCompanyLtd]:www.centospub.com ←输入组织名(任意)
  •   OrganizationalUnitName(eg,section)[]: ←直接回车跳过
  •   CommonName(eg,yournameoryourserver'shostname)[]:www.centospub.com ←FTP服务器名反馈
  •   EmailAddress[]:yourname@yourserver.com ←输入E-mail地址
  • #p#

      启动 ProFTPD

      启动之前,先对超级服务器的ProFTPD的启动脚本做一些修改。

      [root@samplecerts]#vi/etc/xinetd.d/xproftpd ←编辑ProFTPD启动脚本 
  •   log_on_success+=DURATIONUSERID ←找到此行,将“DURATIONUSERID”改为“HOSTPID”
  •   ↓
  •   log_on_success+=HOSTPID ←变为此状态,防止登录时要等待30秒
  •   log_on_failure+=USERID ←找到此行,将“USERID”改为“HOST”
  •   ↓
  •   log_on_failure+=HOST ←变为此状态,防止登录时要等待30秒
  •   disable=yes ←找到此行,将yes改为no
  •   ↓
  •   disable=no ←变为此状态,让ProFTPD通过超级服务器启动
  •   然后,通过重新启动超级服务器间接启动ProFTPD。

      [root@samplecerts]#chkconfigxproftpdon ←设置ProFTPD自启动 
  •   [root@samplecerts]#chkconfig--listxproftpd ←查看ProFTPD自启动
  •   xproftpdon ←确认为on的状态就OK
  •   [root@samplecerts]#/etc/rc.d/init.d/xinetdrestart ←重新启动超级服务器
  •   Stoppingxinetd:                [OK]
  •   Startingxinetd:                [OK]
  •   连接到FTP服务器

      当我们成功的启动了FTP服务之后,就可以通过客户端软件连接到服务器进行文件的上传和下载了。但由于,本站介绍的方法,把安全、传输的保密性放在了 ***位,这也就使得好多不支持TSL的FTP软件无法连接到服务器。支持TSL的FTP客户端软件,比较有代表性的有Staff-FTP, SmartFTP。本站将以SmartFTP为例(下一节),介绍如何从客户端通过FTP连接到服务器的方法。

    原文链接:https://77isp.com/post/8670.html

    =========================================

    https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。