随着网络安全威胁的增加,传统的用户名和密码已经变得不再安全。为了加强网络访问的安全性,双因素身份验证成为了一种流行且有效的解决方案。在本文中,我们将介绍如何在已有的Windows AD环境下,在Ubuntu 22.04上安装和配置Freeradius和Google Authenticator来实现双因素身份验证,来提供网络访问服务器认证、授权和帐户信息。。
实验环境:
Windows AD(已有):提供LDAP服务,作为用户信息的存储库。
Ubuntu 22.04:将用于安装和配置Freeradius和Google Authenticator。
以下是实施步骤:
apt update && apt upgrade -y
apt-get install freeradius freeradius-common freeradius-utils freeradius-ldap libpam-google-authenticator -y
root@ud-Virtual-Machine:/home/ud# freeradius -v
radiusd: FreeRADIUS Version 3.0.26, for host x86_64-pc-linux-gnu, built on Jan 4 2023 at 03:23:09
FreeRADIUS Version 3.0.26
Copyright (C) 1999-2021 The FreeRADIUS server project and contributors
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE
You may redistribute copies of FreeRADIUS under the terms of the
GNU General Public License
For more information about these matters, see the file named COPYRIGHT
root@ud-Virtual-Machine:/home/ud# google-authenticator -h
google-authenticator [<options>]
-h, --help Print this message
-c, --counter-based Set up counter-based (HOTP) verification
-C, --no-confirm Don't confirm code. For non-interactive setups
-t, --time-based Set up time-based (TOTP) verification
-d, --disallow-reuse Disallow reuse of previously used TOTP tokens
-D, --allow-reuse Allow reuse of previously used TOTP tokens
-f, --force Write file without first confirming with user
-l, --label=<label> Override the default label in "otpauth://" URL
-i, --issuer=<issuer> Override the default issuer in "otpauth://" URL
-q, --quiet Quiet mode
-Q, --qr-mode={NONE,ANSI,UTF8} QRCode output mode
-r, --rate-limit=N Limit logins to N per every M seconds
-R, --rate-time=M Limit logins to N per every M seconds
-u, --no-rate-limit Disable rate-limiting
-s, --secret=<file> Specify a non-standard file location
-S, --step-size=S Set interval between token refreshes
-w, --window-size=W Set window of concurrently valid codes
-W, --minimal-window Disable window of concurrently valid codes
-e, --emergency-codes=N Number of emergency codes to generate
/etc/freeradius/3.0/radiusd.conf
文件# SECURITY CONFIGURATION
security {
# user/group: The name (or #number) of the user/group to run radiusd as.
user = root
group = root
}
/etc/freeradius/3.0/sites-enabled/default
。这个文件告诉 FreeRADIUS 如何使用 PAM 进行授权和认证。/etc/freeradius/3.0/policy.d/filter
中定义的新过滤器( “filter_google_otp”),它有助于从密码中提取6位数的TOTP。/etc/freeradius/3.0/dictionary
文件中,如下所示。/etc/freeradius/3.0/clients.conf
,我们可以设置客户端(例如:网络设备或服务器)用于连接到 RADIUS 服务器的密钥。请确保将默认密钥更改为不同的密钥,以提高安全性,以下配置仅供测试使用。/etc/freeradius/3.0/mods-available/ldap
,内容如下所示。/etc/pam.d/radiusd
文件,并指示它集成 Google Authenticator PAM。请按照以下配置并将其余行注释掉。ln -s /etc/freeradius/3.0/mods-available/ldap /etc/freeradius/3.0/mods-enabled/
ln -s /etc/freeradius/3.0/mods-available/pam /etc/freeradius/3.0/mods-enabled/
/lib/systemd/system/freeradius.service
# Ensure the daemon can still write its pidfile after it drops
# privileges. Combination of options that work on a variety of
# systems. Test very carefully if you alter these lines.
RuntimeDirectory=freeradius
RuntimeDirectoryMode=0775
User=root
Group=root
systemctl daemon-reload
systemctl restart freeradius.service
在开始测试之前,您需要创建 LDAP 用户 Google Authenticator,并保存在/google_auth
文件夹下。
#!/bin/bash
if [ -z $1 ]; then
echo "Usage: add_otp_user USERNAME"
exit 1
fi
# Ensure the otp folder is present
[ -d /google_auth ] || mkdir -p /google_auth
google-authenticator \
--time-based \
--disallow-reuse \
--force \
--rate-limit=3 \
--rate-time=30 \
--window-size=3 \
-s /google_auth/${1}.google_authenticator
chmod -v +x add-otp-user
#添加OTP 【where username matches the LDAP username】
bash ./add-otp-user <username>
#Command Syntax
radtest <username> <password+google authenticator TOTP> localhost 1812 <RADIUS secret key>
#Example:
radtest use01 ldapuserpassword123456 localhost 1812 testing123#
通过实施以上步骤,您可以为您的Radius服务添加一层额外的安全性。双因素身份验证不仅提供了更强的身份认证,还可以减少身份盗窃和未授权访问的风险。然而,需要注意的是,双因素身份验证并不能保证100%的安全性。使用强密码、定期更换密码、定期更新系统和进行安全审计等其他安全措施同样重要。综合采取多种安全策略,才能有效保护系统和用户的数据安全。
通过结合Freeradius、Google Authenticator和LDAP的强大功能,您可以轻松实现双因素身份验证,并提升系统的安全性。不断关注并采取最新的安全技术,保护您的网络免受恶意入侵和数据泄露的威胁。为了您的系统和用户的安全,投入一些时间和精力来实施双因素身份验证是值得的!