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è)為NOwrite_enable=YES/NO
是否允許寫入。例如添加文件等。本項目為YESlocal_enable=YES/NO
是否允許本地用戶登錄。本項目為YESlocal_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è)置為022chroot_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í)行。
詳細參考此鏈接
- 如果此項設(shè)置為YES,即啟用列表則:
allow_writeable_chroot=YES
參考4.1/etc/ftpusers
這是一個文件,是個黑名單。里面用戶不能登錄ftpuserlist_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é)果展示
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
這一行注釋掉。