【轉載】CentOS 6.4 安裝 vsftpd FTP Server

vsFTPd (very secure FTP daemon) 作者為Chris Evans其主要著眼於安全、快速、穩定,在Linux系統中是很常用到的服務。安裝也非常的快速及簡單,安裝方法如下:

1. 安裝 vsftpd:
[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# touch /etc/vsftpd/chroot_list
[root@localhost ~]# chkconfig vsftpd on


2. 安裝完後讓防火牆可以通過 21 Port:
[root@localhost ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
[root@localhost ~]# service iptables save


3. 編輯 "/etc/vsftpd/vsftpd.conf"[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
找到:anonymous_enable=YES
將 YES 改成 NO。
如要限制用戶只能在自己的家目錄,則在檔案加入:
限制用戶只能在家目錄 (/etc/vsftpd/chroot_list 的用戶可不受限制)
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
如要 ftp 的檔案列表可以看到跟 Server 上同樣的時間,請在檔案加入:
# 使用本地時區
use_localtime=YES

4. 啟動 vsftpd:
[root@localhost ~]# service vsftpd start


基本上以上設定就架好FTP Server了,但如果你使用root登入會發現FTP 會回傳530 Permission denied.。為什麼會這樣呢?root不是最大權限系統管理者帳號嗎?理論上應該是通行無阻才對,原來是因為安全性的關係vsftp預設會將系統某些重要帳號設定為無法使用FTP服務。


[root@localhost ~]# ftp 192.168.0.118
Connected to 192.168.0.118 (192.168.0.118).
220 Welcome to ftp.netqna.com FTP Server.
Name (192.168.0.118:root): root
530 Permission denied.
Login failed.
ftp>


那要怎麼讓root可以登入FTP呢?請執行下面幾個動作

移除ftpusers 裡面的帳號

vim /etc/vsftpd/ftpusers
找到root 前面加上#號註解

[root@localhost ~]# vim /etc/vsftpd/ftpusers
# Users that are not allowed to login via ftpbin
#root
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
[root@localhost ~]#

移除user_list裡面的帳號

vim /etc/vsftpd/user_list
一樣找到root 前面加上#號註解

[root@localhost ~]# vim /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.bin
#root
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
[root@localhost ~]#

重新啟動VSFTPd 

[root@localhost ~]# /etc/init.d/vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]

重新使用root登入

[root@localhost ~]# ftp 192.168.0.118
Connected to 192.168.0.118 (192.168.0.118).
220 Welcome to ftp.netqna.com FTP Server.
Name (192.168.0.118:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> bye
221 Goodbye.
[root@localhost ~]#

增加FTP Server安全性

雖然root登入很方便,但還是有一定程度的安全性議題,畢竟FTP傳輸協定是明文在傳輸的,預設本身沒有加密,萬一帳號被竊取,很有可能導致公司重要資料被竊取,建議新增一個FTP User,而這個User不能登入系統,只能使用FTP 服務,即使帳號密碼被竊取,起碼可以將駭客的權限限制到FTP服務。以下兩個方法可以增加FTP的安全性。

限制FTP使用者

如果我們想把chris這個用戶目錄定位在/var/www/html/chris/public_html這個目錄中,並且不能登錄系統,我們應該如下操作

[root@localhost ~]# adduser -d /var/www/html/chris/public_html -g ftp -s /sbin/nologin chris
[root@localhost ~]# passwd chris


另外如果希望讓chris可以切換目錄,其它都不行的話,可以修改vsftpd.conf 加上兩行設定

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
並將chris寫入 /etc/vsftpd/chroot_list 之中即可!!

限制來源IP

設定只允許 192.168.0.0/24 的主機使用 FTP Server
編輯「/etc/hosts.allow」,輸入 vsftpd: 192.168.0.x
編輯「/etc/hosts.deny」,輸入 vsftpd: ALL 

總結

雖然已經限制了FTP使用者,也針對信任的來源IP纔可以使用FTP 服務,看起來好像很安全了,但是就如上文所說的,FTP還是使用明文傳輸,萬一網路環境不乾淨,駭客躲在網路的傳輸中加入一個惡意的節點,攔截所有經過的網路封包,接著嘗試取得封包內的機密訊息,例如帳號、密碼等..。這時如果訊息沒有經過加密就很有可能帳號密碼因此就外洩了,可怕的是在攔截的過程中雙方都會收到彼此的訊息,管理者很難發現被中間人攻擊了,建議可以使用SFTP (SSH File Transfer Protocol),就算封包被攔截竊取,駭客也需要花時間去解密,起碼管理者有緩衝的時間,做一些因應與處理。

出處:http://www.netqna.com/2014/04/centos-64-vsftpd-ftp-server.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章