FTP连接及连接模式

控制连接:TCP 21,用于发送FTP命令信息

数据连接:TCP 20,用于上传、下载数据

数据连接的建立类型

主动模式:服务端从 20 端口主动向客户端发起连接

被动模式:服务端在指定范围内某个端口被动等待客户端连接

FTP传输模式

文本模式:ASCII 模式,以文本序列传输数据

二进制模式:Binary 模式,以二进制序列传输数据

基于系统用户的 FTP 服务(匿名用户)

首先挂载光盘 切换到/yum.repos.d/目录 删除所有文件 修改文件

然后安装ftp服务器

I rootdlocalhost mount / devtcdrom 
mount: /dev/srO 
I rootdlocalhost -l cd /etc/yum. repos. d/ 
rootetocalhost yum. repos. 
1 root root 53 8k 
I rootblocalhost yum. repos. dl 
I rootßlocalhost yum. repos. 
I rootdlocalhost yum. repos. dl # 
mnt/ 
12 17. 
•57 aa. repo 
vim zz. repo 
yum Install vsftpd* -

*ECS') 
narne=ZZ 
baseurl=file: ///mnt 
enable* 
gpgcheck=o

切换到vsftpd目录 重启发ftp服务 关闭防火墙和安全Linux

[ rootOlocalhost yum. repos. d] # cd /etc/vsftpd 
root•localhost vsftpdl systemctl restart vsftpd 
[ root810calhost vsftpd] # systemctl stop firewalld 
I rootalocalhost vsftpdl setenforce O 
setenforce: SELinux is disabled

切换到/ftp/pub目录下 创建一个文件 然后登录ftp可以下载

root@localhost vsftpd] # cd /var/ftp 
rootatocalhost ftpl# 
drwxr- xr-x 2 root root 6 10k 2020 pub 
root•tocalhost 
bash: cd: 'pub: 
rootatocalhost 
root•tocalhost 
root@localhost 
ftpl# cd /pub 
ftpl# cd pub 
publ # touch qqq 
publ#

Tem plates 
Videos 
NTUSER.D„. 
Lj ntuser.dat..„ 
ntuser.dat..„ 
n 
NTUSER.D... 
Cl NTUSER.D... 
C) NTUSER.D„. 
ntuser.ini 
1.310,7... 
o 
373.760 
65,536 
524,288 
524,288 
20 
DAT 
LOGI 
LOG2 
BLF 
REGTRAN... 
REGTRAN... 
2021/7/6 11:... 
2021/6/1 17:... 
2021/6/1 15:... 
2021/6/1 15:... 
2021/6/1 17:... 
2021/6/1 15:... 
2021/6/1 15:... 
2021/6/1 15:... 
2021/9/261... 
2021/9/26...

切换到vsftpd目录下 复制一份配置文件 然后进ftp服务的配置文件

I rootßlocalhost publ # cd tetc/vsft 
I rootßlocalhost vsftpdl# Il 
20 
- 1 root root 125 1 Og 
IA 2020 ftpusers 
I root root 361 1 Ok 
14 2020 user list 
- I root root 5116 10B 
14 2020 vsftpd. conf 
1 root root 338 1 Ok 
14 2020 vsftpd conf migrate. sh 
- rvxr--r-- 
I rootetocalhost vsftpdl cp vsftpd. conf vsftpd. eonf. Sak 
I rootßlocalhost vsttpdl g vim vsttpd. cont 
I rootdlocalhost vsftpdl systemctl restart vsftpd

开启匿名用户:去掉前面#符号 保存退出 重启ftp服务

local umask=C22 
Uncomment this to allow the 
has an effect if the above gl 
obviously need to create a dj 
When SELinux is enforcing che

切换到ftp目录下 给pub这个目录可以上传的权限

LinuxFTP文件传输服务_虚拟用户

随便拖一个文件上传到ftp

kroot8toca1host pub] # 
- I ftp ftp 5071 
26 
11: 57 
r--r-- 1 root root 
26 
LAMP- 7. 3. txt

再切换到vsftpd目录,进配置文件修改

I root$localhost ftpl# cd /etc/vsftpd 
I root810calhost vsftpdl g virn vsftpd. conf 
I root$localhost vsftpdl # virn vsftpd. conf 
I root810calhost vsftpdl g systernctl restart vsftpd

开启用户

LinuxFTP文件传输服务_上传_02

允许上传

when SELinux is enforcing 
full access 
anon_up 
Uncomment this if you wan-

创建目录权限,其他写入和删除权限,传输速率

