文章目錄
- 1.完成網路配置
- 2.安裝vsftpd服務器
- 3.配置匿名用戶
- 4.配置本地用戶
- 5.安裝并配置mysq
- 6.啟用日志檔案
1.完成網路配置
點擊windowns安裝環回網卡完成網路配置
2.安裝vsftpd服務器
2.1檢測系統內部是否已經安裝好vsftpd檔案
[root@mail3 ~]# rpm -qa |grep vsftpd
出現如下圖,則已安裝好vsftpd,沒有則采用yum安裝

2.2安裝
[root@mail3 ~]# yum install vsftpd
[root@localhost ~]# yum install ftp


2.3開機啟動
[root@mail3 ~]# systemctl enable vsftpd
3.配置匿名用戶
3.1打開組態檔/etc/vsftpd/vsftpd.conf
[root@mail3 ~]# vim /etc/vsftpd/vsftpd.conf
3.2啟用匿名用戶,允許下載,上傳但禁止洗掉檔案
使用vim快捷鍵搜索修改即可,在命令模式下輸入/加關鍵字回車后修改,搜不到的添加上去,然后在命令模式下輸入wq回車退出保存,
anonymous_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_umask=022
anon_other_write_enable=NO
3.3在控制臺上輸入下面的命令
[root@mail3 ~]# mkdir -p /var/ftp/pub
[root@mail3 ~]# chown ftp /var/ftp/pub
3.4啟動服務,測驗匿名用戶的各種操作
[root@mail3 ~]# systemctl restart vsftpd
在瀏覽器上使用用戶名ftp(密碼為任意字符)訪問服務器ftp://172.16.51.1,或者在命令列上輸入ftp命令測驗,
[root@localhost ~]# ftp localhost
Trying ::1…
Connected to localhost (::1).
220 (vsFTPd 3.0.2)
Name (localhost:root): ftp
331 Please specify the password.
Password:回車
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||19529|).
150 Here comes the directory listing.
drwxr-xr-x 2 14 0 6 Oct 13 16:10 pub
226 Directory send OK.
ftp> cd pub
250 Directory successfully changed.
ftp> dir
229 Entering Extended Passive Mode (|||36760|).
150 Here comes the directory listing.
226 Directory send OK.
ftp> mkdir ftp
257 “/pub/ftp” created
ftp> dir
229 Entering Extended Passive Mode (|||46141|).
150 Here comes the directory listing.
drwxr-xr-x 2 14 50 6 Mar 01 08:38 ftp
226 Directory send OK.
ftp> quit
221 Goodbye.
4.配置本地用戶
4.1打開組態檔/etc/vsftpd/vsftpd.conf
vim /etc/vsftpd/vsftpd.conf
4.2啟用本地用戶,允許下載,上傳和禁止洗掉檔案,
local_enable=YES
write_enable=YES
local_umask=022
4.3限制本地用戶切換目錄
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YES //檔案里沒有這個,需要自己添加上去
注意:檔案/etc/vsftpd/chroot_list需要手動生成
4.4將需要限制切換目錄的用戶名字按照每行一個的方式寫入chroot_list_file指定的檔案中,每一個用戶一行,
打開vim編輯
[root@localhost ~]# vim /etc/vsftpd/chroot_list
修改
mary
4.5重啟服務,在命令列上測驗(可參照如下命令)
重啟
[root@localhost ~]# systemctl restart vsftpd
測驗
[root@localhost ~]# ftp localhost
Trying ::1…
Connected to localhost (::1).
220 (vsFTPd 3.0.2)
Name (localhost:root): mary
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||49733|).
150 Here comes the directory listing.
-rw-r–r-- 1 0 0 0 Mar 01 08:58 public_html
226 Directory send OK.
ftp> cd /
250 Directory successfully changed.
ftp> dir
229 Entering Extended Passive Mode (|||49114|).
150 Here comes the directory listing.
-rw-r–r-- 1 0 0 0 Mar 01 08:58 public_html (沒有切換到根目錄,測驗成功
226 Directory send OK.
ftp> exit
221 Goodbye.
5.安裝并配置mysq
5.1安裝mysql服務
[root@localhost ~]# yum install gcc gcc-c++ pam-devel
[root@localhost ~]# yum install mysql-devel
安裝mysql-server(要讓linux聯網,可新建一個網卡(Net連接),并暫時關閉其他網卡,)
[root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# yum install mysql-community-server
5.2下載并安裝mysql.so
下載方法一:(不推薦速度慢)
[root@localhost ~]# wget http://downloads.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz?use_mirror=nchc
下載方法二:
點擊mysql.so進去下載,然后復制到linux根目錄,
輸入以下命令
[root@localhost pam_mysql-0.7RC1]# ll pam_mysql-0.7RC1.tar.gz
[root@localhost pam_mysql-0.7RC1]# tar -zxf pam_mysql-0.7RC1.tar.gz -C /tmp/
[root@localhost pam_mysql-0.7RC1]# cd /tmp/pam_mysql-0.7RC1/
[root@localhost pam_mysql-0.7RC1]# ./configure --with-pam=/usr --with-mysql=/usr --with-pam-mods-dir=/usr/lib64/security
[root@localhost pam_mysql-0.7RC1]# make;make install
5.3創建虛擬用戶對應的系統用戶
[root@localhost pam_mysql-0.7RC1]# useradd -d /home/virtual -s /sbin/nologin virtual
[root@localhost pam_mysql-0.7RC1]# chmod o+r /home/virtual
5.4創建存盤虛擬用戶的資料庫和表
重啟服務
[root@localhost pam_mysql-0.7RC1]# systemctl restart mysqld
輸入下面的mysql陳述句,默認的密碼為空,直接回車即可,
[root@localhost pam_mysql-0.7RC1]# mysql -u root -p

輸入mysql陳述句
mysql> use ftpdb;
mysql> create table ftpusers(name char(20),password char(20));
mysql> insert into ftpusers(name,password)values(‘pei’,‘pei’);
mysql> insert into ftpusers(name,password)values(‘huan’,‘huan’);
mysql> grant select on ftpdb.ftpusers to virtual@localhost identified by’123456’;
mysql>quit
若重復創建某用戶,可以采用delete命令洗掉,命令如下
mysql> delete from ftpuser where name"huan";
查看某用戶的命令
mysql> select * from ftpusers;
5.5修改vsftp主組態檔
[root@localhost pam_mysql-0.7RC1]# vim /etc/vsftpd/vsftpd.conf
pam_service_name=vsftpd.virtual
下面兩個命令沒有添加上去就行
guest_enable=YES
guest_username=virtual
5.6建立pam認證檔案
[root@localhost pam_mysql-0.7RC1]# vim /etc/pam.d/vsftpd.virtual
auth required /usr/lib64/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpdb table=ftpusers usercolumn=name passwdcolumn=password crypt=0
account required/usr/lib64/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpdb table=ftpusers usercolumn=name passwdcolumn=password crypt=0
注意:以上檔案共2行,如下所示,

注意:
crypt=n
crypt=0:明文密碼
crypt=1:使用crpyt()函式(對應SQL資料里的encrypt(),encrypt()隨機產生salt)
crypt=2:使用MYSQL中的password()函式加密crypt=3:表示使用md5的散列方式
5.6重啟vsftpd服務
[root@localhost pam_mysql-0.7RC1]# systemctl restart vsftpd
5.7采用虛擬用戶pei和huan進行測驗
[root@localhost ~]# ftp localhost
Trying ::1…
Connected to localhost (::1).
220 (vsFTPd 3.0.2)
Name (localhost:root): huan
331 Please specify the password.
Password:(密碼輸入huan)
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>dir
229 Entering Extended Passive Mode (|||33353|).
150 Here comes the directory listing.
226 Directory send OK.
ftp> exit
221 Goodbye.
5.8將虛擬用戶設定獨立目錄
[root@localhost ~]# vim /etc/vsftp.conf
user_config_dir=/etc/vsftpd/vsftpd_user_conf
[root@localhost ~]# mkdir -p /etc/vsftpd/vsftpd_user_conf
5.9用戶huan擁有自己的個人目錄,具有修改檔案的屬性
[root@localhost ~]# vim /etc/vsftp.conf
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
[root@localhost ~]# mkdir -p /etc/vsftpd/vsftpd_user_conf
[root@localhost ~]# mkdir /home/huan
[root@localhost ~]# chown virtual.virtual /home/huan/
[root@localhost ~]# cd /etc/vsftpd/vsftpd_user_conf
[root@localhost vsftpd_user_conf]# vim huan
local_root=/home/huan
anon_other_write_enable=YES
anon_upload_enable=YES
重啟vsftpd
[root@localhost ~]# systemctl restart vsftpd
5.10測驗虛擬用戶個人目錄及屬性設定
在huan的主目錄下新建兩個檔案(1.txt,hello-dir),以及在root目錄新一個2.txt檔案
[root@localhost ~]# cd /home/huan
[root@localhost huan]# touch 1.txt
[root@localhost huan]# touch test_dir
[root@localhost huan]# cd
[root@localhost ~]# touch 2.txt
測驗
[root@localhost ~]# ftp localhost
Trying ::1…
Connected to localhost (::1).
220 (vsFTPd 3.0.2)
Name (localhost:root): huan
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> get 1.txt
local: 1.txt remote: 1.txt
229 Entering Extended Passive Mode (|||35884|).
150 Opening BINARY mode data connection for 1.txt (0 bytes).
226 Transfer complete.
ftp> put 2.txt
local: 2.txt remote: 2.txt
229 Entering Extended Passive Mode (|||38336|).
150 Ok to send data.
226 Transfer complete.
ftp> rename test_dir hello-dir
350 Ready for RNTO.
250 Rename successful.
ftp> dir
229 Entering Extended Passive Mode (|||22539|).
150 Here comes the directory listing.
-rw-r–r-- 1 0 0 0 Mar 01 11:53 1.txt
-rw-r–r-- 1 1002 1002 0 Mar 01 11:55 2.txt
-rw-r–r-- 1 0 0 0 Mar 01 11:52 hello-dir
226 Directory send OK.
ftp> exit
221 Goodbye.
6.啟用日志檔案
在主組態檔/etc/vsftpd/vsftpd.conf中找到相關資訊進行修改
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
xferlog_enable=YES
xferlog_std_format=NO
重啟vsftpd服務
[root@localhost ~]# systemctl restart vsftpd
在Windows測驗
-
按win+R鍵輸入FTP回車

-
輸入open 172.16.51.1后回車,然后輸入用戶名和密碼

-
輸入dir查看FTP服務器中的檔案及目錄

-
輸入lcd d:\進入本地D盤,然后輸入!dir查看本地檔案及目錄

- 輸入put mary.txt(我事先已在D盤建了)上傳自FTP服務器,然后輸入dir查看

查看日志
[root@localhost ~]# cat /var/log/vsftpd.log

博主首頁:https://zjj0707.blog.csdn.net/
如果文章對你有幫助,記得一鍵三連 ?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/265513.html
標籤:其他
