FTP服务

2022-11-16  本文已影响0人  Tess鱼丸
image.png image.png image.png image.png
[root@localhost ~]# rpm -q vsftpd
未安装软件包 vsftpd 
[root@localhost ~]# 
[root@localhost ~]# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 文件已删除
[root@localhost ~]# ^C
[root@localhost ~]# 
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls 
bak  localyum.repo  redhat.repo
[root@localhost yum.repos.d]# rm -rf redhat.repo 


[root@localhost ~]# 
[root@localhost ~]# mount /dev/sr0  /mnt/cdrom/
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# 
[root@localhost ~]# ls -al /mnt/cdrom/
总用量 53
dr-xr-xr-x. 7 root root  2048 4月   4 2020 .
drwxr-xr-x. 4 root root    31 10月 31 14:54 ..
dr-xr-xr-x. 4 root root  2048 4月   4 2020 AppStream
dr-xr-xr-x. 4 root root  2048 4月   4 2020 BaseOS
-r--r--r--. 1 root root    60 4月   4 2020 .discinfo
dr-xr-xr-x. 3 root root  2048 4月   4 2020 EFI
-r--r--r--. 1 root root  8266 4月   4 2020 EULA
-r--r--r--. 1 root root  1455 4月   4 2020 extra_files.json
-r--r--r--. 1 root root 18092 4月   4 2020 GPL
dr-xr-xr-x. 3 root root  2048 4月   4 2020 images
dr-xr-xr-x. 2 root root  2048 4月   4 2020 isolinux
-r--r--r--. 1 root root   103 4月   4 2020 media.repo
-r--r--r--. 1 root root  1669 4月   4 2020 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 4月   4 2020 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 4月   4 2020 TRANS.TBL
-r--r--r--. 1 root root  1560 4月   4 2020 .treeinfo
[root@localhost ~]# 
[root@localhost ~]# rpm -q vsftpd
未安装软件包 vsftpd 
[root@localhost ~]#  
[root@localhost ~]# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
0 文件已删除
[root@localhost ~]#  
[root@localhost ~]# dnf install vsftpd -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
BaseOS                                          405 MB/s | 2.3 MB     00:00    
AppStream                                       542 MB/s | 5.8 MB     00:00    
依赖关系解决。
================================================================================
 软件包          架构            版本                  仓库                大小
================================================================================
安装:
 vsftpd          x86_64          3.0.3-31.el8          AppStream          180 k

事务概要
================================================================================
安装  1 软件包

总计:180 k
安装大小:343 k
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                 1/1 
  安装    : vsftpd-3.0.3-31.el8.x86_64                                      1/1 
  运行脚本: vsftpd-3.0.3-31.el8.x86_64                                      1/1 
  验证    : vsftpd-3.0.3-31.el8.x86_64                                      1/1 
Installed products updated.

已安装:
  vsftpd-3.0.3-31.el8.x86_64                                                    

完毕!
[root@localhost ~]# 
[root@localhost ~]# dnf install ftp -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:02:56 前,执行于 2022年11月17日 星期四 08时41分23秒。
依赖关系解决。
================================================================================
 软件包        架构             版本                  仓库                 大小
================================================================================
安装:
 ftp           x86_64           0.17-78.el8           AppStream            70 k

事务概要
================================================================================
安装  1 软件包

总计:70 k
安装大小:112 k
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                 1/1 
  安装    : ftp-0.17-78.el8.x86_64                                          1/1 
  运行脚本: ftp-0.17-78.el8.x86_64                                          1/1 
  验证    : ftp-0.17-78.el8.x86_64                                          1/1 
Installed products updated.

已安装:
  ftp-0.17-78.el8.x86_64                                                        

完毕!
[root@localhost ~]# 
[root@localhost ~]# rpm -qa |grep vsftpd
vsftpd-3.0.3-31.el8.x86_64
[root@localhost ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost ~]# 
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-11-17 08:45:48 EST; 8s ago
  Process: 4100 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCC>
 Main PID: 4101 (vsftpd)
    Tasks: 1 (limit: 11160)
   Memory: 968.0K
   CGroup: /system.slice/vsftpd.service
           └─4101 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

11月 17 08:45:48 dns.long90.cn.10.168.192.in-addr.arpa systemd[1]: Starting Vsftpd ftp daemon.>
11月 17 08:45:48 dns.long90.cn.10.168.192.in-addr.arpa systemd[1]: Started Vsftpd ftp daemon.
[root@localhost ~]# systemctl enable vsftpd
Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service.
[root@localhost ~]# 
[root@localhost ~]# firewall-cmd --permanent --add-service=ftp
success
[root@localhost ~]# firewall-cmd --reload 
success
[root@localhost ~]# 
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client dns ftp http ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
    
[root@localhost ~]# 
[root@localhost ~]# setsebool -P ftpd_full_access=on
[root@localhost ~]# 

先备份后再配置主目录

