FTP匿名用戶,系統用戶和虛擬用戶及lftp命令


一.ftp文件傳輸協議)介紹linux

1FTP鏈接及傳輸模式數據庫

FTP服務器默認使用TCP協議的2021端口與客戶機進行通訊。如:vim

20端口用於創建數據鏈接。並傳輸文件數據;windows

21端口用於創建控制鏈接,並傳輸FTP控制命令。安全


2.ftp的兩種工做模式服務器

1主動模式PORT當客戶端主動鏈接時,客戶端向服務器的FTP端口(默認是21)發送鏈接請求,服務器接收鏈接,創建一條命令鏈路。當須要傳送數據時,客戶端以PORT命令告知服務器我打開了某端口>1024,你來鏈接我,因而服務器從20端口向客戶端的該端口發送請求並創建數據鏈接。多線程


(2)被動模式(PASV)當客戶端被動鏈接時,客戶端向服務器的FTP端口(默認是21)發送鏈接請求,服務器接收鏈接,創建一條命令鏈路。當須要傳輸數據時,服務器告知客戶端我打開了某端口,你來鏈接我。因而客戶端向服務器的該端口發送請求並創建數據鏈接。併發

3.FTP用戶服務類型:app

1匿名用戶:tcp

  anonymous或ftp

2本地用戶:

  帳號名稱、密碼等信息保存在passwd、shadow文件中

3虛擬用戶:

使用獨立的帳號和密碼數據文

4.ftp的主配置文件

listen=YSE                  是否監聽服務

listen_address=0.0.0.0         FTP服務的IP地址

listen_port=21                FTP服務的端口號

write_enable=YES            寫入權限

download_enable=YES        是否容許下載

dirmessage_enable=YSE     用戶切換進入目錄是顯示.message(若是存在)文件的內容

xferlog_enable=YES          啓用xferlog日誌,默認記錄到「/var/log/xferlog」

xferlog_std_format=YES       啓用xferlog標準日誌格式

connect_from_port_20=YES 容許服務器主動模式(從20端口創建數據鏈接)

pasv_enable=YES             容許被動模式鏈接

pasv_max_port=24600          服務器最大端口

pasv_min_port=24500          服務器最小端口

pam_service_name=vsftpd   用於用戶認證的PAM文件位置

userlist_enable=YES             suer_list用戶類表文件

userlist_deny=YES              ser_list列表文件中的用戶帳號

max_clients=0                  最多容許多少個客戶端同時鏈接(0無限制)

max_per_ip=0                  最多容許多少個併發鏈接(0無限制)

tcp_wrappers=YES              是否啓用TCP_Wrappers主機訪問控制


二.具體配置

(1)匿名用戶

@1.ftp服務器默認就支持匿名用戶,下載好包,啓動服務就能夠了

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

[root@tx1 ~]# vim /etc/vsftpd/vsftpd.conf

anonymous_enable=YES啓用匿名訪問

local_umask=022                 匿名用戶上傳文件權限的掩碼

anon_upload_enable=YES          容許上傳文件

anon_mkdir_write_enable=YES     容許建立目錄

[root@tx1 ~]# service vsftpd restart

Shutting down vsftpd:                                      [FAILED]

Starting vsftpd for vsftpd:                                [  OK  ]

複製一些文件供用戶下載

[root@tx1 default]# cp /etc/passwd /var/ftp/

[root@tx1 default]# cp /etc/group /var/ftp/

[root@tx1 default]# cp /etc/fstab /var/ftp/


@2.客戶端測試

[root@tx2 ~]# ftp 192.168.8.70

Connected to 192.168.8.70.

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.8.70:root): ftp//匿名用戶的用戶名

331 Please specify the password.

Password://這裏不用輸入密碼

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls//查看服務器的文件

227 Entering Passive Mode (192,168,8,70,33,125)

150 Here comes the directory listing.

-rw-r--r--    1 0        0             608 Jul 23 02:50 fstab

-rw-r--r--    1 0        0             631 Jul 23 02:50 group

-rw-r--r--    1 0        0            1595 Jul 23 02:50 passwd

drwxr-xr-x    2 0        0            4096 Dec 05  2011 pub

226 Directory send OK.

客戶端下載

ftp> ls

227 Entering Passive Mode (192,168,8,70,51,26)

