centos安裝vsftpd,部署ftp伺服器
Vsftp 安裝配置
1.檢視是否安裝vsftp
rpm –qa|grep vsftpd
如果出現 vsftpd-2.0.5-16.el5_5.1 說明已經安裝 vsftp
安裝vsftp
yum -y install vsftpd
2.測試 是否安裝成功 (ip 改成自己啊,不要用俺的此次登入為匿名登入 user: anonymous 密碼為空 如果成功登入會有下面內容 這說明vsftpd安裝成功)
[[email protected] ~]#service vsftpd start
為 vsftpd 啟動 vsftpd:[確定]
[[email protected] ~]#ftp 192.168.1.107
Connected to192.168.1.107.
220 (vsFTPd 2.0.5)
530 Please loginwith USER and PASS.
530 Please loginwith USER and PASS.
KERBEROS_V4 rejectedas an authentication type
Name(192.168.1.107:root): anonymous
331 Please specifythe password.
Password:
230 Loginsuccessful.
Remote system typeis UNIX.
Using binary mode totransfer files.
ftp> bye
221 Goodbye.
[
3.修改配置檔案/etc/vsftpd/vsftpd.conf
[[email protected] ~]#vi /etc/vsftpd/vsftpd.conf
取消下面內容前面的註釋或新增
anonymous_enable=YES/NO 是否允許匿名使用者訪問
chroot_list_enable=YES 限定使用者不可以離開主目錄
chroot_list_file=/etc/vsftpd/chroot_list
loca_enable=YES/NO 本地使用者是否可以訪問 注:如果為NO 則所有虛擬使用者都將不能訪問原因:虛擬使用者訪問在主機上其實是以本地使用者訪問的
pam_service_name=vsftpd pam認證檔名 在/etc/pam.d/vsftpd
guest_enable=YES 啟用虛擬使用者功能
guest_username=ftp 指定虛擬使用者的宿主使用者 –centos 裡面已經有內建的ftp使用者了(注:此使用者在chroot_list_file=/etc/vsftpd/chroot_list檔案裡所指定的使用者)
user_config_dir=/etc/vsftpd/vuser_conf 設定虛擬使用者個人vsftp的服務配置檔案
(此檔案後面不能出現空格)
4.檢視是否安裝 db4 db4-utils
[
db4-devel-4.3.29-10.el5_5.2
db4-4.3.29-10.el5_5.2
db4-devel-4.3.29-10.el5_5.2
db4-4.3.29-10.el5_5.2
db4-tcl-4.3.29-10.el5_5.2
db4-utils-4.3.29-10.el5_5.2
[[email protected] ~]#
如果沒安裝則要安裝db4-utils
4.1安裝db4-utils
[[email protected]
5. 建立 chroot_list_file=/etc/vsftpd/chroot_list檔案
[[email protected] ~]#vi /etc/vsftpd/chroot_list (編輯檔案把 /etc/vsftpd/vsftpd.conf 中guest_username的值寫到檔案中本例中為 ftp)
或者直接按下面進行操作
[[email protected] ~]#touch /etc/vsftpd/chroot_list
[[email protected] ~]# echoftp >> /etc/vsftpd/chroot_list (此處ftp 也要是/etc/vsftpd/vsftpd.conf中的guest_username的值)
6.建立虛擬使用者目錄(密碼文字)
[[email protected] ~]#vi /etc/vsftpd/vftpuser.txtx (奇數行為使用者名稱 ,偶數行為密碼)
本文中新增如下(用cat 命令檢視)
[[email protected] ~]#cat /etc/vsftpd/vftpuser.txtx
zz
aaaaa
ftp1
zzzzz
[[email protected] ~]#
7.生成虛擬使用者的db檔案
[[email protected] ~]#db_load -T -t hash -f /etc/vsftpd/vftpuser.txtx /etc/vsftpd/vftpuser.db
8.生成虛擬使用者的認證檔案
[[email protected]]# vi /etc/pam.d/vsftpd
#%PAM-1.0
session optional pam_keyinit.so force revoke
auth required pam_listfile.so item=user sense=denyfile=/etc/vsftpd/ftpusers onerr=succeed
auth required pam_shells.so
auth include system-auth
account include system-auth
session include system-auth
session required pam_loginuid.so
註釋掉/etc/pam.d/vsftpd中所有的內容 反正已經不要本地使用者的認證了
特別注意 以下區別
32位系統增加以下兩句:
auth required pam_userdb.so db=/etc/vsftpd/vftpuser
account required pam_userdb.so db=/etc/vsftpd/vftpuser
64位系統增加以下兩句:
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vftpuser
account required /lib64/security/pam_userdb.sodb=/etc/vsftpd/vftpuser
注:db=/etc/vsftpd/vftpuser 中的vftpuser 是你生成的虛擬使用者的db檔案
9.建立每個虛擬使用者自己的配置檔案,配置檔案的路徑是/etc/vsftpd/vsftpd.conf中的
user_config_dir=/etc/vsftpd/vuser_conf路徑
在 /etc/vsftpd/vuser_conf/下面建立以使用者名稱為名稱的檔案(名稱是/etc/vsftpd/vftpuser.txtx 下面的奇數行)
[[email protected]]# cat /etc/vsftpd/vftpuser.txtx
zz
aaaaa
ftp1
zzzzz
[[email protected]]# mkdir vuser_conf
[[email protected]]# vi /etc/vsftpd/vuser_conf/zz
內容如下
local_root=/var/www(虛擬使用者的根目錄根據實際修改)
write_enable=YES (可寫)
download_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
10.給文夾許可權(否則不能上傳 許可權可自定 本人給的是 777)
[[email protected]]# chmod 777 /var/www/
11.重啟vsftpd
[[email protected]]# service vsftpd restart
到此安裝配置完成 如果出現連線被 同位體重置 或其它錯誤 請檢視SELinux的當前模式
12.登入測試
[[email protected] vsftpd]# ftp192.168.1.107
Connected to 192.168.1.107.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as anauthentication type
Name (192.168.1.107:root): zz
331 Please specify the password.
Password:
500 OOPS: cannot changedirectory:/var/www
Login failed.
ftp>
檢視方法
[[email protected] vsftpd]# getenforce
Enforcing 如果出現(Enforcing )
關閉方法:[[email protected] vsftpd]#setenforce 0 (0|1 開|關)
再次測試 登入成功
[[email protected] vsftpd]# chmod 777/var/www/
[[email protected] vsftpd]# ftp192.168.1.107
Connected to 192.168.1.107.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as anauthentication type
Name (192.168.1.107:root): zz
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
檢視系統是多少位的命令
[[email protected] ~]# getconf LONG_BIT
64 (64|32)
1.檢視有沒有安裝vsftpd:
rpm -qa | grep vsftpd
2.yum安裝vsftpd:
yum install vsftpd
3.rpm安裝vsftpd:
安裝命令:
rpm -Uvh vsftpd-1.1.3-8.i386.rpm
4.設定每次開機時自動執行及手工啟動它:
chkconfig vsftpd on
service vsftpd start
netstat -tl 可以檢視ftp埠是否在偵聽了!
5.為vsftpd新增ftp賬號
用useradd建立的使用者,如果後面不加引數,建立的使用者為普通使用者,有系統登陸許可權,所以要在useradd命令後面加上引數,為虛擬主機新增不可以登入系統的ftp專用賬號,命令如下:
# useradd –s /sbin/nologin –d /var/www -g ftp ftpadmin
如果顯示如下資訊:
Creating mailbox file: File exists
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
表示使用者家目錄已經存在(/var/www),不可再新建此目錄,並非新增使用者失敗,接下來給使用者設定密碼,否則此賬號不能使用,命令如下:# passwd ftpadmin
這樣就為linux系統新增使用者ftpadmin,使用者目錄指定為/var/www,屬於ftp使用者組,且此使用者不能登陸系統。
注:
-s /sbin/nologin是讓其不能登陸系統
-d 是指定使用者目錄為/var/www
-g ftp 把使用者加入到ftp組中
修改/var/www目錄屬性:
$ chmod -R 777 /var/www 遞迴地給此目錄下所有檔案和子目錄的讀、寫、執行許可權
$ chgrp -R ftp /var/www 遞迴地把此目錄及該目錄下所有檔案和子目錄的組屬性設定成ftp組
6.配置etc/vsftpd/vsftpd.conf檔案:
nano -w /etc/vsftpd/vsftpd.conf
注:用nano編輯配置檔案要加引數“-w”,用於取消自動換行,否則有可能會出錯。
配置檔案範例:
# 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=NO
#
# 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
#
# Activate logging of uploads/downloads.
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
#
# 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
#
# 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
chroot_local_user=YES
userlist_enable=YES
tcp_wrappers=YES
注:此配置檔案僅在預設配置檔案基礎上修改為如下兩項:
anonymous_enable=NO #禁止匿名登入
chroot_local_user=YES #把系統內所有的FTP使用者都限制在家目錄中
7.檢視誰登陸了FTP,並殺死它的程序
ps –xf |grep ftp
kill 程序號
8.使vsftp下root登入:
1)編輯兩個FTP配置檔案:/etc/vsftpd.ftpusers和/etc/vsftpd.user_list,將root那一行刪掉或#註釋掉;
2)重啟vsftpd服務:
service vsftpd restart
設定虛擬目錄
# cd /var/ftp
# mkdir v1
# mount --bind /sourcedir /var/ftp/v1
# vi /etc/fstab
在最後增加一行:
/sourcedir /var/ftp/v1 none ro,bind 0 0 # /etc/init.d/vsftpd restart
架設ftp伺服器
1.安裝vsftp
在這裡,我們架設的是虛擬使用者,所謂虛擬使用者就是沒有使用真實的帳戶,只是通過某種手段達到對映帳戶和設定許可權的目的。
yum install vsftpd
touch /var/log/vsftpd.log #建立vsftp的日誌檔案
在CentOS中,這樣就可以完成了一個簡單的匿名FTP的搭建。你可以通過訪問ftp://yourip來進行,不過這個FTP沒有任何許可權。
2.啟動/重啟/關閉vsftpd伺服器
[[email protected] ftp]# /sbin/service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
OK表示重啟成功了.
啟動和關閉分別把restart改為start/stop即可.
如果是原始碼安裝的,到安裝資料夾下找到start.sh和shutdown.sh檔案,執行它們就可以了.
3.與vsftpd伺服器有關的檔案和資料夾
vsftpd伺服器的配置檔案的是: /etc/vsftpd/vsftpd.conf
vsftpd伺服器的根目錄,即FTP伺服器的主目錄:/var/ftp/pub
如果你想修改伺服器目錄的路徑,那麼你只要修改/var/ftp到別處就行了
4.新增FTP本地使用者(即虛擬使用者,簡單方案)
有的FTP伺服器需要使用者名稱和密碼才能登入,就是因為設定了FTP使用者和許可權.
FTP使用者一般是不能登入系統的,只能進入FTP伺服器自己的目錄中,這是為了安全.
這樣的使用者就叫做虛擬使用者了.實際上並不是真正的虛擬使用者,只是不能登入SHELL了而已,沒許可權登入系統.
/usr/sbin/adduser -d /opt/test_ftp -g ftp -s /sbin/nologin test
這個命令的意思是:
使用命令(adduser)新增test使用者,不能登入系統(-s /sbin/nologin),自己的資料夾在(-d /opt/test_ftp)),屬於組ftp(-g ftp)
然後你需要為它設定ftp登入密碼 passwd test
passwd test
Changing password for user test.
New UNIX password:
Changing password for user test.New UNIX password:
注意:這裡的密碼要求為字母和數字的組合才可以,如果不符合密碼驗證機制的話就修改不成功,會有各種報錯,“BAD PASSWORD: it's WAY too short”,這是報密碼太短,不符合/etc/login.defs的設定,“BAD PASSWORD: it is based on your username”,這是密碼與帳號不能同名,這是不符合/etc/pam.d/passwd的設定。“BAD PASSWORD: it is based on a dictionary word”這是因為出現了字典裡的字串,如果你英文與數字組合使用,就不會報錯。
----------------------------------------------------------------------------------------------------------
1)我們在/etc/vsftpd/vsftpd.conf中做如下CentOS FTP服務配置:(複雜方案)
anonymous_enable=NO 設定不允許匿名訪問
local_enable=YES 設定本地使用者可以訪問。注:如使用虛擬宿主使用者,在該專案設定為NO的情況下所有虛擬使用者將無法訪問。
chroot_list_enable=YES 使使用者不能離開主目錄
xferlog_file=/var/log/vsftpd.log 設定vsftpd的服務日誌儲存路徑。注意,該檔案預設不存在。必須要手動touch出來
ascii_upload_enable=YES
ascii_download_enable=YES 設定支援ASCII模式的上傳和下載功能。
pam_service_name=vsftpd PAM認證檔名。PAM將根據/etc/pam.d/vsftpd進行認證
以下這些是關於Vsftpd虛擬使用者支援的重要CentOS FTP服務配置專案。
預設vsftpd.conf中不包含這些設定專案,需要自己手動新增CentOS FTP服務配置。
guest_enable=YES 設定啟用虛擬使用者功能。
guest_username=ftp 指定虛擬使用者的宿主使用者。-CentOS中已經有內建的ftp使用者了
user_config_dir=/etc/vsftpd/vuser_conf 設定虛擬使用者個人vsftp的CentOS FTP服務檔案存放路徑。
存放虛擬使用者個性的CentOS FTP服務檔案(配置檔名=虛擬使用者名稱)
2)建立chroot list,將使用者ftp加入其中:
touch /etc/vsftpd/chroot_list
echo test >> /etc/vsftpd/chroot_list
3)進行認證(可以不認證):
首先,安裝Berkeley DB工具,很多人找不到db_load的問題就是沒有安裝這個包。
yum install db4 db4-utils
然後,建立使用者密碼文字/etc/vsftpd/vuser_passwd.txt ,注意奇行是使用者名稱,偶行是密碼
ftpuser1
ftppass1
ftpuser2
ftppass2
接著,.生成虛擬使用者認證的db檔案
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
隨後,編輯認證檔案/etc/pam.d/vsftpd,全部註釋掉原來語句
再增加以下兩句
auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd
account required pam_userdb.so db=/etc/vsftpd/vuser_passwd
最後,建立虛擬使用者個性CentOS FTP服務檔案
mkdir /etc/vsftpd/vuser_conf/
vi /etc/vsftpd/vuser_conf/ftpuser1
內容如下:
local_root=/opt/var/ftp1 虛擬使用者的根目錄(根據實際修改)
write_enable=YES 可寫
anon_umask=022 掩碼
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
-------------------------------------------------------------------------------------------------------------------------
5、常見錯誤:
安裝完以後,可能發現連線ftp伺服器,一般是由於SELinux的問題,原因如下:
他的系統是CentOS,是RH派系的。我把vsftpd安裝配置好了,以為大功告成,但客戶端訪問提示如下錯誤:
500 OOPS: cannot change directory:/home/ftp
原因是他的CentOS系統安裝了SELinux,因為預設下是沒有開啟FTP的支援,所以訪問時都被阻止了。
//檢視SELinux設定
# getsebool -a|grep ftp
ftpd_disable_trans --> off
ftp_home_dir-->off
//使用setsebool命令開啟
# setsebool ftpd_disable_trans 1
# setsebool ftp_home_dir 1
由於作業系統一旦重啟後,這種設定需要重新設定,這裡使用-P引數實現.
//setsebool使用-P引數,無需每次開機都輸入這個命令
# setsebool -P ftpd_disable_trans 1
# setsebool -P ftp_home_dir 1
//檢視當前狀態是否是on的狀態
# getsebool -a|grep ftp
ftpd_disable_trans --> on
ftp_home_dir-->on
# service vsftpd restart
有關selinux的配置
如關閉,僅僅警告,強制等等 需要編輯/etc/sysconfig/selinux 預設是強制。
1.553 Could not create file
一般都是SELinux的問題,設定SELinux的一個值,重啟伺服器即可。
setsebool -P ftpd_disable_trans 1
service vsftpd restart
2.500 OOPS: bad bool value in config file for: write_enable
注意你的CentOS FTP服務檔案中保證每一行最後沒有任何空格,一般出錯就是在多餘的空格上。
開啟/etc/selinux/config
將selinux=enforcing 改成 permissive 或 disabled。
•enforcing強制模式,只要SELinux不允許,就無法執行;
•permissive警告模式,將該事件記錄,依然允許執行;
•disabled關閉SELinux;
•停用、啟用需要重啟計算機;
•使用setenforce切換enforcing與permissive模式不需要重啟計算機;
•getenforce及sestatus檢視執行模式;
關閉selinux命令:setenforce 0
以前問過這個問題,朋友們說是LINUX的防火牆沒有關閉
請問在字元方式下如何關閉我LINUX上的防火牆?
yongpeng 我的FTP無法訪問提示ftp: connect :未知錯誤號
service iptables stop
or
/etc/rc.d/init.d/iptables stop
nios 我的FTP無法訪問提示ftp: connect :未知錯誤號
謝謝你了,
LINUX 預設會起這個防火牆嗎??
順便說一下剛才發現一個檢視服務的命令
/sbin/service --status-all
ftp:connect:未知錯誤號
可能的原因是ftp服務沒有真正啟動成功,可以做以下幾步
1、檢視兩臺機器間能否ping通
2、關閉防火牆:service iptables stop (也可以chkconfig iptables off 這樣啟動是就關閉了,其他服務類似)
3、檢視21埠,有沒有被其他暫用:netstat -ano | grep 21
如果被暫用,就修改ftp的預設埠
最近需要一個ftp,正好藉著正在學習centOS的機會配置一個vsftpd。
配置的過程中遇到了不少錯誤,這裡記錄下正確的完整的過程,以供大家分享。
首先下載vsftpd
yum install vsftpd,然後確認一下選項是都正確,按照下圖所示,特別是前三行,沒有的話手動新增。
可以現在如果你嘗試ftp的話還是不行,是因為你的pubs上傳資料夾的許可權不對。
新建資料夾在/var/ftp/目錄下,pubs
檢視他的許可權ls -l,如果不是下面的則使用chown ftp pubs 命令,修改許可權。 如果還是不行的話,那是因為你的SELINUX是開啟的,最簡單直接的辦法就是關閉SELINUX。 SELINUX的配置檔案位於/etc/selinux/config 將config檔案修改為
至此,基本已經完成。匿名 可上傳,可下載,可修改。
如果還是有問題的話,請檢視下你的防火牆是否阻止了。
只要輸入service iptables stop 關閉防火牆後,如果能開啟ftp了就說明防火牆阻止了。
可惜暫時不會修改防火牆的規則,先將就著把防火牆關了吧!!!!以後再補充!!!
還有就是提醒一點,vsftpd的根目錄的許可權是755,不可修改。
出於安全性的而考慮,根目錄下是不可以上傳檔案的,只能新建一個單獨的資料夾用於上傳。
同時在實際的配置中我發現,可以同時實現只能下載不能上傳和修改。
還是因為歸屬許可權的問題。
我新建一個資料夾,將其設定為
chown ftp downloadONLY
上傳一些常用的檔案,然後將其許可權設定回
chown root downloadONLY
這樣,就實現了只能匿名下載,而不能修改或上傳在這個目錄上,而不影響pubs可上傳同時可下載的目錄。
但是有一個問題是,不能管理員在系統內複製檔案到downloadONLY檔案件,因為這樣檔案的歸屬權就不是ftp了,就不能下載了。
只能下修改許可權,然後上傳,在把許可權改回來,從而只能實現匿名下載功能。