FTP
FTP:File Transfer Protocol 文件傳輸協議
常見的ftp服務器端程序:
wu-ftpd: 華盛頓大學研發
vsftpd: very Secure ftp Daemon 安全性高
proftpd:
pureftpd:
Filezilla
windows的ftp服務器“
Serv-U
Filezilla(開源)
客戶端程序:
CLI:
ftp
lftp
GUI:
gftpd
FlashFXP
Cuteftp
Filezilla
vsftpd: 紅帽中的rpm包是vsftpd,主要着眼於安全性
/etc/vsftpd: 配置文件目錄(rpm)
/etc/init.d/vsftpd: 服務腳本
/usr/sbin/vsftpd: 主程序
基於PAM實現用戶認證
/etc/pam.d/*
/lib/security/* 認證模塊
/lib64/security/* 64位系統,認證模塊在這兒
支持虛擬用戶
vsftpd: /var/ftp: 提供服務的根目錄,這個目錄對於vsftpd這個進程來說,是不能有寫權限的,不允許除了root用戶以外,其它用戶有寫權限 文件目錄,其它用戶不能有寫權限,這是一種安全保證
ftp: 用戶
匿名用戶 --> 有一個與之對應的系統用戶
系統用戶
虛擬用戶 --> 有一個與之對應的系統用戶
以上三種用戶,都要映射爲系統用戶
/var/ftp: ftp用戶的家目錄
匿名用戶默認訪問的目錄 因爲匿名用戶被映射爲ftp用戶
下面我們使用vsftpd來構建一個簡單的ftp服務器
1、關閉selinux,setenforce 0,永久關閉請編輯配置文件/etc/selinux/config使SELINUX=permissive,然後再執行setenforce 0,執行getenforce可查看是否關閉
2、配置yum源
3、裝載開發組環境 yum groupinstall "Development Tools" "Development Libraries"
1、yum install vsftpd
安裝後生成的部分文件介紹:
2、ftp服務的運行者
3、在windows命令行界面下,匿名登錄
4、vsftpd的配置文件部分選項介紹,及其部分配置圖解
- 配置文件/etc/vsftpd/vsftpd.conf中的部分選項介紹:
- 想詳細瞭解選項問題:man vsftpd.conf
- anonymous_enable= #是否開放匿名用戶
- local_enable = #是否開放系統用戶
- write_enable= #是否能上傳文件的(定義的是系統用戶)
- listen=YES #表示vsftpd是否工作爲獨立守護進程
- anon_upload_enable= #是否允許匿名用戶上傳文件
- anon_mkdir_write_enable= #是否允許創建目錄
- dirmessage_enable=YES #當用戶進入一個目錄時,是否顯示歡迎信息的
- xferlog_enable=YES #是否打開傳輸日誌
- xferlog_file=/var/log/xferlog #打開這項才能看日誌的
- xferlog_std_format=YES #日誌文件是否顯示爲標準格式
- #chown_uploads=YES #當用戶上傳完文件後,是否把屬主改了
- #chown_username=whoever #改爲誰
- chroot_list_enable=YES #是不是用一個文件將特定用戶鎖在它的家目錄下
- chroot_list_file=/etc/vsftpd/chroot_list #在哪創建一個用戶列表,所有在列表中的用戶都將鎖在
- 用戶家目錄下
- 加一行:chroot_local_user=YES #表示所有用戶都被禁錮在家目錄下
/etc/vsftpd/ftpusers #所有寫在這個文件中的用戶都禁止訪問ftp服務器
userlist_enable=YES #使用這個列表中的用戶來控制用戶登錄的
userlist_deny=YES #這個列表中的用戶拒絕登錄ftp服務器
userlist_deny=NO #僅允許這個列表中的用戶登錄ftp
- [root@mail ~]# echo "redhat" | passwd --stdin peter
- Changing password for user peter.
- passwd: all authentication tokens updated successfully.
- [root@mail ~]# cp /etc/inittab /home/peter #複製一個文件至peter的家目錄下
- [root@mail ~]# cd /etc/vsftpd
- [root@mail vsftpd]# ftp 172.16.25.3
- Connected to 172.16.25.3.
- 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 (172.16.25.3:root): peter
- 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 (172,16,25,3,55,140)
- 150 Here comes the directory listing.
- 226 Directory send OK.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,116,15)
- 150 Here comes the directory listing.
- -rw-r--r-- 1 0 0 1666 Apr 17 20:10 inittab
- 226 Directory send OK.
- ftp> pwd
- 257 "/home/peter"
- ftp> cd /etc #用戶可以訪問其他目錄,沒有鎖定在其家目錄下
- 250 Directory successfully changed.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,88,24)
- 150 Here comes the directory listing.
- -rw-r--r-- 1 0 0 2518 May 11 2011 DIR_COLORS
- -rw-r--r-- 1 0 0 2420 May 11 2011 DIR_COLORS.xterm
- -rw-r--r-- 1 0 0 92794 May 29 2007 Muttrc
- -rw-r--r-- 1 0 0 0 May 29 2007 Muttrc.local
- drwxr-xr-x 4 0 0 4096 Mar 29 13:34 NetworkManager
- drwxr-xr-x 9 0 0 4096 Mar 29 13:46 X11
- -rw-r--r-- 1 0 0 2562 Jan 15 2008 a2ps-site.cfg
# 文件服務權限:文件系統權限*文件共享權限
5、匿名用戶上傳文件
# cd /etc/vsftpd/
匿名用戶映射爲了ftp用戶,雖然ftp服務的進程的執行者是ftp用戶,但是/var/ftp和/var/ftp/pub目錄的屬主和屬組
都是root用戶,所以雖然開啓了允許匿名用戶上傳文件的選項,但其還沒讀寫的權限,我們創建一個目錄,給ftp用戶
讀寫執行權限
6、刪除和創建目錄
- [root@mail vsftpd]# ftp 172.16.25.3
- Connected to 172.16.25.3.
- 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 (172.16.25.3: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 (172,16,25,3,161,139)
- 150 Here comes the directory listing.
- drwxr-xr-x 2 0 0 4096 Dec 05 2011 pub
- drwxrwxr-x 2 0 0 4096 Apr 17 20:33 upload
- 226 Directory send OK.
- ftp> cd upload
- 250 Directory successfully changed.
- ftp> lcd /etc
- Local directory now /etc
- ftp> put fstab
- local: fstab remote: fstab
- 227 Entering Passive Mode (172,16,25,3,131,221)
- 150 Ok to send data.
- 226 File receive OK.
- 684 bytes sent in 0.043 seconds (15 Kbytes/s)
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,24,127)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- 226 Directory send OK.
- ftp>
- [root@mail vsftpd]# service vsftpd restart
- Shutting down vsftpd: [ OK ]
- Starting vsftpd for vsftpd: [ OK ]
- [root@mail vsftpd]# ftp 172.16.25.3
- Connected to 172.16.25.3.
- 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 (172.16.25.3: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 (172,16,25,3,253,29)
- 150 Here comes the directory listing.
- drwxr-xr-x 2 0 0 4096 Dec 05 2011 pub
- drwxrwxr-x 2 0 0 4096 Apr 17 20:37 upload
- 226 Directory send OK.
- ftp> cd upload
- 250 Directory successfully changed.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,239,197)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- 226 Directory send OK.
- ftp> mkdir lsq #成功創建目錄
- 257 "/upload/lsq" created
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,187,136)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- drwx------ 2 14 50 4096 Apr 17 20:50 lsq
- 226 Directory send OK.
- ftp> delete lsq
- 550 Delete operation failed.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,164,33)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- drwx------ 2 14 50 4096 Apr 17 20:50 lsq
- 226 Directory send OK.
- ftp> delete fstab #成功刪除目錄
- 250 Delete operation successful.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,39,238)
- 150 Here comes the directory listing.
- drwx------ 2 14 50 4096 Apr 17 20:50 lsq
- 226 Directory send OK.
- ftp>
7、怎樣鎖定用戶在其家目錄下
以上就是ftp服務,部分可以啓用的選項的應用,大家可以動手做做,瞭解一下其它選項的作用,這裏就不一一介紹了!
下一篇配置vsftpd+pam+mysql