配置与管理FTP服务(FTP服务器搭建实例一二)
一、FTP服务器1。
1、利用Centos镜像文件作为yum源写入本地yum配置文件
[root@centos7-1~]# mkdir /opt/centos
[root@centos7-1~]# mount /dev/cdrom /opt/centos
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos7-1~]# mv /etc/yum.repos.d/* /home/
[root@centos7-1~]# vim /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
2、查看yum源状态
[root@centos7-1 ~]# yum clean all //安装前先清除缓存
[root@centos7-1 ~]# yum repolist
3、安装ftp服务器
[root@centos7-1 ~]# yum install vsftpd -y
[root@centos7-1 ~]# yum install ftp -y //同时安装ftp软件包
[root@centos7-1 ~]# rpm -qa|grep vsftpd //检查安装组件是否成功
4、设置selinux值增强内核安全性能
[root@centos7-1~]# setenforce 0
5、防火墙设置
[root@centos7-1~]# iptables -F
[root@centos7-1~]# iptables -X
[root@centos7-1~]# iptables -Z
[root@centos7-1~]# iptables-save
[root@centos7-1~]# systemctl stop firewalld
6、ftp服务器端IP地址利用静态配置IP地址
[root@centos7-1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=9f92031e-cb20-4cde-b796-6935a082ba86
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.10.1
NETMASK=255.255.255.0
GATEWAY=192.168.10.254
7、配置fpt主配置文件
[root@centos7-1 ~]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
[root@centos7-1 ~]# grep -v "#" /etc/vsftpd/vsftpd.conf.bak > /etc/vsftpd/vsftpd.conf
[root@centos7-1 ~]# touch /var/ftp/pub/sample.tar
[root@centos7-1 ~]# vim /etc/vsftpd/vsftpd.conf
在配置文件后面加
anon_root=/var/ftp #设置匿名用户的根目录为/var/ftp
anon_upload_enable=YES #允许匿名用户上传文件
anon_mkdir_write_enable=YES #允许匿名用户创建写入目录
保存退出
8、重启ftp服务器
[root@centos7-1 ~]# systemctl restart vsftpd
[root@centos7-1 ~]# systemctl status vsftpd //查看ftp服务器状态
9、设备本地系统权限
[root@centos7-1 ~]# ll -ld /var/ftp/pub
drwxr-xr-x. 2 root root 6 Dec 4 2022 /var/ftp/pub //其他用户没有写入权限
[root@centos7-1 ~]# chown ftp /var/ftp/pub //将属主改为匿名用户ftp,
[root@centos7-1 ~]# chmod o+w /var/ftp/pub //将属主改为匿名用户ftp
[root@centos7-1 ~]# ll -ld /var/ftp/pub
drwxr-xr-x. 2 ftp root 6 Dec 4 2022 /var/ftp/pub //已将属主改为匿名用户ftp
[root@centos7-1 ~]# systemctl restart vsftpd
FTP客户端1验证
Linux客户端 (首先保障与服务器端通信正常)这里采用静态方式。
安装 ftp客户端(利用本地yum源进行安装)
[root@client1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=9f92031e-cb20-4cde-b796-6935a082ba86
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.10.10
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
[root@client1~]# mkdir /opt/centos
[root@client1~]# mount /dev/cdrom /opt/centos
mount: /dev/sr0 写保护,将以只读方式挂载
[root@client1~]# mv /etc/yum.repos.d/* /home/
[root@client1~]# vim /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[root@client1~]# yum clean all
[root@client1 ~]# yum repolist //查看yum源状态
[root@client1 ~]# yum install ftp -y
[root@client1 yum.repos.d]# ftp 192.168.10.100 // 提示:如果在Linux上测试,用户名输入:ftp,密码处直接回车即可。
Connected to 192.168.10.100 (192.168.10.100).
220 (vsFTPd 3.0.2)
Name (192.168.10.100:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
查看信息
ftp> ls
227 Entering Passive Mode (192,168,10,100,98,245).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Dec 04 21:24 sample.tar
创建目录
ftp> mkdir devil
257 "/pub/devil" created
ftp> ls
227 Entering Passive Mode (192,168,10,100,132,242).
150 Here comes the directory listing.
drwx------ 2 14 50 6 Dec 04 21:30 devil
-rw-r--r-- 1 0 0 0 Dec 04 21:24 sample.tar
二、FTP服务器2,安装步骤与服务器1一样,这里就不阐述。
修改限制本地用户权限 配置FPT主配置文件
[root@centos7-2~]#vim /etc/vsfgpd/vsfptd.conf
anonymous_enable=no
local_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
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
tcp_wrappers=YES
重启ftp服务器
[root@centos7-2 ~]# systemctl restart vsftpd
创建用户进行验证
[root@centos7-2 ~]# useradd -s /sbin/nologin team1
[root@centos7-2 ~]# useradd -s /sbin/nologin team2
[root@centos7-2 ~]# useradd -s /sbin/nologin user1
[root@centos7-2 ~]# passwd team1
[root@centos7-2 ~]# passwd team2
[root@centos7-2 ~]# passwd user1
将权限被限制的用户添加到列表文件
[root@centos7-2 ~]# vim /etc/vsftpd/chroot_list
team1
team2
防火墙放行和SELinux允许!重启FTP服务。
[root@centos7-2 ~]# firewall-cmd --permanent --add-service=ftp
[root@centos7-2 ~]# firewall-cmd --reload
[root@centos7-2 ~]# firewall-cmd --list-all
[root@centos7-2 ~]# setenforce 0
[root@centos7-2 ~]# systemctl restart vsftpd
创建主目录
[root@centos7-2 ~]# mkdir /web/www/html -p //主配置的指定目录
[root@centos7-2 ~]# touch /web/www/html/test.sample
[root@centos7-2 ~]# ll -d /web/www/html
[root@centos7-2 ~]# chmod -R o+w /web/www/html //其他用户可以写入!
[root@centos7-2 ~]# ll -d /web/www/html
FTP客户端2验证(安装方式与FTP客户端1一样,这里就不在一一赘述了!)
使用team1和team2用户不能转换目录,但能建立新文件夹,显示的目录是“/”,其实是/web/www/html文件夹!
[root@client2 ~]# ftp 192.168.10.1
Connected to 192.168.10.1 (192.168.10.1).
220 (vsFTPd 3.0.2)
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> pwd
257 "/" //显示是“/”,其实是/web/www/html,从列示的文件中就知道。
ftp> mkdir testteam1
257 "/testteam1" created
ftp> ls
227 Entering Passive Mode (192,168,10,1,46,226).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Dec 4 00:21 test.sample
drwxr-xr-x 2 1001 1001 6 Dec 4 02:15 testteam1
226 Directory send OK.
ftp> cd /etc
550 Failed to change directory. //不允许更改目录
ftp> exit
221 Goodbye.
使用user1用户,能自由转换目录,可以将/etc/passwd文件下载到主目录,何其危险啊!
[root@client2 ~]# ftp 192.168.10.1
Connected to 192.168.10.1 (192.168.10.1).
220 (vsFTPd 3.0.2)
Name (192.168.10.1:root): user1 //列表外的用户是自由的
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/web/www/html"
ftp> mkdir testuser1
257 "/web/www/html/testuser1" created
ftp> cd /etc //成功转换到/etc目录
250 Directory successfully changed.
ftp> get passwd //成功下载密码文件passwd到/root,可以退出后查看
local: passwd remote: passwd
227 Entering Passive Mode (192,168,10,1,80,179).
150 Opening BINARY mode data connection for passwd (2203 bytes).
226 Transfer complete.
2203 bytes received in 9e-05 secs (24477.78 Kbytes/sec)
ftp> cd /web/www/html
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,10,1,182,144).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Dec 4 00:21 test.sample
drwxr-xr-x 2 1001 1001 6 Dec 4 02:15 testteam1
drwxr-xr-x 2 1003 1003 6 Dec 4 04:10 testuser1
226 Directory send OK.