FTP 伺服器(10.10.10.160)
安裝
# yum install vsftpd
開機時啟動
# chkconfig vsftpd on
啟動服務
# service vsftpd start
Part1:讓匿名者上傳檔案
編輯組態檔 /etc/vsftpd/vsftpd.conf
# vim /etc/vsftpd/vsftpd.conf
anon_root=/var/ftp/pub
anonymous_enable=YES
write_enable=YES
anon_upload_enable=YES
# setsebool -P allow_ftpd_anon_write on
# service vsftpd restart
產生上傳目錄
# mkdir /var/ftp/pub/upload
# chmod 1777 /var/ftp/pub/upload
# ll -d /var/ftp/pub/upload
drwxrwxrwt. 2 root root 4096 Dec 13 13:50 /var/ftp/pub/upload
防火牆設定
# iptables -A INPUT -i eth0 -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp -m state --state NEW,INVALID -j DROP
# iptables -I INPUT -i eth0 -p tcp --dport 21 -m state --state NEW -j ACCEPT
FTP 客戶端測試(10.10.10.129)
# ftp 10.10.10.160
Connected to 10.10.10.160 (10.10.10.160).
220 (vsFTPd 2.2.2)
Name (10.10.10.160:root): anonymous
331 Please specify the password.
Password: 直接按 Enter 進入
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (10,10,10,160,86,44).
150 Here comes the directory listing.
drwxrwxrwt 2 0 0 4096 Dec 13 05:50 upload
226 Directory send OK.
ftp> cd upload
250 Directory successfully changed.
ftp> put install.log
local: install.log remote: install.log
227 Entering Passive Mode (10,10,10,160,158,187).
553 Could not create file. 上傳檔案被拒絕!?
註:成功連線後,使用指令 dir 或 ls 查看內容(包含其他指令,例如 put..),但畫面卻卡住,大部份是 FTP 伺服器沒有載入 nf_conntrack_ftp 模組,因為伺服器回應時不是透過 21port,而是以一個亂數產生的 port number 回應,而這個 port number 會被防火牆阻擋。
10.10.10.160# modprobe nf_conntrack_ftp
解決匿名上傳檔案被拒絕的問題(SELinux)
# tail -f /var/log/messages
Dec 13 15:12:41 localhost setroubleshoot: [avc.ERROR] Plugin Exception catchall_boolean #012Traceback
(most recent call last):#012 File "/usr/lib64/python2.6/site-packages/setroubleshoot/analyze.py", line 191, in
analyze_avc#012 report = plugin.analyze(avc)#012 File "/usr/share/setroubleshoot/plugins/catchall_boolean.py",
line 90, in analyze#012 man_page = self.check_for_man(b)#012 File
"/usr/share/setroubleshoot/plugins/catchall_boolean.py", line 76, in check_for_man#012 man_page =
name.split("_")[0] + "_selinux"#012AttributeError: 'tuple' object has no attribute 'split'
Dec 13 15:12:41
localhost setroubleshoot: SELinux is preventing /usr/sbin/vsftpd from write access on the directory upload.
For complete SELinux messages. run sealert -l c5f97a15-0622-4443-bdb3-a9ae3ac693c9 // 這個錯誤訊息
要裝 setroubleshoot 才會顯示
# sealert -l c5f97a15-0622-4443-bdb3-a9ae3ac693c9
If you want to allow /usr/sbin/vsftpd to be able to write to shared public content
Then you need to
change the label on upload to public_content_rw_t, and potentially turn on the
allow_httpd_sys_script_anon_write boolean.
# ll -dZ /var/ftp/pub/upload/
drwxrwsrwt. root root unconfined_u:object_r:public_content_t:s0 /var/ftp/pub/upload/
# chcon -t public_content_rw_t /var/ftp/pub/upload/
# ll -dZ /var/ftp/pub/upload/
drwxrwsrwt. root root unconfined_u:object_r:public_content_rw_t:s0 /var/ftp/pub/upload/
Part2:讓系一般使用者帳密登入自己家目錄,並讓家目錄成為使用者的根目錄
使用一般使用者帳密登入
# ftp 10.10.10.160
Connected to 10.10.10.160 (10.10.10.160).
220 (vsFTPd 2.2.2)
Name (10.10.10.160:root): guest
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/guest
Login failed.
編輯組態檔 /etc/vsftpd/vsftpd.conf
# vim /etc/vsftpd/vsftpd.conf
anon_root=/var/ftp/pub
anonymous_enable=YES
write_enable=YES
anon_upload_enable=YES
local_enable=YES
chroot_local_user=YES
passwd_chroot_enable=YES // 此設定是參考/etc/passwd內容
# setsebool -P ftp_home_dir on
# service vsftpd restart
chroot限制使用者到其他目錄,只能存取自己家目錄底下的子目錄。
# ftp 10.10.10.160
Connected to 10.10.10.160 (10.10.10.160).
220 (vsFTPd 2.2.2)
Name (10.10.10.160:root): guest
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
沒有留言:
張貼留言