FTP服务

发布时间 2023-12-14 22:06:56作者: q_7

大致的流程:

1:安装ftp的安装包

2:创建一个ftp共享文件和给予权限

3:编写ftp的配置文件

4:防火墙和selinux的设置

5:linux访问和windows访问,创建文件上传文件,下载文件

权限全部都开着

服务器:

1:安装ftp的安装包和创建共享文件给予权限

创建了一个用于上床的文件夹upload,

[root@controller /]# yum -y install vsftpd
[root@controller /]# systemctl start vsftpd
[root@controller /]# systemctl enable vsftpd
[root@controller /]# netstat -pant|grep 21
tcp        0      0 192.168.20.110:46420    151.101.1.91:443        ESTABLISHED 2219/gnome-shell    
tcp6       0      0 :::21                   :::*                    LISTEN      3411/vsftpd         
[root@controller /]# 
[root@controller /]# mkdir /ftp-share
[root@controller /]# touch /ftp-share/ftp-flag
[root@controller /]# mkdir /ftp-share/upload
[root@controller /]# chmod o+w /ftp-share/upload/
[root@controller /]# ll /ftp-share/upload/ -d
drwxr-xrwx. 2 root root 6 Dec 15 21:21 /ftp-share/upload/
[root@controller /]# 

 

2:编写ftp的配置文件

[root@controller /]# vim /etc/vsftpd/vsftpd.conf 
anonymous_enable=YES
anon_root=/ftp-share  #ftp的共享文件
anon_upload_enable=YES #允许上传文件的权限
anon_mkdir_write_enable=YES #允许创建文件夹
anon_other_write_enable=YES # 允许进行重名或删除,移动等操作 
[root@controller /]# systemctl restart vsftpd

 

3:防护墙和selinxu的设置

主要就是利用防火墙的富规则来设置一些权限,0.0.0.0/0对于所有的网段能够访问

selinux的就是设置2个一个是允许连接,另一个是允许在在其ftp的根目录下有写的权限

[root@controller /]# firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=0.0.0.0/0 service name=ftp accept'
success
[root@controller /]# firewall-cmd --reload 
success
[root@controller /]# semanage boolean -l |grep ftpd
ftpd_anon_write                (off  ,  off)  Allow ftpd to anon write
ftpd_connect_all_unreserved    (off  ,  off)  Allow ftpd to connect all unreserved
ftpd_connect_db                (off  ,  off)  Allow ftpd to connect db
ftpd_full_access               (off  ,  off)  Allow ftpd to full access
ftpd_use_cifs                  (off  ,  off)  Allow ftpd to use cifs
ftpd_use_fusefs                (off  ,  off)  Allow ftpd to use fusefs
ftpd_use_nfs                   (off  ,  off)  Allow ftpd to use nfs
ftpd_use_passive_mode          (off  ,  off)  Allow ftpd to use passive mode
[root@controller /]# setsebool -P ftpd_full_access on
[root@controller /]# setsebool -P ftpd_anon_write on

 

 

客户端

1:linux访问

[root@nodes1 /]# yum -y install lftp   #访问ftp
[root@nodes1 /]# lftp 192.168.10.110
lftp 192.168.10.110:~> ls
-rw-r--r--    1 0        0               0 Dec 15 13:21 ftp-flag
drwxr-xrwx    3 0        0              16 Dec 15 13:51 upload
lftp 192.168.10.110:/> get ftp-flag 
lftp 192.168.10.110:/> ls
-rw-r--r--    1 0        0               0 Dec 15 13:21 ftp-flag
drwxr-xrwx    3 0        0              16 Dec 15 13:51 upload
lftp 192.168.10.110:/> cd upload/
lftp 192.168.10.110:/upload> mkdir 33
mkdir ok, `33' created
lftp 192.168.10.110:/upload> rm -rf 33
rm ok, `33' removed
lftp 192.168.10.110:/upload> ls
drwx------    2 14       50              6 Dec 15 13:51 11

 

可以输入help寻求帮助

2:windows访问

在网络中访问 

 

总结:

就是ftp的根目录下,默认是不允许有些的操作,如果在ftp共享文件设置了有写的权限,会连接不上去,所以就是在连接上去了,再来开放共享文件夹的写的权限(对于其他的用户),还有设置selinux的ftp的写的设置,就能实现在ftp的根目录下有写的权限