CentOS7 FTP服务搭建(虚拟用户访问FTP服务)

概述

最近在搞Oracle在Linux系统下集群,针对Linux系统,笔人也是一片空白。Liunx外部文件的传输,避免不了使用FTP服务,所以现在就整理下,CentOS7环境下,FTP服务的搭建。FTP服务器需要安装vsftp服务端软件。我们知道,在建立vsftpd用户时,我们一般是在linux下建立用户useradd的方式来访问ftp,但有时我们只想提供ftp服务,而避免用户用ftp的帐号去登录linux,采用一般的方式只能是限制该用户的访问权限,但还是避免不了用户登录进linux系统,所以比较好的方法是用vsftpd的虚拟用户(virtual users)。

开始部署:

[root@localhost /]# yum  clean all       #清除yum缓存
[root@localhost /]# yum -y install vsftpd*           #安装vsftpd
#配置本地yum仓库或指向互联网都可。
[root@localhost /]# vim /etc/vsftpd/vusers.list      #创建文本格式的用户名/密码列表

下面写入虚拟账号,其中,奇数行为用户名,偶数行为上一行中用户所对应的密码。

mike
123
john
456

写完保存退出即可,上面添加了两个虚拟用户,mike的密码是123,John的密码是456。

#
[root@localhost /]# cd /etc/vsftpd/
[root@localhost vsftpd]# db_load -T -t hash -f vusers.list vusers.db  #创建Berkeley DB格式的数据库文件
[root@localhost vsftpd]# chmod 600 /etc/vsftpd/vusers.*     #为保证数据安全,所以更改下权限
[root@localhost vsftpd]# useradd -d /var/ftproot -s /sbin/nologin test          #添加虚拟用户的映射账号
[root@localhost vsftpd]# chmod 777 /var/ftproot/
[root@localhost vsftpd]# vim /etc/pam.d/vsftpd.vu          为虚拟用户建立PAM认证文件
auth    required        pam_userdb.so db=/etc/vsftpd/vusers
account required        pam_userdb.so db=/etc/vsftpd/vusers

写完上面两行,保存退出即可

[root@localhost vsftpd]# mkdir /etc/vsftpd/vusers_dir        #为不同的虚拟用户建立独立的配置文件
[root@localhost vsftpd]# cd /etc/vsftpd/vusers_dir/
[root@localhost vusers_dir]# vim john    #写入john用户的权限
anon_upload_enable=YES
anon_mkdir_write_enable=YES

写完上面两行,保存退出即可

[root@localhost vusers_dir]# cp john mike           #给用户mike复制一份
[root@localhost vusers_dir]# vim /etc/vsftpd/vsftpd.conf     #编辑主配置文件为如下

我为了使主配置文件简洁一些,注释类的配置我都删除了,以下为我这里主配置文件的所有内容

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.vu
userlist_enable=YES
tcp_wrappers=YES
guest_username=test
guest_enable=YES
allow_writeable_chroot=YES
anon_world_readable_only=NO
anon_other_write_enable=YES
user_config_dir=/etc/vsftpd/vusers_dir

将主配置文件更改为如上,即可保存退出。

最后重启vsftpd服务器

[root@localhost ~]# systemctl start vsftpd                    #启动vsftpd服务,使用客户端访问验证即可

可通过  tail -f /var/log/secure 指令,查看服务器安全日志,便于分析错误问题,设置操作效果一定要仔细…..

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code