Ubuntu14.04搭建FTP服務器記錄

1、Ubuntu 14.04下FTP服務器的安裝

1.安裝vsftpd

打開"終端窗口",輸入"sudo apt-get install vsftpd"-->回車-->安裝完成。html

2.判斷vsftpd是否安裝成功

打開"終端窗口",輸入"sudo service vsftpd restart"重啓vsftpd服務-->回車-->vsftpd處於運行狀態,說明安裝成功。linux

3.設置用戶主目錄、新建用戶ftp並設置密碼

打開"終端窗口",輸入"sudo useradd -d /home/workspace/project/Build_FOTA -s /bin/bash ftp"-->回車-->用戶新建成功-->輸入"sudo passwd ftp"設置ftp用戶的密碼-->回車-->輸入兩次密碼-->回車-->密碼設置成功。 ubuntu

設置完後,該ftp用戶瀏覽器訪問,只能看到Build_FOTA 目錄下的內容。
單純的使用useradd ftp1,沒有指定目錄的話,測試瀏覽器也是沒法訪問FTP服務器。
若是想刪除某個用戶,例如ftp,刪除命令爲:userdel -r ftp (參數-r 用於完全刪除)

root@chenwr-pc:/home/workspace/project/Build_FOTA# userdel -r ftp
userdel: ftp mail spool (/var/mail/ftp) not found
userdel: /srv/ftp not owned by ftp, not removing
複製代碼

4.默認配置FTP可以下載,可是沒法上傳文件

首先優先確認防火牆是否關閉。 selinux默認ubuntu不安裝,所以使用getenforce來查看當前selinux狀態windows

root@chenwr-pc:/etc/selinux# getenforce 
Disabled
複製代碼

其次肯定windows防火牆是否關閉 瀏覽器

鏈接到 172.16.XX.XX。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
ftp> user ftp
331 Please specify the password.

230 Login successful.
ftp>
ftp> put 1.zip /home/workspace/project/Build_FOTA/EC20-delta-gentools/v1/targetfiles.zip
200 PORT command successful. Consider using PASV.
550 Permission denied.
複製代碼

提示沒有權限,修改配置文件便可。 上傳 功能# Uncomment this to enable any form of FTP write command. write_enable=YES(開啓就行了) sudo service vsftpd restart重啓服務就ok安全

原先目錄存在同名文件,上傳文件提示沒法建立文件,此時只須要修改目錄權限便可。bash

200 PORT command successful. Consider using PASV.
553 Could not create file.
複製代碼

修改FTP服務器指定目錄的權限便可 chmod 777 -R EC20-delta-gentools/服務器

5.指定用戶訪問FTP服務器配置

(1)輸入"sudo gedit /etc/ftpusers",該文件記錄不能訪問FTP服務器的用戶清單 網絡

測試使用ftp2用戶沒法訪問

(2)本身新建文件存儲ftp用戶名來容許訪問的方式。app

root@chenwr-pc:/etc# vi cwr_allow_users
複製代碼

並添加ftp ftp1 ftp2 本身測試添加的用戶名,進行測試。 修改 /etc/vsftpd.conf配置文件,添加

  • userlist_deny=NO
  • userlist_enable=YES # vsftpd 將會從所給的用戶列表文件中加載用戶名字列表
  • userlist_file=/etc/cwr_allow_users # 存儲用戶名字的列表
  • 重啓服務

詳細說明:

配置 vsftpd.conf

第一步,配置userlist_deny

  • 當userlist_deny=YES,用戶列表/etc/cwr_allow_users中的用戶沒法訪問FTP服務器;
  • 當userlist_deny=NO,用戶列表/etc/cwr_allow_users中的用戶可以訪問FTP服務器;

第二步,userlist_enable=YES 啓用了用戶列表。

第三步,配置用戶列表,userlist_file=/etc/cwr_allow_users (cwr_allow_users這個文件本身新建的,隨意怎麼命名均可以)

root@chenwr-pc:/etc# cat cwr_allow_users 
ftp
ftp1
ftp2
複製代碼

6.卸載vsftpd和配置文件

sudo apt-get remove vsftpd --purge

root@chenwr-pc:~# sudo apt-get remove vsftpd --purge
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  vsftpd*
0 upgraded, 0 newly installed, 1 to remove and 750 not upgraded.
After this operation, 361 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 185238 files and directories currently installed.)
Removing vsftpd (3.0.2-1ubuntu2.14.04.1) ...
vsftpd stop/waiting
Purging configuration files for vsftpd (3.0.2-1ubuntu2.14.04.1) ...
Processing triggers for man-db (2.6.7.1-1) ...
複製代碼

2、vsftpd.conf配置文件

配置選項說明

anonymous_enable=NO       # 關閉匿名登陸
local_enable=YES                # 容許本地用戶登陸
write_enable=YES                # 啓用能夠修改文件的 FTP 命令
local_umask=022                  # 本地用戶建立文件的 umask 值
dirmessage_enable=YES      # 當用戶第一次進入新目錄時顯示提示消息
xferlog_enable=YES              # 一個存有詳細的上傳和下載信息的日誌文件
connect_from_port_20=YES # 在服務器上針對 PORT 類型的鏈接使用端口 20(FTP 數據)
xferlog_std_format=YES        # 保持標準日誌文件格式
listen=NO                               # 阻止 vsftpd 在獨立模式下運行
listen_ipv6=YES                     # vsftpd 將監聽 ipv6 而不是 IPv4,你能夠根據你的網絡狀況設置
pam_service_name=vsftpd    # vsftpd 將使用的 PAM 驗證設備的名字
userlist_enable=YES             # 容許 vsftpd 加載用戶名字列表
tcp_wrappers=YES                # 打開 tcp 包裝器
chroot_local_user=YES 	      # 選項chroot_local_user=YES 意味着本地用戶將進入 chroot 環境,當登陸之後默認狀況下是其 home 目錄。
allow_writeable_chroot=YES  # 默認狀況下,出於安全緣由,VSFTPD 不容許 chroot 目錄具備可寫權限。設置爲YES爲開啓寫權限。
複製代碼

參考資料: ubuntu 下的ftp詳細配置 - 何惜戈 - 博客園 www.cnblogs.com/hexige/p/78…

樹莓派FTP文件傳輸小記 - 興國的博客 - CSDN博客 blog.csdn.net/cyzyfs/arti…

相關文章
相關標籤/搜索