Uncornment this if you want the 
new directories. 
anon mkdir write enable—YES 
anon other write enable=YES

基于系统用户的 FTP 服务(实名用户)

切换到vsftpd目录 然后编辑ftp配置文件 重启发ftp服务 并创建一个用户

I rootB10calhost 
I root810caIhost 
I rootnocalhost 
I root810calhost 
root81 oca I host 
I rootB10calhost 
usi 
ttplț Vim vsftpd. conf 
ftpl # cd 
vsftpdl 
vsftpdl 
vsftpdl 
vsttpdl 
/ etc/vsftpd 
Vim vsftpd. conf 
systemctl restart vsftpd 
useradd 
passwd tisi

编辑配置文件

将用户禁锢在主目录 允许家目录具有写入权限 白名单

# the user does not have write access to the top 
# chroot) 
chroot local user=YES 
Eh root: 
allow writeable chroot=YES 
# (default follows) 
h root _ list 
c 
# You mav activate the 
" -R" option to the built in

创建黑名单 然后切换到用户查看上传的文件

root810calhost 
rootatocalhost 
root8tocathost 
rootOlocalhost 
8 
vsftpd] # 
vsftpdl 
vs ftpd] # 
tom] # Il 
touch chroot list 
systemctl restart vsftpd 
cd /home/tom/ 
rwr r - 1 tom tom 3071 27 13:42 LAMP-7.3. txt

切换到上行目录 不让他进去家目录,修改黑名单的配置,就添加用户tom到列表里,就不会被锁定

重启ftp服务 如果要换一个目录就修改ftp配置文件 创建目录 给他权限 重启一下服务

最后给ftp目录所有权限 可以实现在目录下可以上传下载删除等

