簡介:
vsftpd是“very secure FTP daemon”的縮寫,是一個完全免費的、開放源代碼的ftp服務器軟件。
工作原理:
vsftpd使用ftp協議,該協議屬於應用層協議。它是典型的c/s架構,ftp服務端用來存儲文件,ftp客戶端可以通過ftp協議連接服務端實現上傳和下載資源。
ftp使用tcp的21端口進行命令傳輸,然后用tcp的20端口進行數據傳輸(主動模式)。
特點:
非常高的安全性需求、帶寬限制、良好的可伸縮性等。
安裝部署:
yum install vsftpd ftp lftp -y
PS:
vsftpd為服務端軟件;ftp、lftp為客戶端工具,推薦使用lftp。
部署詳情可參照《如何在Centos服務器上搭建起Oracle10、VNC、以及FTP》
啟動服務:
service vsftpd start
systemctl start vsftpd
查看狀態:
service vsftpd status
systemctl status vsftpd
用戶登錄:
- 用本地用戶登錄需要輸入用戶名及密碼驗證。
- 用ftp客戶端匿名登錄需要輸入用戶名及密碼驗證,匿名用戶名為:ftp或者anonymous,密碼為空。
- 用lftp客戶端匿名登錄則不需要輸入以上信息。
本地用戶登錄:
[root@TEST ~]# ftp
ftp> open 8.8.8.8
Connected to 8.8.8.8 (8.8.8.8).
220 (vsFTPd 2.2.2)
Name (8.8.8.8:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
登錄失敗時:
[root@TEST ~]# ftp 8.8.8.8
Connected to 8.8.8.8 (8.8.8.8).
220 (vsFTPd 2.2.2)
Name (8.8.8.8:root): root
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> close
221 Goodbye.
ftp> open 8.8.8.8
Connected to 8.8.8.8 (8.8.8.8).
220 (vsFTPd 2.2.2)
Name (8.8.8.8:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp客戶端匿名登錄:
[root@TEST ~]# ftp 8.8.8.8
Connected to 8.8.8.8 (8.8.8.8).
220 (vsFTPd 2.2.2)
Name (8.8.8.8:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
lftp客戶端連接:
[root@TEST ~]# lftp 8.8.8.8
lftp 8.8.8.8:~>
下載命令:
get用於下載單個文件:
可以先切換到**本地指定目錄**(data)進行文件的下載,保存:
ftp> lcd /data1/
Local directory now /data1
ftp> cd /data2/
ftp> get file001.txt
ps:
當客戶端已經連接上服務端,cd
是用於切換服務器中的目錄命令,lcd
是用於切換客戶端本地的目錄。
mget用於批量下載:
ftp> mget file00*
Total 7 files transferred
上傳命令:
put用於下載單個文件:
要想使用上傳命令,需要開啟上傳權限和可寫權限,可往下看。
直接上傳不改名,可以省去-o refile:
ftp> !dir
file001.txt file002.txt
ftp> bin
421 Timeout.
ftp> put /etc/file003.txt
501 bytes transferred
ftp> !dir
file001.txt file002.txt file003.txt
PS:
如果不知道本地目錄有哪些文件,可以使用!dir
查看;
而且,一定要使用bin二進制傳輸!!!
上傳文件之后,並改名,就要帶-o refile了:
ftp> bin
421 Timeout.
ftp> put /etc/file003.txt -o file004.txt
501 bytes transferred
ftp> ls
drwx------ 2 14 50 6 Aug 08 06:27 file001.txt
-rw------- 1 14 50 501 Aug 08 06:34 file002.txt
-rw------- 1 14 50 501 Aug 08 06:34 file003.txt
-rw------- 1 14 50 501 Aug 08 06:34 file004.txt
mput用於批量上傳:
上傳多個文件,可以使用put
和mput
命令上傳,多個文件之間用空格分隔;
如果想使用通配符,只有mput
命令支持:
ftp> bin
421 Timeout.
ftp> put /etc/file005.txt /etc/file006.txt
1580 bytes transferred
Total 2 files transferred
ftp> ls
drwx------ 2 14 50 6 Aug 08 06:27 abc
-rw------- 1 14 50 1079 Aug 08 06:40 file005.txt
-rw------- 1 14 50 501 Aug 08 06:40 file006.txt
ftp> bin
421 Timeout.
ftp> mput /etc/file00*
1688 bytes transferred
Total 2 files transferred
ftp> ls
drwx------ 2 14 50 6 Aug 08 06:27 abc
-rw------- 1 14 50 1079 Aug 08 06:41 file005.txt
-rw------- 1 14 50 501 Aug 08 06:41 file006.txt
匿名用戶權限:
匿名用戶的默認配置只能進行文件的讀取和下載,不能進行寫入和上傳文件:
lftp 8.8.8.8:~> put /etc/fstab
put: Access failed: 550 Permission denied. (fstab)
lftp 8.8.8.8:/> mkdir abc
mkdir: Access failed: 550 Permission denied. (abc)
可以看到上傳命令和創建命令都失敗了,沒有響應的權限!
開啟匿名用戶創建文件,重命名,刪除,上傳權限:
#開啟上傳權限
anon_upload_enable=YES
#開啟創建文件權限
anon_mkdir_write_enable=YES
#開啟重命名,刪除權限
anon_other_write_enable=YES
重啟服務,再次進入,發現還是沒法創建目錄,但是報錯信息不一樣,如下:
lftp 8.8.8.8:/> mkdir abc
mkdir: Access failed: 550 Create directory operation failed. (abc)
這是因為目錄沒有寫權限,給pub目錄授權,如下:
[root@localhost ~]# chmod o+w /var/ftp/pub/
[root@localhost ~]# ll /var/ftp/pub/ -d
drwxr-xrwx 3 root root 192 8月 7 08:37 /var/ftp/pub/
再次進入,創建目錄,如下:
lftp 8.8.8.8:/pub> mkdir abc
mkdir 成功, 建立 `abc'
PS:
要想匿名用戶有寫的權限,一是需要服務端配置文件開啟寫的權限,二是所在的目錄本身有其他用戶寫的權限!
禁止匿名用戶登錄:
你甚至可以修改配置文件,只讓本地用戶登錄:
vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
故障解決:
如果重啟或者登陸服務器時,報錯如下:
[root@localhost ~]# systemctl restart vsftpd
Job for vsftpd.service failed because the control process exited with error code. See "systemctl status vsftpd.service" and "journalctl -xe" for details.
[root@localhost ~]# journalctl -xe
-- Unit vsftpd.service has begun starting up.
8月 08 02:59:14 localhost.localdomain vsftpd[12751]: 500 OOPS: bad bool value in config file for: anonymous_en
8月 08 02:59:14 localhost.localdomain systemd[1]: vsftpd.service: control process exited, code=exited status=2
解決辦法:
這種問題一般就是空格導致的,是每一行配置后面都不能有空格,也不能跟注釋。