天天看點

linux ftp 服務配置

1 FTP服務搭建環境

server端:

CentOS release 6.8 (Final)

ip 192.168.91.3

hostname:Darren

client端:

CentOS release 6.6 (Final)

ip 192.168.91.5

hostname:zhishutang

2 server端安裝vsftpd服務

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

[root@Darren packages]# rpm -qa vsftpd

vsftpd-2.2.2-21.el6.x86_64  

[root@Darren ~]# chkconfig --level 2345 vsftpd on

[root@Darren ~]# /etc/init.d/vsftpd restart

#ftp服務預設為21端口

[root@Darren ~]# netstat -nltup |grep vsftp       

tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      20334/vsftpd  

[root@Darren ~]# ps -ef |grep vsftp

root      20334      1  0 12:42 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

3 client端安裝ftp用戶端

[root@Darren packages]# yum -y install ftp

[root@zhishutang ~]# rpm -qa ftp

ftp-0.17-54.el6.x86_64

4 常用指令解析

[root@Darren home]# useradd user3    --在server端建立一個測試使用者user3

[root@zhishutang ~]# ftp   --在client端登陸

ftp> open 192.168.91.3    --用open指定server端IP位址

Connected to 192.168.91.3 (192.168.91.3).

220 (vsFTPd 2.2.2)

Name (192.168.91.3:root): user3    --輸入使用者名

331 Please specify the password.

Password:                                      --輸入密碼

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> help                                       --檢視幫助,顯示所有ftp指令

Commands may be abbreviated.  Commands are:

!               debug           mdir            sendport        site

$               dir             mget            put             size

account         disconnect      mkdir           pwd             status

append          exit            mls             quit            struct

ascii           form            mode            quote           system

bell            get             modtime         recv            sunique

binary          glob            mput            reget           tenex

bye             hash            newer           rstatus         tick

case            help            nmap            rhelp           trace

cd              idle            nlist           rename          type

cdup            image           ntrans          reset           user

chmod           lcd             open            restart         umask

close           ls              prompt          rmdir           verbose

cr              macdef          passive         runique         ?

delete          mdelete         proxy           send

ftp> close  --斷開用戶端和服務端ftp連接配接,不退出ftp的shell

500 OOPS: vsf_sysutil_recv_peek: no data

ftp> disconnect   --同close功能相同

221 Goodbye.

ftp> open 192.168.91.3 21  --指定IP位址和端口,如果為預設端口21,可不指定

ftp> bye    --斷開用戶端和服務端ftp連接配接,并退出ftp的shell(功能同quit和!)

幫助指令:? help  rhelp

ftp> ascii       

200 Switching to ASCII mode.

ftp> binary

200 Switching to Binary mode.

切換響鈴以在每個檔案傳送指令完成後響鈴。預設情況下,鈴聲是關閉的。

ftp> bell

Bell mode on.

Bell mode off.

ftp> cd /tmp  --切換遠端服務端目錄

250 Directory successfully changed.

ftp> cdup   --跳到上一層目錄

ftp> pwd    --顯示遠端服務端的目錄

257 "/"

ftp> lcd /tmp   --指定更改的本地計算機上的目錄

Local directory now /tmp

ftp>ls       --顯示遠端服務端目錄檔案和子目錄

ftp> dir     --顯示遠端服務端目錄檔案和子目錄

ftp> size /tmp/root.txt   --顯示遠端服務端檔案的大小12922KB

213 12922

ftp> mkdir /tmp/ftpdir   --建立遠端服務端文目錄

257 "/tmp/ftpdir" created

ftp> rmdir /tmp/ftpdir   --删除遠端服務端文目錄

250 Remove directory operation successful.

ftp> rename /tmp/file /tmp/fileuser3    --修改遠端服務端檔案名

350 Ready for RNTO.

250 Rename successful.

ftp> chmod 755 /tmp/fileuser3   --修改遠端服務端檔案權限

200 SITE CHMOD command ok.

ftp> modtime fileuser3   --顯示遠端伺服器上的檔案的最後修改時間

fileuser3       11/15/2016 08:12:21 GMT

ftp> append /home/file /tmp/file    --将本地檔案上傳到遠端計算機上的檔案

local: /home/file remote: /tmp/file

227 Entering Passive Mode (192,168,91,3,113,93).

150 Ok to send data.

226 Transfer complete.

ftp> send /home/file /tmp/file        --将本地檔案上傳到遠端計算機上的檔案

227 Entering Passive Mode (192,168,91,3,99,109).

ftp> put /home/file /tmp/file     --将本地檔案上傳到遠端計算機上的檔案

227 Entering Passive Mode (192,168,91,3,56,26).

local: /tmp/file remote: /tmp/file   ----将遠端計算機上的檔案 下載下傳到本地檔案

227 Entering Passive Mode (192,168,91,3,62,156).

150 Opening BINARY mode data connection for /tmp/file (0 bytes).

ftp> recv /tmp/file /tmp/file      ----将遠端計算機上的檔案下載下傳到本地檔案

local: /tmp/file remote: /tmp/file

227 Entering Passive Mode (192,168,91,3,139,114).

ftp> delete /tmp/file    --删除遠端計算機上的檔案

250 Delete operation successful.

ftp> umask    

200 Your current UMASK is 022

ftp>prompt  --切換交談式指令(使用mput/mget 時不用每個檔案皆詢問yes/no)

