vps建站教程 CentOS6如何安裝配置FTP服務器


通過之前的幾篇文章,我們都知道了如何配置PHP環境,也知道如何保護我們的vps以及如何綁定多個域名建設多個網站。有時候我們為了讓我們的朋友也能用我們的vps建站又不想給他們太多權限,有時候我們想要當個主機商賣賣虛擬空間過過癮又不想裝管理環境,那么就想要裝個ftp服務器了。

經過前面的教程,相信大家對管理vps的操作是比較熟悉了,這里我就不在截圖了,安裝ftp服務器也是比較簡單的,相信大家可以輕松學會。

 

一安裝環境

1.先檢查有沒有安裝   rpm -q vsftpd
如果沒有安裝   yum install vsftpd

2.先關閉防火牆進行調試.

service iptables stop

或者一步到位   添加規則允許21端口通行
vi /etc/sysconfig/iptables

添加一條 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

為了讓FLASHFXP之類的軟件更好的連接服務器,得讓VSFTPD支持被動模式才行:

b.防火牆配置開放:

-A INPUT -p tcp --dport 30000:30100 -j ACCEPT
重啟防火牆即可
service iptables restart

這時應該可以用 winscp進行 SFTP連接了  ROOT帳戶
現在開始設置FTP   默認的已經可以用匿名登錄了

二。備份 etc/vsftpd/vsftpd.conf
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

編輯vsftpd.config文件   vi /etc/vsftpd/vsftpd.conf

anonymous_enable=NO
設定不允許匿名用戶訪問。

為了讓FLASHFXP之類的軟件更好的連接服務器,得讓VSFTPD支持被動模式才行,上面已經開通相應端口防火牆,在最后加入
pasv_enable=YES
pasv_max_port=30100
pasv_min_port=30000
(上面的30000--30100端口號可以是其它的,在此舉例)

/usr/sbin/setenforce 0 立刻關閉 SELINUX

#mkdir /tmp/test   //首先創建好目錄

#adduser -d /tmp/test -g ftp -s /sbin/nologin test


//-s /sbin/nologin是讓其不能登陸系統,-d 是指定用戶目錄為/tmp/test ,即該賬戶只能登陸ftp,卻不能用做登陸系統用。-g 是指定為FTP用戶組

#passwd test

Changing password for user beinan.//接下來會出現讓你設置新的密碼

**************************************************
【如果要刪除用戶,用下面代碼:
userdel test      //userdel + 用戶 即可刪除ftp用戶】
***********************************************************

有必要的話  設置TEST目錄權限

修改/var/www目錄屬性:
$ chmod -R 777 /var/www 遞歸地給此目錄下所有文件和子目錄的讀、寫、執行權限
$ chgrp -R ftp   /var/www 遞歸地把此目錄及該目錄下所有文件和子目錄的組屬性設置成ftp組

 

三。接着 限制用戶目錄,不得改變目錄到上級

修改/etc/vsftpd/vsftpd.conf
將這兩行
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
注釋去掉
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

新增一個文件: /etc/vsftpd/chroot_list
內容寫需要限制的用戶名:
test

重新啟動vsftpd

# service vsftpd restart

  

四。最后為了防止服務器由於斷電、重啟等現象發生,導致ftp進程在開機后未啟動,將其添加到開機啟動文件中:

(1)找到/etc/rc.local文件

(2)打開該文件,在最后一行添加:service vsftpd start

(3)保存,退出

 

 

附:vsftpd的配置文件說明:
vsftpd.ftpusers:位於/etc目錄下。它指定了哪些用戶賬戶不能訪問FTP服務器,例如root等。
vsftpd.user_list:位於/etc目錄下。該文件里的用戶賬戶在默認情況下也不能訪問FTP服務器,僅當vsftpd .conf配置文件里啟用userlist_enable=NO選項時才允許訪問。
vsftpd.conf:位於/etc/vsftpd目錄下。來自定義用戶登錄控制、用戶權限控制、超時設置、服務器功能選項、服務器性能選項、服務器響應消息等FTP服務器的配置。
(1)用戶登錄控制
anonymous_enable=YES,允許匿名用戶登錄。
no_anon_password=YES,匿名用戶登錄時不需要輸入密碼。
local_enable=YES,允許本地用戶登錄。
deny_email_enable=YES,可以創建一個文件保存某些匿名電子郵件的黑名單,以防止這些人使用Dos攻擊。
    banned_email_file=/etc/vsftpd.banned_emails,當啟用deny_email_enable功能時,所需的電子郵件黑名單保存路徑(默認為/etc/vsftpd.banned_emails)。
