RHEL5.3-FTP—vsftpd服務安裝和配置

--------陳功磊 2009-6-1
說明:系統鏡像:[紅帽企業.Linux.5].rhel-5.2-server-i386-dvd.iso
1、vsftpd安裝
[root@linux01 ~]# mkdir /media/cdrom
[root@linux01 ~]# mount -t iso9660 /dev/cdrom /media/cdrom # 掛載鏡像
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@linux01 ~]# cd /media/cdrom/Server # 進入軟件包目錄
[root@linux01 Server]#
[root@linux01 Server]# rpm -qa | grep ^vsftpd # 查詢相關已經安裝的軟件包
[root@linux01 Server]# ls | grep vsftpd* # 查詢當前路徑下安裝包
vsftpd-2.0.5-12.el5.i386.rpm
[root@linux01 Server]# rpm -ivh vsftpd-2.0.5-12.el5.i386.rpm # 安裝軟件包 i安裝 v輸出詳細信息 h進度
warning: vsftpd-2.0.5-12.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:vsftpd ########################################### [100%]
[root@linux01 Server]# rpm -qa | grep ^vsftpd # 再次查詢相關已經安裝的軟件包
vsftpd-2.0.5-12.el5
[root@linux01 Server]#cd
[root@linux01 ~]# rpm -ql vsftpd | grep etc # 查詢etc中與vsftpd相關的文件
/etc/logrotate.d/vsftpd.log
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
/etc/vsftpd/vsftpd_conf_migrate.sh
[root@linux01 ~]#
2、、/etc/vsftpd/vsftpd.conf文件配置
[root@linux01 Server]# cat /etc/vsftp/vsftpd.conf # 讀取原文,默認配置
cat: /etc/vsftp/vsftpd.conf: No such file or directory
[root@linux01 Server]# cat /etc/vsftpd/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 # 顯示目錄下的.message
#
# Activate logging of uploads/downloads.
xferlog_enable=YES # 啓用上傳和下載日誌
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES # 啓用FTP數據端口
#
# 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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES # 使用標準的ftpd xferlog日誌格式
#
# 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 # FTP服務器處於獨立啓動模式(相對於受xinnetd管理的啓動模式)
#
# 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 # PAM認證服務的配置文件名稱,/etc/pam.d/vsftpd
userlist_enable=YES # FTP將檢查userlist_file(/etc/vsftpd/user_list)中用戶是否可以訪問FTP服務器
tcp_wrappers=YES # 使用tcp_wrappers作爲主機訪問控制方式,/etc/host.allow和/etc/hosts.deny。
[root@linux01 Server]#
3、/etc/vsftpd.user_list文件配置
[root@linux01 ~]# cd /etc/vsftpd
root@linux01 vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@linux01 vsftpd]# cat 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.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
[root@linux01 vsftpd]#
(當vsftp.conf配置文件中包括以下配置時,user_list中用戶帳號禁止登錄配置:
userlist_enable=YES # 注意大小寫
userlist_deny=YES
當vsftp.conf配置文件中包括以下配置時,只有user_list中用戶帳號允許登錄配置:注意考慮ftpusers文件用戶
userlist_enable=YES # 注意大小寫
userlist_deny=NO
)
[root@linux01 vsftpd]# cat ftpusers
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
[root@linux01 vsftpd]#
4、匿名用戶登錄目錄
匿名用戶將進入/var/ftp目錄
5、vsftpd服務啓動與關閉
root@linux01 vsftpd]# ls -l /etc/init.d/vsftpd # vsftpd啓動腳本文件
-rwxr-xr-x 1 root root 1778 Dec 13 2007 /etc/init.d/vsftpd
[root@linux01 vsftpd]#
[root@linux01 vsftpd]# chkconfig --list vsftpd # 查看
vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@linux01 vsftpd]# chkconfig --level 35 vsftpd on # 設置在35模式下隨機啓動
[root@linux01 vsftpd]# chkconfig --list vsftpd # 檢查查看
vsftpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@linux01 vsftpd]#
[root@linux01 vsftpd]# service vsftpd start # 啓用服務
Starting vsftpd for vsftpd: [ OK ]
[root@linux01 vsftpd]# service vsftpd stop # 停止服務
Shutting down vsftpd: [ OK ]
[root@linux01 vsftpd]# service vsftpd restart # 重啓服務
Shutting down vsftpd: [FAILED]
Starting vsftpd for vsftpd: [ OK ]
[root@linux01 vsftpd]# service vsftpd status # 查看服務狀態
vsftpd (pid 13071) is running...
[root@linux01 vsftpd]#
6、測試帳號登錄
[root@redhatCLI ~]# ftp 192.168.7.2
ftp: connect: No route to host # 防火牆阻止登錄
ftp>bye # 退出ftp
[root@linux01 vsftpd]# service iptables stop # 在服務器上關閉防火牆,在客戶端上也要關閉防火牆
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: nat filter [ OK ]
Unloading iptables modules: [ OK ]
[root@linux01 vsftpd]#
匿名帳號登錄(可以登錄)
[root@redhatCLI ~]# ftp 192.168.7.2 #在客戶端上登錄ftp服務器
Connected to 192.168.7.2.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.7.2:root): anonymous # 使用匿名帳號登錄
331 Please specify the password.
Password: # 密碼爲空
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (192,168,7,2,159,53)
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Dec 13 2007 pub
226 Directory send OK.
ftp> pwd
257 "/"
ftp> bye
221 Goodbye.
[root@redhatCLI ~]#
服務器本地帳號登錄(默認不能登錄)
[root@redhatCLI ~]# ftp 192.168.7.2
Connected to 192.168.7.2.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.7.2:root): test01
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/test01 # 其他帳號同樣不能登錄,與user_list、vsftdpd.conf等無關
Login failed.
ftp> bye
服務器本地帳號不能登錄的修復處理
root@linux01 vsftpd]# setsebool ftpd_disable_trans 1 # 服務器本地帳號不能登錄的修復處理,
# disable SELinux protection of the ftp daemon
# 有什麼不會的後果就不知了。
[root@linux01 vsftpd]# service vsftpd restart # 重啓服務
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@linux01 vsftpd]#
[root@redhatCLI ~]# ftp 192.168.7.2 # 服務器本地帳號登錄
Connected to 192.168.7.2.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.7.2:root): test01
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (192,168,7,2,43,10)
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/home/test01"
ftp> cd / # 進入根目錄
250 Directory successfully changed.
ftp> pwd
257 "/" # 不安全啊
ftp> cd /home # 可以進入/home目錄
250 Directory successfully changed.
ftp> pwd
257 "/home
ftp> mkdir 123
550 Create directory operation failed.
ftp> bye
221 Goodbye.
[root@redhatCLI ~]#
7、禁錮登錄用只在宿主目錄中
[root@linux01 vsftpd]# vi 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.
#
……………………………..
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
chroot_local_user=YES # 添加此行,來禁錮登錄用只在宿主目錄中
"vsftpd.conf" 117L, 4419C written
[root@linux01 vsftpd]# service vsftpd restart # 重啓服務
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@linux01 vsftpd]#
測試
[root@redhatCLI ~]# ftp 192.168.7.2
Connected to 192.168.7.2.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.7.2:root): test01
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> cd /home # 不能使用cd進入非根目錄了
550 Failed to change directory.
ftp> bye
221 Goodbye.
[root@redhatCLI ~]#
8、配置FTP服務器的虛擬用戶(虛擬帳號對系統更安全)
(1)建立虛擬用戶口令庫文件
[root@linux01 ~]# touch /etc/vsftpd/logins.txt
[root@linux01 ~]# vi /etc/vsftpd/logins.txt
mike # 奇數行爲用戶名
pwabc # 偶數行爲密碼
john
pw1234
~
~
"/etc/vsftpd/logins.txt" 4L, 23C written
[root@linux01 ~]# cat /etc/vsftpd/logins.txt
mike
pwabc
john
pw1234
[root@linux01 ~]#
(2)生成vsftpd的認證文件
root@linux01 Server]# db # db + 兩次空格鍵
dbconverter-2 dbus-cleanup-sockets dbus-launch dbus-send
dbus-binding-tool dbus-daemon dbus-monitor dbus-uuidgen
[root@linux01 Server] # 可以看出沒有db-_load命令,默認系統沒有安裝時,要手工安裝了
[root@linux01 Server]# ls | grep ^db # 掛載好光驅後,進入到rpm包文件目錄,查看db有關軟件包
db4-4.3.29-9.fc6.i386.rpm
db4-devel-4.3.29-9.fc6.i386.rpm
db4-java-4.3.29-9.fc6.i386.rpm
db4-tcl-4.3.29-9.fc6.i386.rpm
db4-utils-4.3.29-9.fc6.i386.rpm
dbus-1.0.0-7.el5.i386.rpm
dbus-devel-1.0.0-7.el5.i386.rpm
dbus-glib-0.70-5.i386.rpm
dbus-glib-devel-0.70-5.i386.rpm
dbus-python-0.70-7.el5.i386.rpm
dbus-x11-1.0.0-7.el5.i386.rpm
[root@linux01 Server]#
[root@linux01 Server]# rpm -ivh db4-4.3.29-9.fc6.i386.rpm
[root@linux01 Server]# rpm -ivh db4-devel-4.3.29-9.fc6.i386.rpm
[root@linux01 Server]# rpm -ivh db4-java-4.3.29-9.fc6.i386.rpm
[root@linux01 Server]# rpm -ivh db4-tcl-4.3.29-9.fc6.i386.rpm
[root@linux01 Server]# rpm -ivh db4-utils-4.3.29-9.fc6.i386.rpm # 之後實驗好像裝他就可以了
[root@linux01 Server]# rpm -ivh dbus-1.0.0-7.el5.i386.rpm # 不知db_load是db4的哪個軟件包,所以都安裝了。
[root@linux01 Server]# db # db + 兩次空格鍵。嗨,有了,出來了吧。
db_archive db_dump185 db_upgrade dbus-monitor
db_checkpoint db_load dbus-binding-tool dbus-send
dbconverter-2 db_printlog dbus-cleanup-sockets dbus-uuidgen
db_deadlock db_recover dbus-daemon db_verify
db_dump db_stat dbus-launch
[root@linux01 Server]# cd
root@linux01 ~]# db_load -T -t hash -f /etc/vsftpd/logins.txt /etc/vsftpd/vsftpd_login.db # 生成vsftpd的認證文件
[root@linux01 ~]# file /etc/vsftpd/vsftpd_login.db # 查看文件類型
/etc/vsftpd/vsftpd_login.db: Berkeley DB (Hash, version 8, native byte-order)
[root@linux01 ~]# chmod 600 /etc/vsftpd/vsftpd_login.db # 設置文件只對root讀寫
[root@linux01 ~]# ls -l /etc/vsftpd/vsftpd_login.db
-rw------- 1 root root 12288 Jun 1 20:30 /etc/vsftpd/vsftpd_login.db
[root@linux01 ~]#
(3)建立虛擬用戶所需的PAM配置文件
[root@linux01 ~]# touch /etc/pam.d/vsftpd.vu # 新建文件
[root@linux01 ~]# vi /etc/pam.d/vsftpd.vu # 編輯
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
~
~
"/etc/pam.d/vsftpd.vu" 2L, 141C written
[root@linux01 ~]# cat /etc/pam.d/vsftpd.vu # 查驗
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
[root@linux01 ~]#
(4)建立虛擬用戶及要訪問的目錄並設置權限
[root@linux01 ~]# useradd -d /home/ftpsite virtual # 建立虛擬用戶所需的目錄及系統帳號
[root@linux01 ~]# chmod 700 /home/ftpsite/ # 設置宿主目錄的權限
[root@linux01 ~]# ls -l /home/
total 16
drwx------ 3 virtual virtual 4096 Jun 1 20:39 ftpsite # 剛健的虛擬宿主目錄,爲所有虛擬用戶使用
drwx------ 3 test01 test01 4096 Jun 1 18:58 test01 # 之前的本地用戶test01宿主目錄
[root@linux01 ~]#
(5)設置vsftpd.conf配置文件
[root@linux01 vsftpd]# cp vsftpd.conf vsftpd.conf_bake # 首先進入/etc/vsftpd目錄,然後備份,以防有問題
[root@linux01 vsftpd]# vi vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
#
………………………………..
guest_enable=YES # 添加的內容
guest_username=virtual # 添加的內容
pam_service_name=vsftpd.vu # 添加的內容
"vsftpd.conf" 120L, 4484C written
[root@linux01 vsftpd]#
(6)重啓vsftpd服務
root@linux01 vsftpd]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@linux01 vsftpd]#
(7)測試虛擬用戶帳號 (注意:虛擬帳號和本地用戶帳號默認不可同時生效)
root@linux01 vsftpd]# touch /home/ftpsite/afile # 建立也測試文件
[root@linux01 vsftpd]# chown virtual.virtual /home/ftpsite/afile # 賦予權限
[root@linux01 vsftpd]# ls -l /home/ftpsite
total 4
-rw-r--r-- 1 virtual virtual 0 Jun 1 20:53 afile
[root@linux01 vsftpd]#
[root@redhatCLI ~]# ftp 192.168.7.2
Connected to 192.168.7.2.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.7.2:root): mike
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (192,168,7,2,246,249)
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).
ftp>bye
9、典型FTP服務器設置
[root@linux01 Server]# cat /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
anonymous_enable=YES # 允許匿名登錄
local_enable=YES # 允許本地帳戶登錄
.
write_enable=YES # 開放對本地用戶的寫權限
local_umask=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=whoever
#xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES # 使用標準的ftpd xferlog日誌格式
#idle_session_timeout=600
#data_connection_timeout=120
#nopriv_user=ftpsecure
#async_abor_enable=YES
#ascii_upload_enable=YES
#ascii_download_enable=YES
#deny_email_enable=YES
#banned_email_file=/etc/vsftpd/banned_emails
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd/chroot_list
#ls_recurse_enable=YES
listen=YES # FTP服務器處於獨立啓動模式(相對於受xinnetd管理的啓動模式)
#listen_ipv6=YES
pam_service_name=vsftpd # PAM認證服務的配置文件名稱,/etc/pam.d/vsftpd
userlist_enable=YES # FTP將檢查userlist_file(/etc/vsftpd/user_list)中用戶是否可以訪問FTP服務器
tcp_wrappers=YES # 使用tcp_wrappers作爲主機訪問控制方式,/etc/host.allow和/etc/hosts.deny。
chroot_list_enable=YES # 禁錮用戶在宿主目錄中
max_clients=100 # 限制客戶端的最大連接數
max_per_ip=5 # 同一ip與FTP服務器連接的最大連接數
local_max_rate=500000 # 本地用戶傳輸最大爲500KB/s
anon_max_rate=200000 # 匿名用戶傳輸最大爲200KB/s
[root@linux01 Server]#
ftp密碼用戶登錄方式
ftp://username:password@host:port可以以username爲用戶名,password爲密碼從端口port登錄到host
本文出自 “Gonglei Chen” 博客,轉載請與作者聯繫!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章