我們有個企業解決方案(無論您需要哪種項目的服務,我們都可以滿足你的需求,如果我們沒有適合您的解決方案,我們也會您開發適合您的解決方案),最近一個客戶請我們架設FTP Server,需求是便宜、快速、穩定與安全,我第一個就想到使用Linux(免錢)來架vsFTPd(本身系統非常快速與穩定)啦,vsFTPd (very secure FTP daemon) 作者為Chris Evans其主要著眼於安全、快速、穩定,在Linux系統中是很常用到的服務。安裝也非常的快速及簡單,安裝方法如下:
1. 安裝 vsftpd:
2. 安裝完後讓防火牆可以通過 21 Port:
3. 編輯 "/etc/vsftpd/vsftpd.conf"
將 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:
基本上以上設定就架好FTP Server了,但如果你使用root登入會發現FTP 會回傳530 Permission denied.。為什麼會這樣呢?root不是最大權限系統管理者帳號嗎?理論上應該是通行無阻才對,原來是因為安全性的關係vsftp預設會將系統某些重要帳號設定為無法使用FTP服務。
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安全性
限制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
沒有留言:
張貼留言
如您對本文有任何建議或意見,歡迎您留下您寶貴的意見!