[root@localhost ~]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
[root@localhost ~]# 
[root@localhost ~]# grep -v "#" /etc/vsftpd/vsftpd.conf.bak >/etc/vsftpd/vsftpd.conf
[root@localhost ~]# 
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd.conf.bak  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# ls -al
总用量 36
drwxr-xr-x.   2 root root  111 11月 17 08:51 .
drwxr-xr-x. 141 root root 8192 11月 17 08:44 ..
-rw-------.   1 root root  125 2月  17 2020 ftpusers
-rw-------.   1 root root  361 2月  17 2020 user_list
-rw-r--r--.   1 root root  230 11月 17 08:51 vsftpd.conf
-rw-------.   1 root root 5098 2月  17 2020 vsftpd.conf.bak
-rwxr--r--.   1 root root  348 2月  17 2020 vsftpd_conf_migrate.sh
[root@localhost vsftpd]# 
[root@localhost vsftpd]# touch sample.tar
[root@localhost vsftpd]# ls
ftpusers  sample.tar  user_list  vsftpd.conf  vsftpd.conf.bak  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# ls -al
总用量 36
drwxr-xr-x.   2 root root  129 11月 17 08:54 .
drwxr-xr-x. 141 root root 8192 11月 17 08:44 ..
-rw-------.   1 root root  125 2月  17 2020 ftpusers
-rw-r--r--.   1 root root    0 11月 17 08:54 sample.tar
-rw-------.   1 root root  361 2月  17 2020 user_list
-rw-r--r--.   1 root root  230 11月 17 08:51 vsftpd.conf
-rw-------.   1 root root 5098 2月  17 2020 vsftpd.conf.bak
-rwxr--r--.   1 root root  348 2月  17 2020 vsftpd_conf_migrate.sh
[root@localhost vsftpd]# 

[root@localhost vsftpd]# 
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf

anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES

anon_root=/var/ftp
anon_upload_enable=YES
anon_mkdir_write_enable=YES
~           

放行

[root@localhost vsftpd]# setenforce 0

[root@localhost vsftpd]# firewall-cmd --permanent --add-service=ftp
Warning: ALREADY_ENABLED: ftp
success
[root@localhost vsftpd]# firewall-cmd --reload 
success
[root@localhost vsftpd]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client dns ftp http ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
    
[root@localhost vsftpd]# 

重启vsftpd服务

[root@localhost vsftpd]# systemctl restart vsftpd
[root@localhost vsftpd]# 
windows本地已经可以访问了 但是无权限添加文件

但是此时只能访问,还无权限添加文件或者创建文件夹

[root@localhost ftp]# ls -al
总用量 4
drwxr-xr-x.  3 root root   17 11月 17 08:41 .
drwxr-xr-x. 23 root root 4096 11月 10 09:03 ..
drwxr-xr-x.  2 root root   24 11月 17 09:07 pub
[root@localhost ftp]# 
####给ftp添加权限
[root@localhost ftp]# chown ftp /var/ftp/pub/
####给ftp添加权限
[root@localhost ftp]# ls -al
总用量 4
drwxr-xr-x.  3 root root   17 11月 17 08:41 .
drwxr-xr-x. 23 root root 4096 11月 10 09:03 ..
drwxr-xr-x.  2 ftp  root   39 11月 17 09:12 pub
[root@localhost ftp]# 、
已经可以创建文件了

建立维护网站内容的FTP账号team1、team2,并为其设置密码。

再建一个普通用户user1,用于做对比

[root@localhost ftp]# useradd team1;useradd team2;useradd user1
[root@localhost ftp]# passwd team1
更改用户 team1 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ftp]# 

再去配置vsftpd.conf主配置文件

[root@localhost ftp]# cat /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
#anon_root=/var/ftp
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES
local_root=/web/www/html
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YES

建立/etc/vsftpd/chroot_list文件,添加team1和team2账号

[root@localhost ftp]# cat /etc/vsftpd/chroot_list
team1
team2
[root@localhost ftp]# 

第二部分

Client客户机验证部分

查看cd /mnt/目录下有没有cdrom,没有就创建

