1. 程式人生 > >linux下的ftp伺服器的搭載(檔案伺服器2)

linux下的ftp伺服器的搭載(檔案伺服器2)

1.ftp全稱為檔案傳輸協議

      利用ftp可以給使用者提供上傳和下載的檔案服務

     採用的是客戶機/伺服器模式

     控制連結:是埠21,用於命令的

     資料連線:是埠20,用於下載和傳輸的

     資料鏈接的建立型別:

     主動模式:是客戶端請求連結,伺服器開啟資料鏈接埠20

     被動模式:是客戶機請求連結,客戶機開啟資料鏈接埠

3.ftp的主動模式:

               客戶端代開大於1024埠請求ftp的21埠進行控制連線,客戶端給伺服器的21埠傳送port命令通告自己代開了1100埠(動態生成)

                伺服器段的20埠打開了資料鏈接

4.ftp的被動模式

                客戶機隨機生成埠與伺服器的21埠建立控制連結,客戶段給伺服器段21埠發動pasv命令通告自己要用被動模式與伺服器通訊

                 服務埠告訴客戶機將開啟一個固定埠,客戶機與這個固定埠進行連結。

常見的ftp伺服器程式

lls,serv-u

wu-ftpd。proftpd

vsftpd(very secure ftp daemon)最常用

常見的ftp客戶端程式

vsftpd軟體包(官網上下載)

5.ftp使用者的型別

      匿名使用者:ftp,anonymouse(許可權比較小)

     本地使用者:p 帳號名稱,密碼等資訊儲存在passwd,shadow

      虛擬使用者:p 使用獨立帳號/密碼的資料檔案

6.預設的ftp伺服器的功能

      匿名用可以下載不可長傳,不能切換到根目錄

      本地使用者可以上傳此奧在,可以切換到根目錄,預設是可以切換到家目錄之外的檔案。

7.配置檔案/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                                           本地許可權掩碼    

#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                      主動連結的埠為20
#
# 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.
#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 with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd                              這個是pan模組的名字, 我們放置在這個目錄裡面
userlist_enable=YES
tcp_wrappers=YES

6.常用的ftp命令

--verbose顯示詳細資訊

--reverse上傳檔案

7。設定ftp的配置檔案

 匿名使用者的基本設定
   anonymous_enable=YES      \\允許匿名使用者下載檔案
   anon_upload_enable=YES    \\允許匿名使用者上傳檔案,但在伺服器的檔案系統中必須具有寫入的許可權
   anon_mkdir_write_enable=YES  \\允許匿名使用者建立目錄
   anon_other_write_ebale=YES   \\匿名使用者可以刪除檔案
   anon_max_rate=10240          \\設定匿名使用者的最大傳輸速率,單位為位元組
   
   本地使用者的限制設定
   local_root=/var/ftp/sxjy     \\限制本地使用者的登入目錄
   chroot_local_user=YES        \\是否將本地所有使用者限制在家目錄下
   chroot_list_enable=YES       \\啟用使用者列表
   chroot_list_file=/etc/vsftpd/chroot_list    //將本地使用者限制在家目錄裡面,不能出去/檔案是手動建立的
   
   userlist_enable=YES          \\是否啟用/etc/vsftpd/user_list檔案
   userlist_deny=YES            \\對於/etc/vsftpd/user_list檔案裡面的使用者是允許或拒絕登入

8.在linux中新增ftp使用者,並設定相應的許可權

(1)、被限制使用者名稱為user。

               被限制路徑為/home/user

(2)、建使用者,命令列狀態下,在root使用者下:

         命令:“useradd -d /home/user user”  //增加使用者user,並制定user使用者的主目錄為/home/user

                       passwd user  設定密碼,執行後輸入兩次相同密碼

(3)、更改使用者相應的許可權設定:

           命令:“usermod -s /sbin/nologin user”  //限定使用者test不能telnet,只能ftp

           命令:“usermod -s /sbin/bash user  //使用者test恢復正常

 (4)、限制使用者只能訪問/home/test,不能訪問其他路徑

                修改/etc/vsftpd/vsftpd.conf如下:

           chroot_list_enable=YES   //限制匿名使用者訪問自身目錄 
            # (default follows)
            chroot_list_file=/etc/vsftpd/vsftpd.chroot_list     //vsftpd.chroot_list只要使用者在這個檔案裡九限制了使用者只能訪問家目錄

    編輯上面的內容

    第一行:chroot_list_enable=YES  //限制訪問自身目錄

    第三行:編輯vsftpd.chroot_list。根據第三行說指定的目錄,找到chroot_list檔案。(因主機不同,檔名也許略有不同)

    編輯vsftpd.chroot_list,將受限制的使用者新增進去,每個使用者名稱一行

(5)重啟伺服器

    改完配置檔案,不要忘記重啟vsFTPd伺服器

    執行命令:/etc/init.d/vsftpd restart

(6)、如果需要允許使用者修改密碼,但是又沒有telnet登入系統的許可權:

    執行命令:“usermod -s /usr/bin/passwd test”  //使用者telnet後將直接進入改密介面

8.安全限制配置

max_clients=2   //最大連結數

max_login_fails=3   //允許數輸入密碼次數,超出就會鎖定

max_per_ip=5   //限制使用者下載量

pasv_max_port=65000 //被動模式的時候,限制動態的埠

--------------------------------------------------------------------------------常見錯誤--------------------------------------------------------------


1.[root@localhost ~]# ftp 192.168.73.128
ftp: connect: 沒有到主機的路由
ftp> 

解決方法:iptables防火牆沒有設定 開放21埠規則,同理於23埠等其他埠。

檢視埠是 netstat -anpul

[root@localhost ~]# iptables -A INPUT -p tcp  --dport 21

[root@localhost ~]# service iptables restart
iptables:清除防火牆規則:                                                          [確定]
iptables:將鏈設定為政策 ACCEPT:nat mangle filter            [確定]
iptables:正在解除安裝模組:                                                              [確定]
2.伺服器的檔案許可權是不能為7的 ,也就是所有許可權都是可用的,這樣會導致檔案不能使用的。