Ubuntu FTP服務(wù)器搭建,配置修改,所遇問題解決

1.安裝

sudo apt-get install vsftpd
這樣安裝后,配置文件在 /etc 下即: /etc/vsftpd.conf
備份默認配置
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
下面就是修改配置文件了,此時,我們需要明確的,就是需求,我們的需求如下:

1,一臺win服務(wù)器定時(每兩分鐘)向一臺Ubuntu服務(wù)器(本機器)發(fā)送一個文檔。
2,該win機只能訪問固定目錄,不能全局訪問
3,該win機對應(yīng)用戶名不能ssh登錄Ubuntu服務(wù)器
4,另創(chuàng)建一個可以全局訪問的用戶
5,為Ubuntu服務(wù)器上的幾個用戶開通ftp權(quán)限

注意,最終解決的方法可能并非最優(yōu)方法。

2.配置文件修改/etc/vsftpd.conf

  • 2.1默認配置
    官方解釋
    中文參考資料
  • 2.2重點配置項
    • anonymous_enable=YES/NO
      是否允許匿名登錄ftp。本項目是私有項目,故設(shè)為NO

    • write_enable=YES/NO
      是否允許寫入。例如添加文件等。本項目為YES

    • local_enable=YES/NO
      是否允許本地用戶登錄。本項目為YES

    • local_umask=022
      默認掩碼:設(shè)置用戶創(chuàng)建的文件的默認權(quán)限。同時ftp禁止直接創(chuàng)建一個可執(zhí)行的文件。umask碼與chmod時的碼互補。即若umask=022,實際權(quán)限為777-022=755。但是由于ftp又有上述的禁止條件,所以剛才的算法對文件夾適用,對于文件可以使用666-022=644。具體參考此鏈接 。本項目設(shè)置為022

    • chroot_local_user=YES/NO
      是否限制用戶在其目錄下。YES為限制,即用戶只能在自己的目錄下操作,無法到其他用戶目錄。本項目為YES

    • chroot_list_enable=YES/NO
      是否啟用一個列表,這個列表由chroot_list_file=/path/chroot_list來指定。這個列表里一行一個用戶名。

      • 如果此項設(shè)置為YES,即啟用列表則:
        chroot_local_user=YES,那么這個列表里的用戶就可以跳出目錄限制而有權(quán)限到其他用戶的路徑。
        chroot_local_user=NO,那么這個列表里的用戶就被限制在了自己的目錄而無法到其他用戶路徑。
      • 如果此項設(shè)置為NO,則不啟用列表,直接按chroot_local_user的設(shè)置來執(zhí)行。

      詳細參考此鏈接

    • allow_writeable_chroot=YES
      參考4.1

    • /etc/ftpusers
      這是一個文件,是個黑名單。里面用戶不能登錄ftp

    • userlist_file=/etc/vsftpd.user_list
      這也是指定了一個用戶列表(一行一個)。這個列表會根據(jù)其他配置而變成白名單黑名單
      其他配置即:userlist_enable 和 userlist_deny

    • userlist_enable=YES/NO
      是否啟用userlist(即userlist_file指定的列表)。

      • 當設(shè)置為YES時,這個列表的用戶能不能登錄取決于userlist_deny的值。
      • 當設(shè)置為NO時,除了/etc/ftpusers中的用戶,其他系統(tǒng)用戶都可以登錄。

      默認(即改配置被注釋或不出現(xiàn)在vsftpd.conf文件中時)為NO

    • userlist_deny=YES/NO
      是否把userlist設(shè)置為黑名單。YES為設(shè)置為黑名單;NO為白名單。
      注意!!此設(shè)置僅當userlist_enable=YES時才會起作用。
      默認為YES。即如果只設(shè)置userlist_enable=YES,而不設(shè)置此項,則userlist里的用戶是登錄不了的。

3.結(jié)果展示

登錄過程
登陸成功
網(wǎng)頁登錄

4.所遇問題

  • 4.1. userlist中用戶登錄時報錯:500 OOPS: vsftpd: refusing to run with writable root inside chroot()

解決方法見此處

If you're using vsftpd with chroot local user option and write enable like this:
write_enable=YES
chroot_local_user=YES
and you're getting following error when you log-in through ftp:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
you can fix the problem with adding following line to /etc/vsftpd.conf and restart the vsftpd service:
allow_writeable_chroot=YES

這是因為如果配置中開啟了chroot來控制用戶路徑(chroot_local_user=YES 說明用戶無法跳出自己的初始根目錄而去訪問他人的目錄),則用戶不能再具有在該用戶根目錄下的寫的權(quán)限。所以,要添加配置項allow_writeable_chroot=YES以開啟根目錄(非系統(tǒng)根目錄,而是用戶登錄后所在的最上級目錄)下寫權(quán)限。

  • 4.2. userlist中nologin用戶登錄時報錯:530 Login incorrect.

解決方法見此處

If you are not using PAM, then vsftpd will do its own check for a valid
user shell in /etc/shells. You may need to disable this if you use an invalid
shell to disable logins other than FTP logins. Put check_shell=NO in your
/etc/vsftpd.conf.

或者

Look at check_shell in vsftpd.conf:
Note! This option only has an effect for non-PAM builds of vsftpd.
If disabled, vsftpd will not check /etc/shells for a valid user
shell for local logins.
Default: YES
You can add '/usr/sbin/nologin' to /etc/shells. Simple and easy solution.
Another one is to change vsftpd.conf/PAM configuration.
Comment out this "auth ..." line in PAM case:
$ grep shells /etc/pam.d/vsftpd
auth required pam_shells.so

原因是vsftpd配置文件的check_shell默認是開啟的
當你的用戶當初創(chuàng)建時是用的-s /bin/false or -s bin/nologin
ftp會拿這個和/etc/shells文件比對,如果不包含,則報錯。所以,
你可以把check_shell設(shè)置為NO
或者把bin/nologin添加進/etc/shells來解決此問題。
又或者,找到vsftpd對應(yīng)的pam文件/etc/pam.d/vsftpd,把auth required pam_shells.so這一行注釋掉。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • ftp 文件傳輸協(xié)議 跨平臺 上傳下載文件 vsftpd 工具:非常安全的文件傳輸協(xié)議;默認的命令端口21號,數(shù)據(jù)...
    柒夏錦閱讀 4,109評論 1 9
  • 1 概述 工作中,需要搭建ftp服務(wù)器來實現(xiàn)資源的共享。本文將通過腳本實現(xiàn)自動化安裝ftp服務(wù)器,并進行相關(guān)配置,...
    ghbsunny閱讀 3,130評論 0 2
  • vsftpd.conf 部分:文件格式(5)索引 返回主要內(nèi)容 名稱 vsftpd.conf - vsftpd的配...
    張龍象閱讀 2,351評論 0 1
  • 圖片更清晰,文字在最下面 FTP是TCP/IP的一種應(yīng)用,使用TCP而不是UDP,所以是可靠的,面向連接的。 FT...
    停下浮躁的心閱讀 1,753評論 0 4
  • 1.測試環(huán)境: Centos 6.9虛擬主機中安裝以Vsftpd安裝為例 2.安裝過程: a)因為使用的Cento...
    十二樓中月閱讀 2,239評論 0 12