FTP服务器搭建(centos)

本文详细介绍了在CentOS系统中搭建FTP服务器的步骤,包括开启管理员权限、安装vsftpd、配置vsftpd.conf文件、开启SELinux权限、调整iptables规则以及处理可能遇到的问题。通过这些步骤,即使在局域网环境下也能成功运行FTP服务器。
摘要由CSDN通过智能技术生成

FTP服务器的搭建

1.开启管理员权限

su root

输入密码即可。

2.安装vsftpd。我们使用vsftpd(vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux, BSD, Solaris, HP-UX 以及 IRIX 上面。它支持很多其他的 FTP 服务器不支持的特征。)
安装vsftpd:

yum -y install vsftpd

如果你已经安装了vsftpd,只需要进行一些配置了(在下面)。
如何检测是否安装了vsftpd?

rpm -qa | grep vsftpd

如果没有显示类似如下:
[root@wjl Desktop]# rpm -qa | grep vsftpd
vsftpd-2.2.2-24.el6.x86_64

说明没有安装vsftpd
安装vsftpd过程中,需要选择的地方,全部选择y。

3.配置vsftpd
打开vsftpd.conf配置文件

vi /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.
#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
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
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
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
#
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#

按Esc,然后:+ wq,保存相关配置。

4.开启selinux权限

查看命令:

getsebool -a | grep ftp

将显示的
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftpd_connect_db --> off
ftpd_use_passive_mode --> off
ftp_home_dir --> off

中ftp_home_dir和allow_ftpd_full_access必须为on 才能使vsftpd 具有访问ftp根目录,以及文件传输等权限。
设置方式:setsebool -p xxx on

因为ftp默认的端口为21,而centos默认是没有开启的,所以要修改iptables文件,设置:

vi /etc/sysconfig/iptables

把有22 -j ACCEPT 的那一行复制一下,只是把22换成21,粘贴在下面,然后:wq保存。
因为我是在局域网下使用,所以直接关闭了防火墙=-=,偷了个小懒

service iptables stop

5.此时,配置基本完成,此时运行vsftpd,会发现可能还是被拒绝,没有关系,重启一下电脑,再次打开vsftpd,完成!(记得使用管理员权限,如果打开失败,就先试下关闭)
打开:

service vsftpd start

重启:

service vsftpd restart

关闭:

service vsftpd stop

局域网下实测可以运行,后续会持续更改博客中的问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值