Linux系统上安装FTP服务

文章背景

最近为了调试Linux系统FTP传输工具,刚好有Linux虚拟机环境,于是就搭建了vsftpd服务。

使用环境

Linux系统:BigCloud Enterprise Linux 7.8 (Core)

安装

1. 查询是否安装vsftpd

[root@localhost ~]# rpm -qa | grep vsftpd

2. 安装vsftpd

[root@localhost ~]# yum install vsftpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.01link.hk
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-27.el7 将被 安装
--> 解决依赖关系完成
>>>>>>>>>>>>>>> 安装过程省略 <<<<<<<<<<<<<<<<
Running transaction
  正在安装    : vsftpd-3.0.2-27.el7.x86_64                                                                        1/1 
  验证中      : vsftpd-3.0.2-27.el7.x86_64                                                                        1/1 

已安装:
  vsftpd.x86_64 0:3.0.2-27.el7                                                                                        

完毕!
[root@localhost ~]# 

3. 确认安装

[root@localhost ftptest]# rpm -qa | grep vsftpd
vsftpd-3.0.2-27.el7.x86_64
[root@localhost ftptest]# 

配置

1. 配置/etc/vsftpd/user_list

[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
[root@localhost vsftpdt]# vim user_list 

打开user_list文件如下所示

# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
ftptest

如上在文件末尾添加了ftptest用户,ftptest是我新建的Linux系统用户。

重要:文件头中提示,只有在配置文件中写上userlist_deny=NO,才能使用这个文件列表中的配置。所以我们需要在vsftpd.conf文件中进行配置。

2. 配置vsftpd.conf

[root@localhost vsftpd]# vim vsftpd.conf

打开配置文件如下(已经删除注释部分),并在文件末尾添加userlist_deny=NO

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
tcp_wrappers=YES
userlist_deny=NO

如上所示,我们将匿名允许anonymous_enable配置为NO,然后将userlist_enable配置为YES,软后添加userlist_deny=NO
这样我们的user_list表就生效了。

调试连接

1. 启动vsftpd服务

[root@localhost ~]# service vsftpd start
Redirecting to /bin/systemctl start vsftpd.service
[root@localhost ~]# service vsftpd status

2. 查看状态和端口

[root@localhost ~]# service vsftpd status
Redirecting to /bin/systemctl status vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 一 2023-10-23 09:44:10 CST; 20s ago
  Process: 34251 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 34252 (vsftpd)
    Tasks: 1
   Memory: 620.0K
   CGroup: /system.slice/vsftpd.service
           └─34252 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

10月 23 09:44:10 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
10月 23 09:44:10 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.
[root@localhost ~]# 
[root@localhost ~]# netstat -nltp | grep 21
tcp6       0      0 :::21                   :::*                    LISTEN      34252/vsftpd

如上,状态为(running),已经在侦听21端口。

3. 使用FileZilla客户端进行连接测试

FileZilla连接失败

发现无法连接vsftpd服务,这是由于Linux系统防火墙的原因,将ftp服务添加到防火墙例外中就可以了

4. 添加ftp服务到防火前例外

[root@localhost ~]# firewall-cmd --zone=public --add-service=ftp
success
[root@localhost ~]#

5. 再次连接

FileZilla连接成功

如上,已经连接成功,接下来就可以传输文件和调试代码了。

好了,Linux服务器上安装ftp服务就分享到这里,感谢翻阅,希望帮到你。

猜你喜欢

转载自blog.csdn.net/weixin_44131612/article/details/133984753
今日推荐