天天看點

linux搭建FTP服務

在網際網路出現以前,使用者使用DOS方式傳輸檔案,最通用的應用程式就是FTP,FTP屬于應用層協定,使用TCP端口20和21進行傳輸

FTP有兩種檔案傳輸模式:

二進制模式,用于傳輸程式檔案(比如字尾名為.app、.bin和.btm的檔案)

ASCII碼模式,用于傳輸文本格式的檔案(比如字尾名為.txt、.bat和.cfg的檔案)

第一步、安裝ftp軟體

[root@localhost ~]#yum install vsftpd -y 

第二步、設定FTP的配置檔案

[root@localhost ~]#vim /etc/vsftpd/vsftpd.conf 

#vsftpd預設支援匿名使用者的通路,Vsftpd的匿名使用者叫做ftp,ftp帳号的家目錄是/var/ftp,其中有個目錄稱為pub

anonymous_enable=YES //設定是否允許匿名使用者登入FTP伺服器,預設為YES(改為no就使用本地使用者名密碼登入)

local_enable=YES //是否允許本地使用者登入FTP伺服器,預設為NO。

write_enable=YES //是否對登入使用者開啟寫權限,屬全局性設定,預設NO。

pam_service_name=vsftpd //設定PAM認證服務的配置檔案名稱,該檔案存放在/etc/pam.d/目錄下.

userlist_enable=YES //使用者清單中的使用者是否允許登入FTP伺服器,預設是不允許

tcp_wrappers=YES //使用tcp_wrqppers作為主機通路控制方式

chroot_local_user=YES#将本地帳号鎖定在其家目錄中

local_max_rate=1000#本地帳号的限速操作

local_umask=022#上傳後檔案的權限

local_root=/var/ftp#設定本地使用者登入後所在的目錄

anon_root=/var/ftp#設定匿名使用者登入後所在的目錄

第三步、修改使用者權限(将root注釋掉,不拒絕root使用者登入,其它使用者都拒絕通路)

[root@localhost ~]#vim /etc/vsftpd/user_list

[root@localhost ~]#vim /etc/vsftpd/ftpusers

user_list這個檔案是用來記錄"不允許"登入到FTP伺服器的使用者,通常是一些系統預設的使用者

root //預設情況下,root和它以下的使用者是不允許登入FTP伺服器的.可以将不允許登入的使用者添加到這裡來.但切記每個使用者都要單獨占用一行.

ftpusers其實它的内容結合user_list對使用者檢測

在vsftpd中使用本地帳号登入,将直接登入到該帳号的家目錄中,這時要特别注意selinux,如果開啟,将無切換到家目錄中

setsebool -P ftpd_disable_trans=1  //配置VSFTPD時本地使用者無法切換

第四步、設定ftp目錄權限

[root@localhost ~]# chmod 777 /var/ftp#預設匿名帳号隻能下載下傳,不能上傳,修改,重命名檔案

匿名帳号隻能向其家目錄下的一個子目錄上傳檔案,例如:向/var/ftp/pub目錄中上傳檔案。(/var/ftp/pub目錄必須有寫入的權限)

[root@localhost ~]# vim /etc/hosts.allow 

通過/etc/hosts.allow和/etc/hosts.deny來控制使用者的通路,這種方式稱為TCPWRAPPER

/etc/hosts.allow

vsftpd:172.24.254.254

etc/hosts.deny

ALL:ALL

第五步、重新開機FTP服務

[root@localhost ~]#service vsftpd  restart  重新啟動FTP服務(這裡防火牆已經關閉了)

[root@localhost ~]# sestatus -b | grep ftp  

[root@localhost ~]#sudo setsebool -P /var/ftp on

第六步、驗證登入資訊

打開浏覽器 輸入ftp://IP  即可登入或

<a href="https://s1.51cto.com/wyfs02/M00/06/C5/wKiom1m-MwmzLh-hAAGlDV884L4264.jpg" target="_blank"></a>

關閉windows防火牆再試試

<a href="https://s3.51cto.com/wyfs02/M00/A5/76/wKioL1m-M1HBBxcVAAHOIwfFs8c535.jpg" target="_blank"></a>

搭建TFTP服務

[root@localhost ~]# yum install tftp-server -y 

[root@localhost ~]# vim /etc/xinetd.d/tftp #編輯使其打開tftp功能    

# default: off

# description: The tftp server serves files using the trivial file transfer \

#       protocol.  The tftp protocol is often used to boot diskless \

#       workstations, download configuration files to network-aware printers, \

#       and to start the installation process for some operating systems.

service tftp

{

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -s /var/lib/tftpboot

        disable                 = no

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

~                                                                                           

~              

[root@localhost ~]# service xinetd restart

本文轉自 周小玉 51CTO部落格,原文連結:http://blog.51cto.com/maguangjie/1875211,如需轉載請自行聯系原作者

繼續閱讀