Linux

使用 vsftpd 控制 ftp 訪問

  • September 13, 2018

I had vsftpd set up such that I was able to upload files to a VPS I set up. The only problem is that I could not create directories. I set up vsftpd to disallow anonymous users, but allow virtual users to connect with their local credentials. At this point, the error message when I tried to create a folder changed from ‘550: Create directory failed’ (I’m paraphrasing) to ‘550: Permission denied’. root owns the /var/www folder, and user with which I was authenticating had read and execute permissions but not write, so it makes sense that I wouldn’t be able to create folders or files.

At this point I tried using chown and chmod to recursively change the group ownership to a group that my user was in and give my user write permission. This seemed to work at first - in the SSH session, I was able to cd to /var/www and create a new directory. However, when I tried to log in with my ftp client, I was now denied access.

What’s even weirder is when I checked /var/log/vsftpd.log, I see the following lines:

Mon Jan  5 00:03:25 2015 [pid 801] CONNECT: Client "73.53.82.111"
Mon Jan  5 00:03:25 2015 [pid 800] [gradinafrica] OK LOGIN: Client "73.53.82.111"

…even though the login doesn’t seem to work. What’s going on?

EDIT (more info): OS: Ubuntu 14.04 Architecture: Virtual private server (?)

當我設置伺服器時,我不允許以 root 身份登錄(如多個來源所建議的那樣)並設置了一個不同的使用者 - ‘gradinafrica’ - 我將其添加到 sudo 組中。我正在嘗試將此帳戶用於 ftp。我根本沒有使用過 sftp。

這是 vsftpd.conf 的內容(註釋省略):

listen=YES
anonymous_enable=NO
local_enable=YES
virtual_use_local_privs=YES
anon_upload_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
local_root=/var/www/
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

如果您需要在 /var/www/ 中獲得使用者帳戶的寫入權限,則特定使用者希望根據您的作業系統成為 apache 或 www-data 組的成員。

write_enable=YES

僅當您添加了具有 Web 根目錄的使用者作為其主目錄時才使用此選項

allow_writeable_chroot=YES

引用自:https://unix.stackexchange.com/questions/177468