LINUX系统配置FTP服务器教程

首先,我们要安装搭建好一个linux服务器。

然后是将该服务器配置成FTP服务器。

具体操作如下:

1.检查是否安装vsftpd

rpm -qa | grep vsftpd

其实这一步也没啥乱用,就看一下,rpm命令是否可以使用,vsftpd的版本号而已。 

2.安装 vsftpd

yum -y install vsftpd

报错了:

错误:运行此命令需要管理员特权(多数系统下是root用户)。

 原因是我的这个账号不是管理员,那我们 修改命令再操作:
 

sudo yum -y install vsftpd

 命令!!的意思就是重复上一条执行的命令,所以我的  sudo !! 的下面显示的就是我们真正要执行的命令。输入密码之后自动安装。

命令解释:

yum:在线安装,所以你的电脑必须联网;

-y:一路yes,避免询问;

install:安装的命令

vsftpd:是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点。vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux、BSD、Solaris、 HP-UNIX等系统上面,是一个完全免费的、开放源代码的ftp服务器软件,支持很多其他的 FTP 服务器所不支持的特征。比如:非常高的安全性需求、带宽限制、良好的可伸缩性、可创建虚拟用户、支持IPv6、速率高等。

3、关闭匿名访问

关闭匿名访问后,想访问里面的文件就需要账号和密码;如果不关,就可以直接访问。所以,这一步是可选操作。

vim /etc/vsftpd/vsftpd.conf

如果提示是只读文件,那么你只需要输入命令:

sudo  vim /etc/vsftpd/vsftpd.conf

打开之后的页面显示如下:

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600

关闭匿名访问就是将:anonymous_enable=NO

我们输入  i ,然后找到这个对应的字段,修改为NO即可。然后输入  ESC,再输入  :wq! 最后回车即可。  

我这里的默认就是anonymous_enable=NO,我们不做修改。如果你的这个文件的这个字段的取值是YES,同时你想禁止匿名访问,把它该成NO即可。

当然还有其他的配置可以修改,我们这里就先修改匿名访问的配置。

3、启动服务

systemctl start vsftpd.service

4、查看服务状态

启动之后我们可以查看服务的状态,看看启动是否成功:

systemctl status vsftpd.service

 我们看到绿色的  active(running),代表着启动成功正在运行中。

我们按  q 或者Ctrl + c 退出这个显示页面,回到命令行。

5、开放访问端口

启动成功之后我们可以在服务器上访问了,但是如果我们要在电脑上访问的话还是不行的,因为这个存在防火墙的问题,此时就需要打开相应端口的防火墙了。

# 开启21端口访问权
firewall-cmd --zone=public --add-port=21/tcp --permanent
#开启1025-65535端口访问权
firewall-cmd --zone=public --add-port=1025-65535/tcp --permanent
# 重启防火墙
systemctl restart firewalld

切记:最后一个命令的  firewall后面有个d,不然会报错:

Failed to restart firewall.service: Unit firewall.service not found.

 此时我们可以通电脑去查看对应FTP服务器的情况了,在电脑上输入:

ftp://192.168.xx.xx

上面是你的服务器的ip,然后显示页面如下:

 

 输入用户名密码并保存密码,登陆之后的页面如下:

上图中的file目录是我自己之前在服务器上创建的,其他的都是服务器安装时生成的目录。 

6、新增用户

我们可以创建一个用户用于FTP操作,因为在Linux上,root用户是不能登陆FTP的。如果你输入的是root用户,登陆会失败的。

adduser fangdake01

上面是创建的用户名:fangdake01

给fangdake01设置密码:

passwd fangdake01

输入两次密码就ok了。

至此为止我们的FTP服务器搭建完了,怎么验证呢?我们把一个文件拖到ftp的某一个地方,比如:

 然后我们去服务器上看看:

 文件确实上传上去了,同时所在的目录也是正确的。

至此,我们的FTP服务器搭建完毕。

我们还可以通过ftp连接工具去打开,我们这里使用Xftp 7连接:

 

fangdake01是我们刚才创建的用户,登陆之后发现在该用户自己的目录下,什么都没有,因为这个是我们刚创建一个普通用户而已。如果我们使用fangdake来登陆的话,发现就不一样了。我们可以访问对应的目录,比如以临时目录文件来说:

 至此,说明通过ftp连接工具也是可以正常访问我们的ftp服务器了。那么我么的FTP服务器就搭建好了。

服务器搭建好之后,默认不是开机自动启动的,我们需要设置开机启动。网上找了不少方法,有不少都不行,可能与我的虚拟机版本有问题,我的是CentOS 8 Stream版本的。

最终可行的方法是:

chkconfig vsftpd on

 但是这个命令好像被废弃了,直接转发到其他命令上了。

[fangdake@CentOS-8-FTP file]$ chkconfig vsftpd on
注意:正在将请求转发到“systemctl enable vsftpd.service”。
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ====
Authentication is required to manage system service or unit files.
Authenticating as: fangdake
Password: 
==== AUTHENTICATION COMPLETE ====
Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service.
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ====
Authentication is required to reload the systemd state.
Authenticating as: fangdake
Password: 
==== AUTHENTICATION COMPLETE ====
 

 也就是说将命令转发到了“systemctl enable vsftpd.service”上面。我们输入密码即可。或者Ctrl + c退出,然后使用命令:

systemctl enable vsftpd.service

然后输入两次密码即可。 

最后,需要说明的是:

1.原始的服务器的网络适配器必须是桥接模式;

2.必须联网,因为要联网安装。

要在Linux系统上配置FTP服务器,你可以按照以下步骤进行操作: 1. 安装FTP服务器软件:常用的FTP服务器软件有vsftpd、ProFTPD等。例如,如果你使用的是Debian或Ubuntu系统,可以通过以下命令安装vsftpd: ``` sudo apt-get install vsftpd ``` 2. 配置FTP服务器:编辑FTP服务器配置文件以进行必要的设置。对于vsftpd,配置文件位于`/etc/vsftpd.conf`。你可以使用文本编辑器打开该文件,例如: ``` sudo vim /etc/vsftpd.conf ``` 3. 根据需要进行配置:以下是一些常见的配置选项: - `anonymous_enable=YES`:启用匿名访问(可选)。 - `local_enable=YES`:允许本地用户访问FTP服务器。 - `write_enable=YES`:允许用户上传文件到服务器。 - `chroot_local_user=YES`:限制本地用户的访问范围为其主目录。 - `local_umask=022`:设置默认的文件权限为022。 - `pasv_min_port=xxxx`和`pasv_max_port=yyyy`:指定被动模式下使用的端口范围(可选)。 根据你的需求修改这些选项并保存文件。 4. 重新启动FTP服务器:保存配置文件后,重新启动FTP服务器以使更改生效。使用以下命令重启vsftpd服务: ``` sudo systemctl restart vsftpd ``` 5. 配置防火墙规则:如果你的系统上启用了防火墙,确保允许FTP流量通过。例如,如果你使用的是iptables防火墙,可以使用以下命令打开FTP端口(默认为21): ``` sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT ``` 以上步骤完成后,你的Linux系统上的FTP服务器应该已经配置好了。你可以使用FTP客户端软件连接到服务器并进行文件传输。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北冥牧之

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值