[ root@locathost 
/etc/vsftpd 
[ root'tocalhost 
I root@localhost 
I root•tocalhost 
[ root@localhost 
I root@localhost 
chroot list 
ftpusers 
[ root8toca1host 
I root@localhost 
I root'localhost 
tom] # cd - 
vsftpdl # 
vim chroot list 
vsftpdl # 
systemctl restart vsftpd 
vsftpdl 
vim vsftpd. conf 
vsftpdl # 
mkdlr • p /ftp/test 
vsftpdl 
chmod 777 
user list 
vs ftpd. conf 
vsftpdl # chmod 777 /ftp/test/ 
vsftpdl cd / 
c2mod 777 / ftp 
vs ftp 
vs ftp

# Uncomment this to allow loca 
# When SELinux is enforcing chr 
Local enable=YES 
local _ root=/ftp/test 
# Uncomment this to enable any 
write enabte=YES

D vşFT... 
L) 222 
66 
2,461 
Heinot... 
2021/9/27... 
2021/9/27... 
2021/9/27... 
1003 
-rw-r„r- 00 
drwx•••... 
1003 1..

构建基于虚拟用户的 FTP 服务

切换到vsftpd目录下 过滤监听ftp端口号 然后修改ftp的配置文件 重启服务

[ rootOlocalhost 
rootOlocaIhost 
tcp6 
[ root8tocathost 
[ rootOlocalhost 
root•tocalhost 
[ root810calhost 
cd /etc/vsftpd 
vsftpdl 
vsftpd] # 
vsftpd] # 
vsftpdl 
vsftpd] # 
netstat - anptl grep ftp 
vim vsftpd. conf 
systemctl restart vsftpd 
vim user list 
systemctl restart vsftpd

独立运行的监听服务 地址 和端口号 去掉ipv6

tisten=YES 
Usten address* 92.168.1.20

addresses) then you must run two copies of vsl 
# files. 
Make sure. that one at the I i Cten 
user List enable*ES

启用 user_list 列表文件 禁用 user_list 中的用户

Make sure, that one of t 
/tUsten_Lpvö-YES 
userlist enable=YES 
userlist deny=YES 
pam service _name*usftpd

用户加入到里就不能连接

I rootßlocalhost 
I rootetocalhost 
rootB10cathost 
I rootßlocalhost 
vs ftpdl 
vsftpdl # 
vsftpdl 
vsftpdl g 
vim user 
systemctl restart 
vim user list 
systemctl restart 
vs ftpd 
vs ftpd

root 
bin 
aenon 
adm 
Sync 
shutdown 
halt 
ucp 
ope ra tor 
games 
10 body

配置虚拟用户密码 转换成数据库文件 更改权限 指定家目录不能登入操作系统并添加用户

[ root•tocalhost vsttpd] # vim vusers. txt 
[ rootOlocalhost vsftpd] # db load -T -t hash -f vusers. txt vusers. db 
rootalocalhost vsftpdl chmod 600 vusers. 
[ root810calhost vsttpd] # useradd -d /srv/ -s /sbin/notogin vuser 
user-add : :

Iqaz2wsx ! QAZ 
u ser2 
Iqaz2wsx!QAZI

编辑虚拟用户的认证模块 重启服务

[ root•tocalhost vsttpdl # vi /etc/pam. d/vsftpd. vu 
I rootalocalhost vsftpdl vim csftpd. conf 
[ rootstocalhost vsttpdl # vim vsttpd. conf 
rootatocalhost vsftpdl systemctl restart vsftpd

auth 
account 
required 
pam userdb . so db—/etc/vsftpd/vusers 
db=/etc/vsftpd/vusers• 
requi red 
pam_userdb . so

编辑ftp配置文件

pam service_nameasftpd 
use rust enabte=YES 
tcp _wrappers—YES 
guest e=MES 
guest_use rname4user 
am vu 
se r=/etc/vsftpd/vdir 
•vsftpd. conf" 140L, 5393c

再次修改配置文件 创建vdir目录 切换到vdir目录 然后在/opt/创建t01目录

再给那个目录属主为vuser权限

I rootßlocalhost 
I root610calhost 
I rootblocalhost 
I root610calhost 
rootOIocaIhost 
I root810ca1host 
roototocalhost 
I rootßlocalhost 
I root610caIhost 
I rootblocalhost 
vsttpdl g 
vsftpdl # 
vs ftpdl 
vsftpdl 
vsftpdl # 
vim vsttpd. cont 
systemctl restart vsftpd 
vim vsftpd. conf 
mkdir vdir 
cd vdir/ 
vdirl# vi user-I 
mkdir /opt/t01 
vdirl# chown vuser / opt/tOI 
vdirl# -d /opt/t01/ 
drwxr. xr.x 2 vuser root 6 9B 27 15:46 / opt/t01/

修改后重启

LinuxFTP文件传输服务_重启_03

编辑用户user1

anon_uptoad enable—YES 
anon mkdir write enable=YES 
anon other write enable=YES 
locat_rootZ/opt/EOU

切换目录 修改配置文件 重启服务后切换到/opt/目录下查看

[ root810caIhost vdirlä cd . 
rootalocalhost vsftpdl vim vsftpd. conf 
[ rootstocathost vsftpd] # systemctl restart vsftpd 
rootBIocaIhost vsftpdl cd / opt/ 
krootBtocathost opt] # 11 
40

# chroot) 
#chroot local user—YES 
#chroot list enable=YES 
allow 
# (deFauIt follows) 
list

最后测试查看 user1

I rootalocalhost 
ocalhost 
I rootatocalhost 
I rootBtoca1host 
optl # 
toll# 
toll 
cd UI/ 
touch 1112 
cd

 

) ・ 可 二 コ 幽 ト 三 
文 件 大 小 文 僻 型 
2021 / 5 / 1 1 5 :. 
2021 〃 / 5 1 1 :. 
文 僻 名 
ロ 222 
ー 66 
2461 
0 
Helnot... 
文 件 
文 件 
最 近 修 改 
2021 / 9 / 27 … 
2021 / 9 / 27. を 
2021 / 9 / 27 … 
模 限 
可 w ィ - 
drwx-- 
所 有 者 / 重 
1003 1.. 
0 0 
1003 1..

切换目录 再编辑user2 创建目录 属主改为vuser 切换到目录下做测试

I root'localhost -l g cd /etc/vsttpd 
I rootmocalhost vsftpdlg cd Vdir/ 
I root810ca1host vdirlg 
rw- - I root root 100 9B 27 15:46 userl 
I root810ca1host vdirl# vim user2 
root'localhost vdirl# mkdir /opt/t02 
root'localhost vdirl# chown vuser /opt/t02 
I root810ca1host vdirlg cd /opt/t02/ 
I rootmocalhost 021 # touch 222

anon_upload enable—YES 
anon mkdir write enable=YES 
anon other write enable=YES 
locat_rootZ/opt/æ021

 

第 こ コ 
30VOC000 
文 件 大 小 文 件 型 
2021 / 5 / 1 15 
2021 / 7 / 611 
文 件 名 
ロ 
VSFT... 
ー 65 
2.451 
Hetnot … 
文 件 実 
電 近 修 改 
2021 / 9 / 27 … 
2021 / 9 / 2 み . 
2021 / 9 / 27 … 
ィ W - ト - 
drwx--- 
所 有 者 / 
1003 1 .. 
0 0 
10031-