1. 程式人生 > >在CentOS下新增ftp帳戶並限制其可訪問目錄

在CentOS下新增ftp帳戶並限制其可訪問目錄

在CentOS下新增ftp帳戶並限制其可訪問目錄

步驟

安裝vsftpd

yum install -y vsftpd

新增一個名為cindy的使用者

sudo useradd -s /sbin/nologin --home-dir /var/cindy cindy

-s /sbin/nologin防止cindy經由ssh登入
--home-dir(或-m) /var/cindy設定了ftp開啟時的目錄(即家目錄)

如果這一步做錯,可能會需要以下指令:
列出所有存在的使用者

cat /etc/passwd | less

刪除名為cindy的帳戶

userdel cindy

設定使用者cindy的密碼

passwd cindy

這裡需畏輸入兩次長度大於等於8的密碼。

讓使用者cindy(及其它所有使用者)只可訪問其家目錄

修改vsftpd的設定檔:

vim /etc/vsftpd/vsftpd.conf

在最後一行加入,讓使用者可以修改其家目錄:

allow_writeable_chroot=YES

這個設定的目的是為瞭解決以下錯誤:
(參考Fixing 500 OOPS: vsftpd: refusing to run with writable root inside chroot

Fixing 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()

參考FTP cannot change directory,將allow_writeable_chroot=YES加在設定檔最後一行可能會有問題,因此額外多加了一個空行。

然後找到chroot_local_user

chroot_list_enable,將它們改為:

chroot_local_user=YES
chroot_list_enable=NO

重啟ftp service讓設定生效

service vsftpd restart

如何讓使用者訪問家目錄外的其它目錄?

有時候除了家目錄外,我們還想讓使用者存取其它的目錄,這時可以透過mount這個指令來解決。
詳見:讓ftp使用者只可存取其家目錄,但給予soft link或mount的存取權

參考連結

讓ftp使用者只可存取其家目錄,但給予soft link或mount的存取權
Error message “500 OOPS: vsftpd: refusing to run with writable root inside chroot()” - keep user jailed
Fixing 500 OOPS: vsftpd: refusing to run with writable root inside chroot
FTP cannot change directory
The Complete Guide to “useradd” Command in Linux – 15 Practical Examples
A command to list all users? And how to add, delete, modify users?
Linux下新增FTP賬號和伺服器、增加密碼和使用者,更改FTP目錄
Linux中如何新增/刪除FTP使用者並設定許可權