配置vsftp

一、安裝、測試

二、用戶類型

三、相關文件及配置

四、添加SSL安全驗證

五、ftp的端口號20、21有何區別


一、安裝、測試

1、安裝vsftp

[root@test3 ~]# yum install -y vsftpd

 

2、vsftp,安裝後,會自動創建一個名爲ftp的用戶,家目錄爲/var/ftp,這個家目錄就是ftp服務器端的文件路徑

[root@test3 pub]# finger ftp
Login: ftp            			Name: FTP User
Directory: /var/ftp                 	Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.

 

3、啓動ftp服務

[root@test3 ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]

 

4、另一臺主機上安裝客戶端ftp或lftp

[root@HTTP conf]# yum install -y ftp

 

5、連接測試,iptable沒有配置前,先關掉服務

[root@HTTP conf]# ftp 10.1.1.112    #ftp IP爲登錄命令
Connected to 10.1.1.112 (10.1.1.112).
220 (vsFTPd 2.2.2)    #協議響應碼220,說明服務器存在
Name (10.1.1.112:root): ftp    #root在此爲降權用戶,使用匿名用戶ftp即可
331 Please specify the password.    #協議響應碼331,輸入用戶名後,響應還未結束,需要輸入密碼
Password:    #匿名登錄時,密碼爲空或者ftp
230 Login successful.    #協議響應碼230,連接成功
Remote system type is UNIX.    
Using binary mode to transfer files.
ftp>

    安裝lftp,連接測試

[root@HTTP conf]# yum install -y lftp
[root@HTTP conf]# lftp ftp:@10.1.1.112    #使用這個格式,指定用戶名、密碼登陸指定的ftp服務器
lftp [email protected]:~>

 

6、連接ftp服務器時,可以看到有協議響應碼,意義如下

1xx:服務器信息

2xx:正確響應信息

3xx:正常響應,某操作過程尚未完成,需進一步補充完成

4xx:客戶端錯誤

5xx:服務器端錯誤

 

二、用戶類型

 

1、匿名用戶和本地用戶

登錄ftp服務器的用戶,都是ftp服務端linux系統的用戶,在vsftp中默認禁止root和uid小於500的用戶登錄,本地用戶登陸ftp服務器,處於自己的家目錄下,除了匿名用戶ftp登錄後,鎖定在/var/ftp,其他本地用戶可以隨意查看系統結構,而且ftp登錄信息是明文的,不安全,完全可以拿着本地用戶登錄linux

[root@test3 pub]# useradd jerry;echo jerry | passwd --stdin jerry
Changing password for user jerry.
passwd: all authentication tokens updated successfully.
[root@HTTP conf]# ftp 10.1.1.112    #使用jerry登錄
Connected to 10.1.1.112 (10.1.1.112).
220 (vsFTPd 2.2.2)
Name (10.1.1.112:root): jerry
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/jerry    #出現提示,這時因爲SELinux未配置,暫時關閉後重新嘗試連接
Login failed.
ftp> bye    #退出
[root@HTTP conf]# lftp jerry:[email protected]    #重新登錄
lftp [email protected]:~> pwd     
ftp://jerry:[email protected]/%2Fhome/jerry    #可以看出,用戶登錄後處於自己的家目錄下
lftp [email protected]:~>

本地用戶隨意瀏覽系統目錄

lftp [email protected]:~> cd /    #匿名用戶鎖死在自己家目錄下,但是本地用戶可以隨意切換所在目錄並瀏覽目錄結構、內容
cd ok, cwd=/
lftp [email protected]:/> ls
dr-xr-xr-x    2 0        0            4096 May 15 08:27 bin
dr-xr-xr-x    5 0        0            1024 May 15 08:28 boot
drwxr-xr-x   19 0        0            3740 May 15 08:31 dev
drwxr-xr-x   62 0        0            4096 May 15 09:30 etc
drwxr-xr-x    3 0        0            4096 May 15 09:30 home
dr-xr-xr-x    8 0        0            4096 May 15 08:27 lib
dr-xr-xr-x    9 0        0           12288 May 15 08:28 lib64
drwx------    2 0        0           16384 May 15 08:26 lost+found
drwxr-xr-x    2 0        0            4096 Sep 23  2011 media
drwxr-xr-x    2 0        0            4096 Sep 23  2011 mnt
drwxr-xr-x    2 0        0            4096 Sep 23  2011 opt
dr-xr-xr-x  104 0        0               0 May 15  2015 proc
dr-xr-x---    2 0        0            4096 May 15 09:18 root
dr-xr-xr-x    2 0        0           12288 May 15 08:28 sbin
drwxr-xr-x    7 0        0               0 May 15  2015 selinux
drwxr-xr-x    2 0        0            4096 Sep 23  2011 srv
drwxr-xr-x   13 0        0               0 May 15  2015 sys
drwxrwxrwt    3 0        0            4096 May 15 09:28 tmp
drwxr-xr-x   13 0        0            4096 May 15 08:26 usr
drwxr-xr-x   18 0        0            4096 May 15 08:48 var
lftp [email protected]:/>


2、虛擬用戶

虛擬用戶事實上也是服務器端自動映射的一個系統用戶,可以多個虛擬用戶同時被映射爲同一個系統用戶,不同的虛擬用戶可以具有不同的訪問權限,啓用虛擬用戶,需配置/etc/pam.d/vsftpd


