1. 程式人生 > >Debian8下安裝ftp伺服器 Vsftpd伺服器配置 ftp圖片伺服器

Debian8下安裝ftp伺服器 Vsftpd伺服器配置 ftp圖片伺服器


先上圖 羨慕 下面開始工作

現在網上的文件差不多大體都能做出來,但是主要是細節沒說,我就不知道他們怎麼成功的,還有幾乎所有文件都是一樣的,天下文章一大抄。版本過老,都是坑。

我的伺服器:Debian GNU/Linux 8

配置篇

說明:debian預設安裝是沒有開啟任何防火牆的,為了伺服器的安全,建議大家安裝啟用防火牆設定,

這裡推薦使用iptables防火牆。

whereis iptables   #檢視系統是否安裝防火牆

iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已經安裝iptables

apt-get install iptables   #如果預設沒有安裝,請執行此命令安裝防火牆

iptables -L  #檢視防火牆配置資訊,

vi /etc/iptables.default.rules    #新增以下內容
##################################################################################################
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0


-A INPUT -i lo -j ACCEPT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
# You could modify this to only allow certain traffic
-A OUTPUT -j ACCEPT
# Allows HTTP and MySQL and FTP connections from anywhere (the normal ports for websites)

-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp --dport 21 -j ACCEPT
-A INPUT -p tcp --dport 9000:9045 -j ACCEPT
# Allows SSH connections for script kiddies
# THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Now you should read up on iptables rules and consider whether ssh access
# for everyone is really desired. Most likely you will only allow access from certain IPs.
# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# log iptables denied calls (access via 'dmesg' command)
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Reject all other inbound - default deny unless explicitly allowed policy:
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT
#######################################################################################

備註:21是指FTP預設埠、80是指web伺服器埠、3306是指MySQL資料庫連結埠、

22是指SSH遠端管理埠、9000到9045是FTP被動模式埠範圍

iptables-restore < /etc/iptables.default.rules    #使防火牆規則生效

nano  /etc/network/if-pre-up.d/iptables   #建立檔案,新增以下內容,使防火牆開機啟動
##########################################################
#!/bin/bash
/sbin/iptables-restore </etc/iptables.default.rules
##########################################################

chmod +x  /etc/network/if-pre-up.d/iptables  #新增執行許可權

二、安裝Vsftpd伺服器

apt-get install vsftpd   #根據提示,輸入y安裝完成

三、配置Vsftpd伺服器

cp /etc/vsftpd.conf  /etc/vsftpd.confbak  #備份原有配置檔案

vi /etc/vsftpd.conf  #編輯

listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
dirmessage_enable=NO
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
async_abor_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to laoyang.com FTP servers
pam_service_name=vsftpd
userlist_enable=NO
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vconf
virtual_use_local_privs=yes
pasv_enable=yes
pasv_min_port=9010
allow_writeable_chroot=YES
pasv_max_port=9020
listen_port=21
tcp_wrappers=YES
具體說明可以再網上檢視

四、建立虛擬使用者名稱單檔案

mkdir /etc/vsftpd  #建立目錄

cat /etc/vsftpd/login.txt

      vsftp       123456

aptitude install db5.3-util          這是安裝db4這個工具,用來生成資料庫的。(第一坑,網上都是3-4,找不到的原因是現在已經是5.3了)
db5.3_load -T -t hash -f login.txt vsftpd_login.db 生成虛擬使用者資料檔案

五、生成虛擬使用者資料檔案

chmod 600 /etc/vsftpd/vsftpd_login.db  #設定PAM驗證檔案,並指定對虛擬使用者資料庫檔案進行讀取

cp /etc/pam.d/vsftpd  /etc/pam.d/vsftpdbak   #備份原有配置檔案


vi /etc/pam.d/vsftpd  #編輯配置檔案,在頭部加入以下資訊(在後面加入無效),並註釋最後四行

# Standard behaviour for ftpd(8).
auth required /lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
#auth   required        pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed

# Note: vsftpd handles anonymous logins on its own. Do not enable pam_ftp.so.

# Standard pam includes
#@include common-account
#@include common-session
#@include common-auth
#auth   required        pam_shells.so

(第二坑,注意紅色部分,要找到你的環境pam_userdb.so所在位置。find / -name security -type d 查詢下)

六、新建一個系統使用者vsftpd,使用者家目錄為/home/www.osyunwei.com, 使用者登入終端設為/bin/false(即使之不能登入系統)

useradd vsftpd -d /home/web -s /bin/false   #建立使用者vsftpd

chown vsftpd:vsftpd /home/web -R  #設定使用者家目錄


七、建立虛擬使用者個人Vsftp的配置檔案

mkdir  /etc/vsftpd/vconf    #建立目錄

cd /etc/vsftpd/vconf  #進入目錄

touch vsftp  #這裡建立三個虛擬使用者配置檔案(使用者名稱不能為root,系統保留)

nano vsftp #編輯使用者bbs配置檔案

local_root=/home/web

write_enable=YES

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

#儲存配置

八、重啟vsftpd伺服器

apt-get install chkconfig  #安裝chkconfig

chkconfig  vsftpd  on   #開機啟動vsftpd

/etc/init.d/vsftpd restart  #重啟

/etc/init.d/vsftpd stop  #停止

/etc/init.d/vsftpd start #啟動

測試篇

在Windows客戶端cmd命令列下輸入

ftp

open 192.168.21.139

vsftp

123456  #密碼

230 Login successful.

參考網址:

http://www.osyunwei.com/archives/4539.html

http://blog.chinaunix.net/uid-23986132-id-1746025.html

http://www.cnblogs.com/hhuai/archive/2011/02/12/1952647.html

http://pep525.blog.51cto.com/2544662/519516/