指令太多,不一一示範。

5 ftp配置檔案說明

/etc/vsftpd/ ftpusers    --這個檔案中的使用者預設不能登入ftp

/etc/vsftpd/user_list     --如果在配置檔案/etc/vsftpd/vsftpd.conf中userlist_deny=YES (預設),這個檔案/etc/vsftpd/user_list中的          使用者不能登入FTP,如果userlist_deny=NO,這個檔案/etc/vsftpd/user_list中的使用者能登入FTP,

/etc/vsftpd/vsftpd.conf   --主要配置檔案

例如:預設情況root是不能登入FTP的,這裡修改配置檔案,使root使用者可用

[root@Darren vsftpd]# vim /etc/vsftpd/ftpusers

#root  --注釋root使用者

[root@Darren vsftpd]# vim /etc/vsftpd/user_list

6 主要配置檔案 /etc/vsftpd/vsftpd.conf  

由于這個檔案比較重要,這裡單獨分析

#################本地使用者權限控制###############

# 允許本地使用者登入

 local_enable=YES

 # 本地使用者的寫權限

 write_enable=YES

 # 使用FTP的本地檔案權限,預設為077

 # 一般設定為022

 local_umask=022

 # 切換目錄時

 # 是否顯示目錄下.message的内容

 dirmessage_enable=YES

 dirlist_enable = NO

 #驗證方式

 #pam_service_name=vsftpd

 # 啟用FTP資料端口的資料連接配接

 connect_from_port_20=YES

 # 以獨立的FTP服務運作

 listen=yes

 # 修改連接配接端口

 #listen_port=2121

######### 匿名登入設定 ###########

 # 允許匿名登入

 anonymous_enable=NO

 # 如果允許匿名登入

 # 是否開啟匿名上傳權限

 #anon_upload_enable=YES

 # 是否允許匿名建立檔案夾并在檔案夾内上傳檔案

 #anon_mkdir_write_enable=YES

 # 匿名帳号可以有删除的權限

 #anon_other_write_enable=yes

 # 匿名的下載下傳權限

 # 匿名為Other,可設定目錄/檔案屬性控制

 #anon_world_readable_only=no

 # 限制匿名使用者傳輸速率,機關bite

 #anon_max_rate=30000

 ######### 使用者限制設定 ###########

 #### 限制登入

 # 用userlist來限制使用者通路

 #userlist_enable=yes

 # 名單中的人不允許通路

 #userlist_deny=no

 # 限制名單檔案放置的路徑

 #userlist_file=/etc/vsftpd/userlist_deny.chroot

 #### 限制目錄

 # 限制所有使用者都在家目錄

 #chroot_local_user=yes

 # 調用限制在家目錄的使用者名單

 chroot_list_enable=YES

 # 限制在家目錄的使用者名單所在路徑

 chroot_list_file=/etc/vsftpd/chroot_list

 ######### 日志設定 ###########

 # 日志檔案路徑設定

 xferlog_file=/var/log/vsftpd.log

 # 激活上傳/下載下傳的日志

 xferlog_enable=YES

 # 使用标準的日志格式

 #xferlog_std_format=YES

 ######### 安全設定 ###########

 # 使用者空閑逾時,機關秒

 #idle_session_timeout=600

 # 資料連接配接空閑逾時,機關秒

 #data_connection_timeout=120

 # 将用戶端空閑1分鐘後斷開

 #accept_timeout=60

 # 中斷1分鐘後重新連接配接

 #connect_timeout=60

 # 本地使用者傳輸速率,機關bite

 #local_max_rate=50000

 # FTP的最大連接配接數

 #max_clients=200

 # 每IP的最大連接配接數

 #max_per_ip=5

 ######### 被動模式設定 ###########

 # 是否開戶被動模式

 pasv_enable=yes

 # 被動模式最小端口

 pasv_min_port=5000

 # 被動模式最大端口

 pasv_max_port=6000

 ######### 其他設定 ###########

 # 歡迎資訊

 ftpd_banner=Welcome to Ftp Server!

7 配置匿名FTP

修改配置檔案:

[root@Darren ftp]# vim /etc/vsftpd/vsftpd.conf

anonymous_enable=YES

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_root=/var/ftp/

其他參數預設不變

ftp是系統使用者:

[root@Darren vsftpd]# cat /etc/passwd|grep ftp

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

[root@zhishutang ~]# ftp

ftp> open 192.168.91.3

Name (192.168.91.3:root): ftp      --使用ftp使用者

Password:          --無密碼,直接回車即可

ftp> pwd

257 "/"  

ftp> ls

227 Entering Passive Mode (192,168,91,3,203,117).

150 Here comes the directory listing.

drwxr-xr-x    2 0        0            4096 Nov 15 10:38 anon

-rw-r--r--    1 14       0               0 Nov 15 11:36 file1

-rw-r--r--    1 0        0               0 Nov 15 11:47 file2

drwxr-xr-x    2 14       0            4096 May 11  2016 pub

226 Directory send OK.

ftp> get /file1 /tmp/file1    --下載下傳檔案file1

local: /tmp/file1 remote: /file1

227 Entering Passive Mode (192,168,91,3,196,32).

150 Opening BINARY mode data connection for /file1 (0 bytes).

本文轉自 Darren_Chen 51CTO部落格,原文連結:http://blog.51cto.com/darrenmemos/1873414,如需轉載請自行聯系原作者

繼續閱讀