三、相關文件及配置

服務腳本:/etc/rc.d/init.d/vsftpd

執行程序:/usr/sbin/vsftpd


------------------------------------------


主配置文件:/etc/vsftpd/vsftpd.conf

anonymous_enable=YES    是否支持匿名用戶登陸

local_enable=YES    是否支持本地用戶登陸

write_enable=YES    是否支持本地用戶上傳,上傳用客戶端用put命令

local_umask=022    遮罩碼,本地用戶上傳文件後,文件的權限

anon_upload_enable=YES    是否允許匿名用戶上傳文件,這項開啓後,匿名用戶可以上傳文件,但是系統目錄是沒有ftp用戶寫權限的,此時可以新建目錄,讓ftp用戶有權限寫,setfacl –m u:ftp:rwx upload/

anon_mkdir_write_enable=YES    匿名用戶是否可以創建目錄

anon_other_write_enable=YES    匿名用戶可以刪除文件,改文件的屬主、屬組

dirmessage_enable=YES    切換目錄有提示信息,當切換到的目錄中有.message文件的目錄時,會顯示.message文件中的文本信息

xferlog_enable=YES    啓用日誌功能,需要開啓指定日誌文件

xferlog_file=/var/log/xferlog    指定日誌文件  
--------------

是否啓用上傳文件後,更改文件屬主功能

chown_uploads=YES  
chown_username=whoever    #將whoever改爲用戶名

---------------

connect_from_port_20=YES    #服務器是否工作在主動模式下

xferlog_std_format=YES    日誌使用標準格式

idle_session_timeout=600    命令連接超時時間

data_connection_timeout=120    數據連接的超時時間  
-------------

是否使用ascii碼格式上傳下載

ascii_upload_enable=YES

ascii_download_enable=YES  
--------------  
ftpd_banner=Welcome to blah FTP service.    歡迎信息

--------------

1、chroot_local_user=YES    所有本地用戶登錄ftp後都禁錮在家目錄下

2、chroot_list_enable=YES    列表文件中的用戶登錄ftp後都禁錮在家目錄下

        (default follows)

     chroot_list_file=/etc/vsftpd/chroot_list

3、3項全啓用時,則禁錮不在列表中的用戶

---------------

ls_recurse_enable=YES    使用ls查看文件時,遞歸顯示所有文件

---------------

pam_service_name=vsftpd    pam服務的文件名爲vsftpd,/etc/pam.d/vsftpd

userlist_enable=YES    啓用用戶列表,/etc/vsftpd/ftpusers文件中的用戶都不允許登錄

tcp_wrappers=YES  
---------------

user_list文件中的用戶默認不能登錄ftp,但如果在主配置文件中加入配置選項userlist_deny=NO,則由黑名單變成白名單,文件中用戶可以登錄ftp

p_w_picpath

---------------

anon_max_rate=    匿名用戶的最大傳輸速率,單位爲字節

local_max_rate=    本地用戶的最大傳輸速率

---------------

不同用戶設置不同下載速率

user_config_dir=/etc/vsftpd/userconfs/    指定目錄,然後在目錄下創建和用戶同名的文件,在文件中設定local_max_rate=,即可

----------------

連接數限定

max_clients=    最多允許多少個連接請求

max_per_ip=    一個ip最多發起多少個連接請求

 

四、添加SSL安全驗證


1、生成私鑰並製作一個證書申請文件

[root@test3 CA]# openssl genrsa -des3 -out /root/testkey.pri 512    #生成私鑰
[root@test3 CA]# openssl req -new -key /root/testkey.pri -out /root/test.csr    #證書申請文件
Enter pass phrase for /root/testkey.pri:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:GuangDong      
Locality Name (eg, city) [Default City]:ShenZhen
Organization Name (eg, company) [Default Company Ltd]:www.test.com
Organizational Unit Name (eg, section) []:tech
Common Name (eg, your name or your server's hostname) []:www.test.com
Email Address []:[email protected]
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:                  
An optional company name []:


2、由CA負責簽署申請的證書

[root@test3 CA]# openssl ca -in /root/test.csr -out /root/test.crt -days 365


3、將下列配置信息添加有vsftpd的主配置文件/etc/vsftpd/vsftpd.conf中,將私鑰文件和證書文件保存到指定指定目錄

#SSL
ssl_enable=YES
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
rsa_cert_file=/etc/vsftpd/ssl/vsftpd.crt    #指定證書存放位置
rsa_private_key_file=/etc/vsftpd/ssl/vsftpd.key    #指定私鑰存放位置

 重新載入配置

[root@test3 vsftpd]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd: Enter PEM pass phrase:
                                                           [  OK  ]


這裏我們用windows中的FlashFXP軟件測試SSL連接FTP服務器,並抓包

tcpdump -i eth0 -XX port 21    #抓包命令,使用命令後監聽21號端口,再用軟件連接FTP服務器


下圖的抓包信息,看出登錄使用了SSL加密認證,且包中信息都不是明文

wKiom1VW8TLw_q1cAAXPhBDonDs736.jpg


五、ftp的端口號20、21有何區別

http://blog.sina.com.cn/s/blog_4fc68b7f0100g5r0.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章