150 Here comes the directory listing.

-rw-r--r--    1 0        0             608 Jul 23 02:50 fstab

-rw-r--r--    1 0        0             631 Jul 23 02:50 group

-rw-r--r--    1 0        0            1595 Jul 23 02:50 passwd

drwxr-xr-x    2 0        0            4096 Dec 05  2011 pub

226 Directory send OK.

ftp> lcd ///改變本地目錄

Local directory now /

ftp> get fstab//下載文件

local: fstab remote: fstab

227 Entering Passive Mode (192,168,8,70,35,55)

150 Opening BINARY mode data connection for fstab (608 bytes).

226 File send OK.

608 bytes received in 0.00014 seconds (4.2e+03 Kbytes/s)

ftp> quit//t退出

221 Goodbye.

[root@tx2 /]# ls//fstab文件已下載

bin   dev  fstab  lib         media  mnt  opt   root  selinux  sys       tmp  var

boot  etc  home   lost+found  misc   net  proc  sbin  srv      tftpboot  usr

客戶端上傳

ftp> cd pub

250 Directory successfully changed.

ftp> ls

227 Entering Passive Mode (192,168,8,70,148,26)

150 Here comes the directory listing.

226 Directory send OK.

ftp> put fstab

local: fstab remote: fstab

227 Entering Passive Mode (192,168,8,70,180,30)

553 Could not create file.//錯誤!!!

解決辦法

 服務端

[root@tx1 ~]# cd /var/ftp/

[root@tx1 ftp]# ll

total 16

-rw-r--r-- 1 root root  608 Jul 23 10:50 fstab

-rw-r--r-- 1 root root  631 Jul 23 10:50 group

-rw-r--r-- 1 root root 1595 Jul 23 10:50 passwd

drwxr-xr-x 2 root root 4096 Dec  5  2011 pub

[root@tx1 ftp]# chmod 757 pub/

客戶端測試

ftp> cd pub

250 Directory successfully changed.

ftp> put fstab

local: fstab remote: fstab

227 Entering Passive Mode (192,168,8,70,32,246)

553 Could not create file.

ftp> put fstab

local: fstab remote: fstab

227 Entering Passive Mode (192,168,8,70,188,161)

150 Ok to send data.

226 File receive OK.

608 bytes sent in 9.8e-05 seconds (6.1e+03 Kbytes/s)

ftp> lcd /etc

Local directory now /etc

ftp> put inittab

local: inittab remote: inittab

227 Entering Passive Mode (192,168,8,70,187,201)

150 Ok to send data.

226 File receive OK.

1666 bytes sent in 0.00036 seconds (4.5e+03 Kbytes/s)

注:不能上傳和之後文件名相同的文件!!!


(2)系統用戶

@1.服務器添加用戶:

[root@tx1 ~]# useradd f1

[root@tx1 ~]# passwd f1

@2.配置文件

12#anonymous_enable=YES啓用匿名訪問要註釋掉

15 local_enable=YES

18 write_enable=YES

22 local_umask=022

[root@tx1 ~]# service vsftpd restart

Shutting down vsftpd:                                      [  OK  ]

Starting vsftpd for vsftpd:                                [  OK  ]


下載:使用系統用戶,下載的時候,只要服務器上有文件就能夠;下載文件以後,保存在鏈接以前所在的目錄,若是使用lcd切換以後,保存在切換後的目錄裏。

上傳:上傳的時候,不須要做任何修改,由於我是向本身的家目錄裏面傳輸文件

(和上面基本上相同,這裏就不作演示了.................

問題:使用f1這種用戶鏈接了服務器以後,可以在服務器上隨意的切換目錄,對服務器來講,這樣不安全!!!


解決:讓f1這種用戶鏈接以後,只在本身的家目錄裏面待着。禁錮普通用戶

[root@tx1 ~]# vim /etc/vsftpd/vsftpd.conf

96 chroot_list_enable=YES

98 chroot_list_file=/etc/vsftpd/chroot_list   保存着被禁錮的用戶

[root@tx1 vsftpd]# echo f1 > chroot_list  (寫用戶名的時候要一行一個)


三.虛擬用戶

1    在vsftpd服務器中,使用虛擬用戶的主要好處在於,能夠將登陸的帳號與系統登陸的帳號區分開來,用戶名,密碼都不相同,從而進一步加強了FTP服務器的安全性。另外虛擬用戶都具備獨立的配置選項。能夠靈活的控制對ftp服務器的訪問。能夠控制用戶讀的權限寫權限下載,上傳的權限

(2)具體配置

@1.建立一個保存虛擬用戶信息的文件:

[root@tx1 vsftpd]# vim login.txt

v1  用戶名

123 密碼


@2.把這個文件轉換成數據庫文件

[root@tx1 vsftpd]# yum install -y db4-utils

[root@tx1 vsftpd]# db_load -T -t hash -f login.txt vsftpd_login.db

-T轉換成數據庫格式

-t hash 轉換的格式-hash

-f指定原文件


@3.編寫ftp虛擬用戶須要的新的pam文件及配置文件

[root@tx1 vsftpd]# vim /etc/pam.d/vsftpd.v

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@tx1 vsftpd]#  vim vsftpd.conf

pam_service_name=vsftpd.v使用新的pam驗證文件

guest_enable=YES支持虛擬用戶

guest_username=vv使用的系統用戶是vv

user_config_dir=/etc/vsftpd/vuser保存虛擬用戶的配置文件的目錄


[root@tx1 vsftpd]# mkdir vuser

[root@tx1 vsftpd]# cd vuser

[root@tx1 vuser]# vim v1

anon_world_readable_only=NO全局只讀,可以瀏覽

anon_upload_enable=YES容許上傳

anon_mkdir_write_enable=YES容許建立目錄

anon_other_write_enable=YES容許修改文件名

local_root=/var/ftp/pub登陸的目錄

注:(vsftpd服務中,虛擬用戶被默認做爲匿名用戶進行處理以下降權限,所以對應的配置項一般以anon_開頭。
[root@tx1 vuser]# service vsftpd restart

Shutting down vsftpd:                                      [  OK  ]

Starting vsftpd for vsftpd:                                [  OK  ]

測試:

[root@tx2 ftp]# ftp 192.168.8.70

Connected to 192.168.8.70.

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.8.70:root): v1

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls

227 Entering Passive Mode (192,168,8,70,126,242)

150 Here comes the directory listing.

-rw-------    1 14       50            608 Jul 23 03:39 fstab

-rw-------    1 14       50           1666 Jul 23 03:39 inittab

226 Directory send OK.

(3)訪問控制

@1.ftpusers

要把配置文件恢復到配置虛擬用戶以前的狀態 這個文件,只要用戶寫進去就不容許訪問ftp。一行一個用戶名

@2.user_list

[root@tx1 vsftpd]# vim vsftpd.conf

userlist_enable=YES

這個文件,只要用戶寫進去就不容許訪問ftp。一行一個用戶名

userlist_enable=NO 取消限制


@3.tcp_wrappers=YES  支持tcp_wrappers 訪問控制

/etc/hosts.allow

/etc/hosts.deny


[root@tx1 vsftpd]# vim /etc/hosts.deny

vsftpd:192.168.8.20    把你要拒絕訪問的客戶端ip或網段寫進去就好了。


四.lftp命令

1.. 登錄:lftp -u test 192.168.0.1 -p 2121
-u  登錄用的用戶名
-p  ftp的端口,標準21端口能夠省略
get test.txt         下載單個文件  
     mget *.txt           下載多個文件
     put test.txt         上傳單個文件
     mput *.txt           上傳多個文件
     mirror test          下載目錄
     mirror -R test       上傳目錄
     pget -n 10 test.bin  多線程下載文件

2. 匿名用戶:

(1)lftp


[root@tx2 vsftpd]# lftp 192.168.8.70

支持tab補齊


(2)mget * 同時下載多個文件


ftp> prompt off  關掉提示

ftp> mget *



@1.匿名用戶:

[root@tx2 vsftpd]# wget ftp://172.16.1.2:21/* --ftp-user=ftp -r


@2.普通用戶:

[root@mail vsftpd]# wget ftp://172.16.1.2:21/* --ftp-user=f1 --ftp-password=123 -r

windows下也可使用ftp傳輸文件。


@3.windows下也可使用ftp傳輸文件。

ftp://server_ip

相關文章
相關標籤/搜索