####查看cd /mnt/目录下有没有cdrom,没有就创建
[root@localhost ~]# 
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls -al
总用量 0
drwxr-xr-x.  3 root root  18 10月 31 14:38 .
dr-xr-xr-x. 17 root root 224 10月 31 14:36 ..
drwxr-xr-x.  2 root root   6 10月 31 14:38 hgfs
[root@localhost mnt]# 
[root@localhost mnt]# mkdir cdrom
[root@localhost mnt]# ls -al
总用量 0
drwxr-xr-x.  4 root root  31 11月 17 10:00 .
dr-xr-xr-x. 17 root root 224 10月 31 14:36 ..
drwxr-xr-x.  2 root root   6 11月 17 10:00 cdrom
drwxr-xr-x.  2 root root   6 10月 31 14:38 hgfs
[root@localhost mnt]#  
[root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# 
[root@localhost ~]# ls -al /mnt/cdrom/
总用量 53
dr-xr-xr-x. 7 root root  2048 4月   4 2020 .
drwxr-xr-x. 4 root root    31 11月 17 10:00 ..
dr-xr-xr-x. 4 root root  2048 4月   4 2020 AppStream
dr-xr-xr-x. 4 root root  2048 4月   4 2020 BaseOS
-r--r--r--. 1 root root    60 4月   4 2020 .discinfo
dr-xr-xr-x. 3 root root  2048 4月   4 2020 EFI
-r--r--r--. 1 root root  8266 4月   4 2020 EULA
-r--r--r--. 1 root root  1455 4月   4 2020 extra_files.json
-r--r--r--. 1 root root 18092 4月   4 2020 GPL
dr-xr-xr-x. 3 root root  2048 4月   4 2020 images
dr-xr-xr-x. 2 root root  2048 4月   4 2020 isolinux
-r--r--r--. 1 root root   103 4月   4 2020 media.repo
-r--r--r--. 1 root root  1669 4月   4 2020 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 4月   4 2020 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 4月   4 2020 TRANS.TBL
-r--r--r--. 1 root root  1560 4月   4 2020 .treeinfo
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
0 文件已删除
[root@localhost ~]# 
[root@localhost ~]# dnf install ftp -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
BaseOS                                          551 MB/s | 2.3 MB     00:00    
AppStream                                       613 MB/s | 5.8 MB     00:00    
依赖关系解决。
================================================================================
 软件包        架构             版本                  仓库                 大小
================================================================================
安装:
 ftp           x86_64           0.17-78.el8           AppStream            70 k

事务概要
================================================================================
安装  1 软件包

总计:70 k
安装大小:112 k
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                 1/1 
  安装    : ftp-0.17-78.el8.x86_64                                          1/1 
  运行脚本: ftp-0.17-78.el8.x86_64                                          1/1 
  验证    : ftp-0.17-78.el8.x86_64                                          1/1 
Installed products updated.

已安装:
  ftp-0.17-78.el8.x86_64                                                        

完毕!
[root@localhost ~]# 

安装完ftp服务后就可以登陆了

账号密码都是在server机创建的

[root@localhost ~]# 
[root@localhost ~]# ftp 192.168.10.1
Connected to 192.168.10.1 (192.168.10.1).
220 (vsFTPd 3.0.3)
Name (192.168.10.1:root): team1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 
ftp> 
ftp> pwd
257 "/" is the current directory
ftp> ls
227 Entering Passive Mode (192,168,10,1,158,56).
150 Here comes the directory listing.
-rw-r--rw-    1 0        0               0 Nov 17 14:46 test.sample
226 Directory send OK.
ftp> 

在服务的的目录下创建文件,客户机就可以看到了。

[root@dns yum.repos.d]# cd /web/www/html/
[root@dns html]# 
[root@dns html]# ls -al
总用量 0
drwxr-xrwx. 2 root root 25 11月 17 09:46 .
drwxr-xr-x. 3 root root 18 11月 17 09:46 ..
-rw-r--rw-. 1 root root  0 11月 17 09:46 test.sample
[root@dns html]# 
[root@dns html]# touch testteam1
[root@dns html]# 
[root@dns html]# ls -al
总用量 0
drwxr-xrwx. 2 root root 42 11月 17 10:05 .
drwxr-xr-x. 3 root root 18 11月 17 09:46 ..
-rw-r--rw-. 1 root root  0 11月 17 09:46 test.sample
-rw-r--r--. 1 root root  0 11月 17 10:05 testteam1
[root@dns html]# 


####客户机上验证

ftp> ls
227 Entering Passive Mode (192,168,10,1,145,117).
150 Here comes the directory listing.
-rw-r--rw-    1 0        0               0 Nov 17 14:46 test.sample
-rw-r--r--    1 0        0               0 Nov 17 15:05 testteam1
226 Directory send OK.
ftp> 

下载文件,重命名

ftp> get test.sample test111.sample
local: test111.sample remote: test.sample
227 Entering Passive Mode (192,168,10,1,93,117).
150 Opening BINARY mode data connection for test.sample (0 bytes).
226 Transfer complete.
ftp> 
下载文件,重命名

Client上传文件

####Client端
ftp> put test111.sample  test00.sample
local: test111.sample remote: test00.sample
227 Entering Passive Mode (192,168,10,1,248,18).
150 Ok to send data.
226 Transfer complete.
ftp> 

服务端

[root@dns html]# ls -al
总用量 0
drwxr-xrwx. 2 root  root  63 11月 17 10:10 .
drwxr-xr-x. 3 root  root  18 11月 17 09:46 ..
-rw-r--r--. 1 team1 team1  0 11月 17 10:10 test00.sample
-rw-r--rw-. 1 root  root   0 11月 17 09:46 test.sample
-rw-r--r--. 1 root  root   0 11月 17 10:05 testteam1
[root@dns html]# 

不允许切换到其他目录,符合需求。

ftp> cd /home/
550 Failed to change directory.
ftp> 
上一篇 下一篇

猜你喜欢

热点阅读