(2)用戶權限控制
write_enable=YES,開啟全局上傳權限。
local_umask=022,本地用戶的上傳文件的umask設為022(系統默認是077,一般都可以改為022)。
anon_upload_enable=YES,允許匿名用戶具有上傳權限,很明顯,必須啟用write_enable=YES,才可以使用此項。同時我們還必須建立一個允許ftp用戶可以讀寫的目錄(前面說過,ftp是匿名用戶的映射用戶賬號)。
anon_mkdir_write_enable=YES,允許匿名用戶有創建目錄的權利。
chown_uploads=YES,啟用此項,匿名上傳文件的屬主用戶將改為別的用戶賬戶,注意,這里建議不要指定root賬號為匿名上傳文件的屬主用戶!
chown_username=whoever,當啟用chown_uploads=YES時,所指定的屬主用戶賬號,此處的whoever自然要用合適的用戶賬號來代替。
chroot_list_enable=YES,可以用一個列表限定哪些本地用戶只能在自己目錄下活動,如果chroot_local_user=YES,那么這個列表里指定的用戶是不受限制的。
     chroot_list_file=/etc/vsftpd.chroot_list,如果chroot_local_user=YES,則指定該列表(chroot_local_user)的保存路徑(默認是/etc/vsftpd.chroot_list)。
nopriv_user=ftpsecure,指定一個安全用戶賬號,讓FTP服務器用作完全隔離和沒有特權的獨立用戶。這是vsftpd系統推薦選項。
async_abor_enable=YES,強烈建議不要啟用該選項,否則將可能導致出錯!
ascii_upload_enable=YES;ascii_download_enable=YES,默認情況下服務器會假裝接受ASCⅡ模式請求但實際上是忽略這樣的請求,啟用上述的兩個選項可以讓服務器真正實現ASCⅡ模式的傳輸。
注意:啟用ascii_download_enable選項會讓惡意遠程用戶們在ASCⅡ模式下用“SIZE/big/file”這樣的指令大量消耗FTP服務器的I/O資源。
這些ASCⅡ模式的設置選項分成上傳和下載兩個,這樣我們就可以允許ASCⅡ模式的上傳(可以防止上傳腳本等惡意文件而導致崩潰),而不會遭受拒絕服務攻擊的危險。
(3)用戶連接和超時選項
idle_session_timeout=600,可以設定默認的空閑超時時間,用戶超過這段時間不動作將被服務器踢出。
data_connection_timeout=120,設定默認的數據連接超時時間。
(4)服務器日志和歡迎信息
dirmessage_enable=YES,允許為目錄配置顯示信息,顯示每個目錄下面的message_file文件的內容。
ftpd_banner=Welcome to blah FTP service,可以自定義FTP用戶登錄到服務器所看到的歡迎信息。
xferlog_enable=YES,啟用記錄上傳/下載活動日志功能。
xferlog_file=/var/log/vsftpd.log,可以自定義日志文件的保存路徑和文件名,默認是/var/log/vsftpd.log。
anonymous_enable=YES 允許匿名登錄local_enable=YES 允許本地用戶登錄
write_enable=YES 開放本地用戶寫權限
local_umask=022 設置本地用戶生成文件的掩碼為022
#anon_upload_enable=YES 此項設置允許匿名用戶上傳文件
#anon_mkdir_write_enable=YES 開啟匿名用戶的寫和創建目錄的權限
dirmessage_enable=YES 當切換到目錄時,顯示該目錄下的.message隱藏文件的內容
xferlog_enable=YES 激活上傳和下載日志
connect_from_port_20=YES 啟用FTP數據端口的連接請求
#chown_uploads=YES 是否具有上傳權限. 用戶由chown_username參數指定。
#chown_username=whoever 指定擁有上傳文件權限的用戶。此參數與chown_uploads聯用。
#xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES 使用標准的ftpd xferlog日志格式
#idle_session_timeout=600 此設置將在用戶會話空閑10分鍾后被中斷
#data_connection_timeout=120 將在數據連接空閑2分鍾后被中斷
#ascii_upload_enable=YES 啟用上傳的ASCII傳輸方式
#ascii_download_enable=YES 啟用下載的ASCII傳輸方式
#ftpd_banner=Welcome to blah FTP service 設置用戶連接服務器后顯示消息
#deny_email_enable=NO 此參數默認值為NO。當值為YES時,拒絕使用banned_email_file參數指定文件中所列出的e-mail地址用戶登錄。
#banned_email_file=/etc/vsftpd.banned_emails 指定包含拒絕的e-mail地址的文件.
#chroot_list_enable=YES 設置本地用戶登錄后不能切換到自家目錄以外的別的目錄
#chroot_list_file=/etc/vsftpd.chroot_list
#ls_recurse_enable=YES
pam_service_name=vsftpd 設置PAM認證服務的配置文件名稱,該文件存放在/etc/pam.d/
userlist_enable=YES 此項配置/etc/vsftpd.user_list中指定的用戶也不能訪問服務器,若添加userlist_deny=No,則僅僅/etc/vsftpd.user_list文件中的用戶可以訪問,其他用戶都不可以訪問服務器。如過userlist_enable=NO,userlist_deny=YES,則指定使文件/etc/vsftpd.user_list中指定的用戶不可以訪問服務器,其他本地用戶可以訪問服務器。
listen=YES 指明VSFTPD以獨立運行方式啟動
tcp_wrappers=YES 在VSFTPD中使用TCP_Wrappers遠程訪問控制機制,默認值為YES

  


#***********************************************************************
#附 vsftpd.conf 配置,完整版
#***********************************************************************
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd whith two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

#######################################################################

 

來源:138vps推薦網


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM