linux配置ftp服务器与访问ftp服务
linux配置ftp服务器与访问ftp服务
⼀:配置FTP 服务器,允许匿名访问
1.1 FTP 服务
FTP 服务,⽤来传输⽂件的协议
FTP 服务器默认使⽤ TCP 协议的20,21 端⼝
20 端⼝⽤于建⽴数据连接,并传输⽂件数据
21 端⼝⽤于建⽴控制连接,并传输FTP 控制命令
FTP 数据连接分为2主动模式和被动模式
主动模式:服务器主动发起数据连接
被动模式:服务器被动等待数据链接(本章实验使⽤被动模式)
1.2  配置FTP 服务器,允许匿名访问
[root@localhost ~]# yum -y install vsftpd                  #安装vsftpd 包
root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers  user_list  f  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# f vsftpd.bak          #备份f ⽂件
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.bak  f  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# vim /etc/f
anonymous_enable=YES          #开启匿名访问(默认已经开启)
write_enable=YES              #开放服务器的写权限(上传⽂件需要开启)默认快开启
anon_umask=022                #设置匿名⽤户上传数据的权限掩码为022 (反掩码)
anon_upload_enable=YES        #允许匿名⽤户上传⽂件
anon_mkdir_write_enable=YES    #允许匿名⽤于创建(上传)⽬录
anon_other_write_enable=YES    #允许其他⽤户删除,重命名,覆盖等操作
:wq                          #保存退出
[root@localhost vsftpd]# systemctl start vsftpd    #启动 ftp 服务
[root@localhost vsftpd]# systemctl enable  vsftpd  #开启 ftp 的⾃启
[root@localhost vsftpd]# systemctl stop firewalld  #关闭防⽕墙
[root@localhost vsftpd]# setenforce 0              #设置selinux 模式
[root@localhost vsftpd]# chmod 777  /var/ftp/pub
#为匿名访问ftp ⽬录的根⽬录下的 pub ⼦⽬录权限设置为最⼤权限,以便匿名⽤户上传数据
⼆:windows 访问测试
连接⽅式:
在Windows 系统 Win +r  ,然后输⼊ cmd  ,打开命令⾏输⼊。
切换windoes ⽬录到桌⾯:
C:\Users\Administrator>cd C:\Users\Administrator\Desktop
连接ftp服务器:
  ftp  ftp服务器地址
匿名访问:
  ⽤户名为 ftp ,密码为空,登录ftp
ftp 操作:
  pwd                  #查看当前所在⽬录
  ls                      #查看当前⽬录
  cd                    #切换⽬录
  get  ⽂件名      #下载⽂件到windows 本地
  put  ⽂件名      #上传⽂件到 ftp⽬录
quit                  #退出
C:\Users\Administrator>cd C:\Users\Administrator\Desktop  #切换到桌⾯C:\Users\Administrator\Desktop>ftp 192.168.23.10        #连接到ftp服务器
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): ftp                    #⽤户名输⼊ ftp
331 Please specify the password.
密码:                                              #密码为空
230 Login successful.
ftp> pwd                            #查看当前所在⽬录
257 "/"                          #根⽬录(匿名⽤户根⽬录是/var/ftp/)
ftp> ls                          #查看⽬录下的内容
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
pub                              #⽬录下有pub ⽬录
226 Directory send OK.
ftp: 收到 8 字节,⽤时 0.00秒 8.00千字节/秒。
ftp> cd pub                    #切换到pub ⽬录
250 Directory successfully changed.
ftp>
ftp> pwd
257 "/pub"
ftp> ls                        #查看pub ⽬录下的内容
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
<                        #拥有 ⽂件
226 Directory send OK.
ftp: 收到 12 字节,⽤时 0.00秒 12000.00千字节/秒。
ftp>               #从ftp 服务器下载 到本地
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection (15 bytes).
226 Transfer complete.
ftp: 收到 15 字节,⽤时 0.00秒 15.00千字节/秒。
ftp>               #从本地上传 到ftp 服务器
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 发送 12 字节,⽤时 0.00秒 12.00千字节/秒。
ftp> quit                    #退出ftp
221 Goodbye.
###  验证 ###
C:\Users\Administrator\Desktop>dir      #windows查看 是否存在2021/06/29  10:25               
1 个⽂件            15 字节
0 个⽬录 725,971,259,392 可⽤字节
[root@localhost pub]# pwd
/var/ftp/pub
[root@localhost pub]# ls              #linux 查看 test ⽂件是否存在
三:设置本地⽤户验证访问ftp 3.1 修改配置⽂件 /etc/f 设置本地⽤户可以登录,禁⽌匿名⽤户登录
[root@localhost ~]# vim /etc/f
local_enable=YES              #启⽤本地⽤户
anonymous_enable=NO            #关闭匿名⽤户访问(要关闭,⽽不失注释)write_enable=YES         
    #开启服务器写权限
