大家好,今天来给大家分享一个基于centos 7的ftp服务器搭建
实现功能:匿名访问,本地登录
查看系统版本:
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
查看本地ip地址
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.5 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 240e:3a2:743:df40:bb08:8c86:f745:edd4 prefixlen 64 scopeid 0x0<global>
inet6 fe80::617f:ef93:80d4:e14e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:87:af:a6 txqueuelen 1000 (Ethernet)
RX packets 50282 bytes 3247879 (3.0 MiB)
RX errors 0 dropped 922 overruns 0 frame 0
TX packets 6542 bytes 8519343 (8.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我们连一下xshell (远程控制终端)
[C:\~]$ ssh 192.168.1.5
Connecting to 192.168.1.5:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Sat Oct 23 11:15:44 2021 from 192.168.1.2
[root@localhost ~]#
测试网络:
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=54 time=10.0 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=54 time=9.79 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=3 ttl=54 time=7.52 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=4 ttl=54 time=8.06 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 22033ms
rtt min/avg/max/mdev = 7.523/8.862/10.065/1.094 ms
这样的话,我们的服务器就可以上网了 (可使用网络yum源)
接下来我们安装vsftpd服务程序
[root@localhost ~]# yum install vsftpd.x86_64 -y
进入vsftpd主目录
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@localhost vsftpd]#
将主配置文件内容当中#全部去掉
[root@localhost vsftpd]# cat vsftpd.conf |grep -v "#"
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
tcp_wrappers=YES
这些是有效地配置文件,我们需要对它进行改动
对主配置文件改名为vsftpd.conf.bak
[root@localhost vsftpd]# mv vsftpd.conf vsftpd.conf.bak
查看
[root@localhost vsftpd]# ls
ftpusers user_list vsftpd.conf.bak vsftpd_conf_migrate.sh
将vsftpd.conf.bak的#号过滤掉,将这个结果过滤到vsftp.conf
[root@localhost vsftpd]# cat vsftpd.conf.bak |grep -v "#" >vsftpd.conf
编辑vsftpd 主配置文件
[root@localhost vsftpd]# vim vsftpd.conf
anon_umask=022
anon_update_enable=YES
anon_nkdir_write_enable=YES
anon_other_write_enable=YES //将这四行的配置文件加入vsftpd.conf,(实现匿名访问)
如下
anonymous_enable=YES
anon_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_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
tcp_wrappers=YES
:wq
保存退出
重启ftp服务器:
[root@localhost vsftpd]# systemctl restart vsftpd
[root@localhost vsftpd]# systemctl enable vsftpd.service //设置开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@localhost vsftpd]#
[root@localhost vsftpd]# systemctl stop firewalld //关闭防火墙
本地测试,显示vsftpd服务器正常
[root@localhost vsftpd]# cd /var/ftp/
[root@localhost ftp]# ls
pub(本来就有的文件)
[root@localhost ftp]#
[root@localhost ftp]# touch 123.txt //创建文件123.txt
[root@localhost ftp]#
创建文件报错,(权限不够)
[root@localhost ftp]# chmod 777 pub/ //加权限
匿名用户访问成功
开始做本地用户
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf //编辑配置文件
anonymous_enable=YES
anon_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_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
tcp_wrappers=YES //这是我们刚刚编辑的配置文件
按箭头去修改
改成:
或者注释掉这四行也是一样的效果:
anonymous_enable=NO
#anon_umask=022
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES
#anon_other_write_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
tcp_wrappers=YES
编辑这个文件
[root@localhost vsftpd]# vim ftpusers
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
根据具体要求,删掉你想登录FTP服务的本地用户。
例如,删掉root。
# Users that are not allowed to login via ftp
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
~
[root@localhost vsftpd]# systemctl restart vsftpd //重启vsftpd 服务
实验成功。测试的时候,既可以用windows的文件搜索,也可以用第三方工具