Akemi

统一认证FreeIPA

2025/10/13

集中认证服务器的类型

  • 基于LDAP的集中认证系统
    LDAP是一种常用的集中认证方式,将信息存储在LDAP目录中,具有层次化结构,便于组织和管理大量用户数据
  • 基于kerberos的集中认证系统
    kerberos是一种网络认证协议,使用票据来验证用户身份,有一个专门的kerberos服务器负责颁发和管理票据
  • 基于OAuth或OpenID Connect的集中认证系统(互联网APP常用)
    用于互联网应用和云服务中的身份认证与授权。
    OAuth允许用户授权第三方应用访问其在另一个服务提供商上的资源
    OpenID Connect在OAuth基础上,提供了简单的身份验证机制
1
2
3
4
5
6
7
8
9
10
11
12
13
集中认证系统技术演进

├── 企业内网时代
│ ├── LDAP (用户信息存储)
│ ├── Kerberos (强认证协议)
│ └── FreeIPA/Samba AD (集大成者)

├── Web单点登录时代
│ └── SAML (企业级SSO标准)

└── 现代互联网时代
├── OAuth 2.0 (授权框架)
└── OpenID Connect (认证层,基于OAuth)
特性 FreeIPA Samba AD (作为DC) OpenLDAP
核心定位 一体化的Linux身份管理 开源的Active Directory替代品 灵活轻量的LDAP目录服务
管理Linux 完美 优秀 优秀 (需额外配置)
管理Windows 良好 (需建立信任) 完美 (原生支持) 基础 (仅LDAP)
易用性 中低
一体化程度 高 (集成DNS, CA等) 高 (集成DNS, CA等) 低 (需自行集成)
主要协议基础 LDAP + Kerberos LDAP + Kerberos 纯LDAP
详细说明 集成了完整的LDAP目录服务和Kerberos认证,是典型的企业内网统一认证系统 完全模拟Windows AD,核心就是LDAP目录+Kerberos认证协议 提供基础的目录服务,通常需要与其他组件(如Kerberos)配合完成完整认证

FreeIPA

在FreeIPA中,我们使用Kerberos领域(realm)和DNS域(domain)来构建一个统一认证系统。

  • Kerberos领域(realm):这是Kerberos认证系统使用的标识,通常是大写的域名。例如,COMPANY.LOCAL。
  • DNS域(domain):这是标准的DNS域名,例如company.local。

如果将FreeIPA服务器的领域设置为COMPANY.LOCAL,域名设置为company.local

那么客户端也应该使用company.local作为其DNS搜索域,并且主机名应该是该域名下的一个FQDN(完全合格域名),例如client1.company.local。

部署freeipa-server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 环境初始化
hostnamectl set-hostname ipa-server.company.local && bash
timedatectl set-timezone Asia/Shanghai
systemctl disable firewalld.service --now

# ipa-server
yum -y install freeipa-server freeipa-server-dns freeipa-client

#
ipa-server-install 参数说明
--realm # 指定 Kerberos 领域
--ds-password # 设置目录服务器密码
--admin-password # 设置管理员账户密码
--unattended # 无人值守模式
--setup-dns # 集成bind作为权威dns服务器
--auto-forwarders # 开启dns后,使用本机dns配置作为外部dns转发器

ipa-server-install \
--realm COMPANY.LOCAL \
--domain company.local \
--ds-password wangsheng12345 \
--admin-password wangsheng \
--hostname ipa-server.company.local \
--setup-dns \
--auto-forwarders \
--unattended

在windows上添加解析:
10.163.2.100 ipa-server.company.local
通过网页访问:
https://ipa-server.company.local
用户admin
密码wangsheng

创建用户

创建用户可以在web端进行手动创建,也可以通过命令行进行创建,这里介绍使用命令行创建的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# ipa-server
kinit admin
# 添加用户
ipa user-add xhy --first=xue --last=huiying --email=test@example.com --password
Password:
Enter Password again to verify:
----------------
Added user "xhy"
----------------
User login: xhy
First name: xue
Last name: huiying
Full name: xue huiying
Display name: xue huiying
Initials: xh
Home directory: /home/xhy
GECOS: xue huiying
Login shell: /bin/sh
Principal name: xhy@COMPANY.LOCAL
Principal alias: xhy@COMPANY.LOCAL
User password expiration: 20251011081813Z
Email address: test@example.com
UID: 1251600003
GID: 1251600003
Password: True
Member of groups: ipausers
Kerberos keys available: True

id xhy
uid=1251600003(xhy) gid=1251600003(xhy) groups=1251600003(xhy)

client加入域

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# client1.company.local
hostnamectl set-hostname client1.company.local && bash
timedatectl set-timezone Asia/Shanghai
systemctl disable firewalld.service --now

# 安装客户端
yum install ipa-client -y

# 配置DNS,指向FreeIPA服务器
echo "nameserver 10.163.2.100" > /etc/resolv.conf
echo "search company.local" >> /etc/resolv.conf

# 测试,可以解析到server的地址
host ipa-server
ipa-server.company.local has address 10.163.2.100

# 加入域
ipa-client-install \
--domain=company.local \
--realm=COMPANY.LOCAL \
--server=ipa-server.company.local \
--principal=admin \
--password=wangsheng \
--unattended
...
The ipa-client-install command was successful

验证:在client上使用xhy用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# client1.company.local
ssh xhy@client1.company.local
(xhy@client1.company.local) Password:
(xhy@client1.company.local) Password expired. Change your password now.
Current Password:
(xhy@client1.company.local) New password:
(xhy@client1.company.local) Retype new password:
Last failed login: Sat Oct 11 16:28:51 CST 2025 from 10.163.2.106 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Sat Oct 11 16:23:29 2025
Could not chdir to home directory /home/xhy: No such file or directory
[xhy@client1 /]$

成功登录了
CATALOG
  1. 1. 集中认证服务器的类型
  2. 2. FreeIPA
    1. 2.1. 部署freeipa-server
    2. 2.2. 创建用户
    3. 2.3. client加入域
    4. 2.4. 验证:在client上使用xhy用户