local_umask=077                #设置仅宿主拥有上传⽂件的权限(反掩码)chroot_local_user=YES          #将访问禁锢在⽤户的宿主⽬录中
etc被拉入黑名单了怎么办allow_writeable_chroot=YES    #允许被限制的⽤户主⽬录具有写权限
:wq
[root@localhost ~]# systemctl restart vsftpd  #重启服务
3.2 访问测试
C:\Users\Administrator\Desktop>ftp 192.168.23.10
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): ftp
331 Please specify the password.
密码:
530 Login incorrect.
登录失败。                    #ftp ⽤户⽆密码登录失败
C:\Users\Administrator\Desktop>ftp 192.168.23.10
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): test  #使⽤test ⽤户登录
331 Please specify the password.
密码:                            #输⼊test ⽤户密码
230 Login successful.            #使⽤普通⽤户 test 的账号登录成功
ftp>
ftp> pwd
257 "/"              #普通⽤户的根⽬录是它的家⽬录
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
下载
公共
图⽚
⽂档
桌⾯
模板
视频
⾳乐
226 Directory send OK.    #这些是⽤户家⽬录⾥的⽂件
ftp: 收到 67 字节,⽤时 0.00秒 16.75千字节/秒。
3.3 图形化登录
(1)  在地址栏输⼊ ftp://ftp 服务器地址
(2) 输⼊⽤户名和密码 (如果是匿名⽤户,点上匿名登录)
(3) windows 和linux 之间可以直接拖拽上传
从windows 上拖拽上传
[test@localhost ~]$ whoami
test
[test@localhost ~]$ pwd
/home/test
[test@localhost ~]$ ls
<  公共模板视频图⽚⽂档下载⾳乐桌⾯
四:设置⽩名单和⿊名单4.1 设置⿊名单
配置⽂件  /etc/vsftpd/usr_list  ,向⽂件添加或删除⽤户[root@localhost ~]# vim /etc/vsftpd/user_list
test      #添加⽤户
:wq
[root@localhost ~]# vim /etc/f
userlist_enable=YES
userlist_deny=YES(默认是此设置)
#设置⿊名单,不允许 user_list ⾥的⽤户登录
:
wq
[root@localhost ~]# systemctl restart vsftpd  #重启服务
测试登录
C:\Users\Administrator\Desktop>ftp 192.168.23.10
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): lisi
331 Please specify the password.
密码:
230 Login successful.        #lisi ⽤户不在user_list 中,可以登录ftp> quit
221 Goodbye.
C:\Users\Administrator\Desktop>ftp 192.168.23.10
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): test
530 Permission denied.      #test ⽤户在user_list 中,不可以登录登录失败。
4.2 设置⽩名单
[root@localhost ~]# vim /etc/f
userlist_enable=YES
userlist_deny=NO
#将YES 改为 NO,即设置⽩名单,仅允许user_list 中⽤户登录 :wq
[root@localhost ~]# systemctl restart vsftpd  #重启服务
测试
C:\Users\Administrator\Desktop>ftp 192.168.23.10
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): lisi
530 Permission denied.
登录失败。              #⽤户lisi 不在⽩名单内,登录失败
ftp> quit
221 Goodbye.
C:\Users\Administrator\Desktop>ftp 192.168.23.10
连接到 192.168.23.10。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
⽤户(192.168.23.10:(none)): test
331 Please specify the password.
密码:
230 Login successful.      #⽤户test 在⽩名单内,登录成功ftp>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。