配置vsftp通过openldap认证

本文涉及的产品
运维安全中心(堡垒机),免费版 6个月
运维安全中心(堡垒机),企业双擎版 50资产 7天
简介:

ftp服务器用过的肯定不少,虽然可能有很多公司已经摒弃不用,网上也有很多其他方案可以替代,但是还是有些特别的用途,还是有一定的用武之地的。在部署了ldap之后,我们当然想尽可能多的将生产范围内的其他系统或应用的认证都对接到ldap上来,所以这一次来使用ldap认证登录vsftp。

1、准备工作

1
2
3
4
5
6
7
8
9
#停止iptables,并查看iptables状态
/etc/init .d /iptables  stop
iptables -L -n
#禁用SELinux,并查看SELinux状态
setenforce 0
getenforce
#编辑/etc/hosts,添加openldap server的记录
echo  "192.168.49.138   ldapsrv01.contoso.com"  >> /etc/hosts
#添加成功后,最好ping一下,看是否能解析正常

2、安装相关的软件包

1
2
yum -y  install  vsftpd  ftp
yum -y  install  nss-pam-ldapd pam_ldap

3、配置/etc/pam_ldap.conf

[root@server136 ~]# cp /etc/pam_ldap.conf /etc/pam_ldap.conf.bak$(date +%F)

[root@server136 ~]# egrep -v "#|^$" /etc/pam_ldap.conf 

host 127.0.0.1

base dc=example,dc=com

[root@server136 ~]# sed -i '/^host/s/host/#host/' /etc/pam_ldap.conf 

[root@server136 ~]# sed -i '/^base/s/base/#base/' /etc/pam_ldap.conf 

[root@server136 ~]# egrep -v "#|^$" /etc/pam_ldap.conf 

[root@server136 ~]# echo "host  192.168.49.138" >>/etc/pam_ldap.conf 

[root@server136 ~]# echo "base  dc=contoso,dc=com" >>/etc/pam_ldap.conf 

[root@server136 ~]# echo "binddn  cn=admin,dc=contoso,dc=com" >>/etc/pam_ldap.conf 

[root@server136 ~]# echo "bindpw  123456" /etc/pam_ldap.conf 

[root@server136 ~]# egrep -v "#|^$" /etc/pam_ldap.conf 

host  192.168.49.138

base  dc=contoso,dc=com

binddn  cn=admin,dc=contoso,dc=com

bindpw  123456

4、配置/etc/vsftpd/vsftpd.conf

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak$(date +%F)

vi /etc/vsftpd/vsftpd.conf

[root@server136 ~]# diff /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak2016-09-12 

12c12

< anonymous_enable=NO

---

> anonymous_enable=YES

28d27

< anon_upload_enable=YES

33d31

< anon_mkdir_write_enable=YES

103,104d100

< chroot_local_user=YES

< #

124,126d119

< guest_enable=YES

< guest_username=ftp

< local_root=/opt/data

5、配置/etc/pam.d/vsftpd

cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak$(date +%F)

[root@server136 ~]# cat /etc/pam.d/vsftpd

#%PAM-1.0

session    optional     pam_keyinit.so    force revoke

session    optional     pam_ldap.so

auth       sufficient   pam_ldap.so

auth       required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

auth       required pam_shells.so

auth       include password-auth

account    sufficient   pam_ldap.so

account    include password-auth

session    required     pam_loginuid.so

session    include password-auth

password   required     pam_ldap.so

6、创建ftp根目录并启动vsftpd服务

1
2
3
4
mkdir  -p  /opt/data
chown  -R  ftp : ftp  /opt/data
chkconfig vsftpd on
/etc/init .d /vsftpd  start

7、使用ftp客户端测试

[root@server136 ~]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 2.2.2)

Name (127.0.0.1:root): charleslv

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp>

#ldap用户登录成功

[root@server136 ~]# useradd user1

[root@server136 ~]# echo "111111" |passwd --stdin user1

Changing password for user user1.

passwd: all authentication tokens updated successfully.

[root@server136 ~]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 2.2.2)

Name (127.0.0.1:root): user1

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> 

#本地用户登录成功



本文转自 jerry1111111 51CTO博客,原文链接:http://blog.51cto.com/jerry12356/1852080,如需转载请自行联系原作者

相关文章
|
缓存 Linux 开发工具
CentOS 7- 配置阿里镜像源
阿里镜像官方地址http://mirrors.aliyun.com/ 1、点击官方提供的相应系统的帮助 :2、查看不同版本的系统操作: 下载源1、安装wget yum install -y wget2、下载CentOS 7的repo文件wget -O /etc/yum.
250920 0
|
存储 安全 Linux
Podman入门全指南:安装、配置与运行容器
Podman入门全指南:安装、配置与运行容器
7144 1
|
网络协议 Java 网络安全
基于Spring Boot的LDAP开发全教程
基于Spring Boot的LDAP开发全教程
2142 0
|
网络协议 Unix Linux
Linux NSS简解
Linux NSS简解
|
存储 数据采集 JSON
彻底搞懂监控系统,使用Prometheus +Grafana搭建完整的应用监控系统
监控是运维系统的基础,我们衡量一个公司/部门的运维水平,看他们的监控系统就可以了。一个完善的监控系统可以提高应用的可用性和可靠性,在提供更优质服务的前提下,降低运维的投入和工作量,为用户带来更多的商业利益和客户体验。下面就带大家彻底搞懂监控系统,使用Prometheus +Grafana搭建完整的应用监控系统。
15527 1
彻底搞懂监控系统,使用Prometheus +Grafana搭建完整的应用监控系统
|
存储 Ubuntu Unix
Docker系列第03部分:列出镜像+搜索镜像+拉取镜像+删除镜像
Docker镜像是由文件系统叠加而成(是一种文件的存储形式)。最底端是一个文件引导系统,即bootfs,这很像典型的Linux/Unix的引导文件系统。Docker用户几乎永远不会和引导系统有什么交互。实际上,当一个容器启动后,它将会被移动到内存中,而引导文件系统则会被卸载,以留出更多的内存供磁盘镜像使用。Docker容器启动是需要的一些文件,而这些文件就可以称为Docker镜像。
12922 1
|
Linux 网络安全 开发工具
通过nexus3部署公司内部的私有npm仓库:从安装到配置、从发布包到测试包的一条龙服务
登录时使用默认用户admin,密码不知道就需要找默认的,点击Sign in时会提示你路径,这里我是这样查的,在linux服务器上输入以下命令
3838 0
|
Docker 容器
docker 镜像源大全
docker 镜像源大全
103406 3
docker 镜像源大全