Centos FTP伺服器(本機使用者)

來源:互聯網
上載者:User

標籤:

LAMP環境搭建是完成了,但是我們需要把開發人員做的網站上傳至伺服器的Apache網站目錄,這樣以來客戶才能正常訪問!這裡使用的上傳、下載的服務是Vsftpd

環境介紹

  • 本案例是接著LAMP環境搭建接軌、案例中使用的是"本機使用者"(不安全)來進行登入並上傳測試
  • 為解決依賴預設還是使用Yum源來進行安裝
  • 因多數瀏覽器、資源管理員、Cmd這寫Windows內建Ftp工具不專業,在此推薦一款專業的Ftp用戶端工具FileZila    32位下載 <-----> 64位下載
  • Vsftp版本:vsftpd-2.2.2

環境搭建

  • 首先保證Linux作業系統可以訪問外網並且可以解析網域名稱
[[email protected] ~]# ping -c 2 www.baidu.comPING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.64 bytes from 61.135.169.121: icmp_seq=1 ttl=52 time=39.5 ms64 bytes from 61.135.169.121: icmp_seq=2 ttl=52 time=39.9 ms
  • 安裝Vsftpd
[[email protected] ~]# yum -y install vsftpd[[email protected] ~]# chkconfig vsftpd on             //開機啟動[[email protected] ~]# service vsftpd start            //啟動服務[[email protected] ~]# netstat -ntulp | grep :21      //查看是否啟動成功tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      4117/vsftpd[[email protected] ~]# iptables -I INPUT -p tcp --dport 21 -j ACCEPT           //加入防火牆允許規則
  • 配置Vsftpd
//為了案例需求、下面配置中並沒有完全解釋ftp檔案解析、將會在後面的FTP虛擬使用者一一舉出[[email protected] ~]# cd /etc/vsftpd/                  //進入vsftpd目錄[[email protected] vsftpd]# vim vsftpd.conf             //編輯設定檔anonymous_enable=NO//不允許匿名登入local_enable=YES                    //允許本地登入write_enable=YES    //FTP伺服器開放對本機使用者的寫入權限local_umask=022//設定本機使用者的檔案產生掩碼dirmessage_enable=YES//當切換到FTP伺服器中的某個目錄時,將顯示該目錄下的“.message”隱含檔案了內容xferlog_enable=YES//啟用上傳和下載日誌connect_from_port_20=YES//啟用ftp資料連接埠的串連請求xferlog_file=/var/log/xferlog//ftpd xferlog日誌儲存路徑xferlog_std_format=YES//使用標準的ftpd xferlog日誌格式chroot_local_user=YES//為YES時、在 chroot_list中不給使用者切換到上級目錄,其他都給與切換chroot_list_enable=NO//為YES時、在 chroot_list中給使用者切換到上級目錄,其他的不允許//當這兩個都為YES時、chroot_list_enable 優先chroot_list_file=/etc/vsftpd/chroot_list         //chroot_list的檔案目標listen=YES//ftp伺服器將使用tcp_wrappers作為主機存取控制模式pam_service_name=vsftpd//PAM認證服務的設定檔名稱,該檔案儲存在"/etc/pam.d/"目錄下userlist_enable=YES//ftp將檢查userlist_file設定檔案中指定的使用者是否可以訪問vsftpd伺服器tcp_wrappers=YESuserlist_deny=NO//與userlist_enable配套使用//為YES時、user_list的使用者列表不能訪問ftp伺服器,檔案外的使用者可以訪問//為NO時、user_list的使用者列表允許訪問ftp伺服器,檔案外的使用者將不可以訪問local_root=/var/www/html//本機使用者Ftp根路徑
[[email protected] ~]# useradd -s /sbin/nologin lansha        //建立不允許登入的系統使用者[[email protected] ~]# passwd lansha  //設定使用者密碼[[email protected] ~]# cd /var/www/      //進入網站目錄[[email protected] www]# setfacl -m u:lansha:rwx html/  //建立一個acl許可權,使 lansha 使用者對 html/目錄擁有讀、寫、執行[[email protected] ~]# cd /etc/vsftpd/                    //進入vsftpd目錄[[email protected] vsftpd]# vim chroot_list  //建立並編輯chroot_list、這裡面的使用者列表將不能切換上級目錄lansha[[email protected] vsftpd]# vim user_list  //編輯 user_list、除了這裡面的使用者以外的使用者將無法登入lansha[[email protected] ~]# setsebool -P ftp_home_dir=1  //設定使用者可以訪問home目錄[[email protected] ~]# setsebool -P allow_ftpd_full_access=1  //設定使用者擁有所有許可權[[email protected] ~]# service vsftpd restart  //重啟服務Shutting down vsftpd:                                      [  OK  ]Starting vsftpd for vsftpd:                                [  OK  ]

環境測試  

  • 安裝下載好的 FileZila 工具、安裝完成過後開啟軟體、輸入Ftp伺服器主機:IP/網域名稱  使用者名稱 ‘lansha‘ 、密碼  輸入連接埠 21 點擊串連

 

  • 保證Apache是運行狀態、在本地上傳一個網頁 ‘index.html‘至伺服器

  • 訪問網站

  

  

 

 

  

 

Centos FTP伺服器(本機使用者)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.