FreeRadius+GoogleAuthenticator实现linux动态口令认证
简介
在运维管理中,服务器的密码管理十分重要。服务器数量少的时候还好说,可以定时来改密码。一旦数量多了,再来改密码就不现实了。
前提
我们假定运维访问服务器是这样的:
- 创建一个普通用户用于登录服务器,给出基础权限,能进行简单的日常操作。但不能修改系统层面的东西。这个权限不能做太多的事。
- 切换到root用户时,不能使用root密码来进行认证切换。不然密码泄露,服务器最高权限就算是没了。这里可以使用动态口令的方式来进行认证切换。
原理
原理图如下:

这里通过FreeRadius+GoogleAuthenticator实现linux动态口令认证,其原理是:
- 通过开源的GoogleAuthenticator来实现动态口令
- 服务器通过FreeRadius进行认证
- FreeRadius使用PAM+GoogleAuthenticator来进行认证
这样说可能有点不清楚,我这里再整理下整个流程。流程是这样的:
- 用户使用普通用户登录业务服务器A 进行操作
- 用户需要提权,切换到root,需要输入动态口令来进行切换
- 输入动态口令
- 业务服务器A 就向动态口令认证服务器B 的FreeRadius进行认证
- 认证服务器B的FreeRadius收到认证请求后,开始认证
- FreeRadius会向GoogleAuthenticator来进行动态口令的校验,然后将结果返回给业务服务器。
- 业务服务器成功切换到root用户
安装部署
服务端
系统:CentOS 7.2
NTP安装
由于Google Authenticator依赖于时间,所以你的服务器时间必须总是正确的。这里通过ntp服务自动同步网络时间。
yum install ntp -y
systemctl enable ntpd
systemctl start ntpd
Google Authenticator Pam安装配置
安装
git clone https://github.com/google/google-authenticator-libpam.git
cd google-authenticator-libpam/
./bootstrap.sh
./configure
make
make install
ln -s /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/pam_google_authenticator.so
如果出現:
configure: error: Unable to find the PAM library or the PAM header files
請安裝此套件後,重新執行./configure:
# yum install pam-devel
配置pam
/etc/pam.d/sshd
#添加下面一行
auth required pam_google_authenticator.so
#注释下面一行
#auth substack password-auth
配置ssh
/etc/ssh/sshd_config
# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes
#ChallengeResponseAuthentication no
重启sshd
systemctl restart sshd.service
为用户启用google-authenticator
输入命令:google-authenticator
1)屏幕提示Do you want authentication tokens to be time-based (y/n) ,回答y选用基于时间的token
2)屏幕提示二维码,拿出手机打开google authenticator软件(没有请自行下载),点击+后选择“条形码扫描"添加认证条目。
---
注意:将屏幕显示的secret key, verification code 和 recovery codes 保存在安全的地方,供密码恢复使用。
---
3)Do you want me to update your "/home/sammy/.google_authenticator" file (y/n) y
4)Do you want to disallow multiple uses of the same authentication token? This restricts you to one login about every 30s, but it increases your chances to notice or even prevent man-in-the-middle attacks (y/n) y
4)By default, tokens are good for 30 seconds. In order to compensate for possible time-skew between the client and the server, we allow an extra token before and after the current time. If you experience problems with poor time synchronization, you can increase the window from its default size of +-1min (window size of 3) to about +-4min (window size of 17 acceptable tokens). Do you want to do so? (y/n) n
5)If the computer that you are logging into isn‘t hardened against brute-force login attempts, you can enable rate-limiting for the authentication module. By default, this limits attackers to no more than 3 login attempts every 30s. Do you want to enable rate-limiting (y/n) y
新建ssh连接(不要关闭当前的防止无法访问)测试配置是否成功。
FreeRadius 安装配置
安装
yum install freeradius freeradius-utils -y
配置
/etc/raddb/radusd.conf
user = radiusd
group = radiusd
#改成
user = root
group = root
/etc/raddb/users
#取消下面2行注释
DEFAULT Group == "disabled", Auth-Type := Reject
Reply-Message = "Your account has been disabled."
#添加一行
DEFAULT Auth-Type := PAM
/etc/raddb/sites-enabled/default
authenticate {
...
# Pluggable Authentication Modules
# pam
...
}
#取消pam行前面的注释
freeradius启用pam模块
ln -s /etc/raddb/mods-available/pam /etc/raddb/mods-enabled/pam
/etc/raddb/clients.conf
#在最后添加一段认证类型
client macolee_sudo {
ipaddr = 0.0.0.0
netmask = 0
secret = macolee_sudo
require_message_authenticator = no
}
/etc/pam.d/radiusd
#%PAM-1.0
#注释掉下面一行
#auth include password-auth
#添加下面一行。secret是google Authenticator认证的配置文件,user是切换为root的时候需要认证
auth required pam_google_authenticator.so secret=/etc/raddb/gauth user=root
account required pam_nologin.so
account include password-auth
password include password-auth
session include password-auth
启动freeradius
systemctl enable radiusd
systemctl start radiusd
打开防火墙限制,开通FreeRadius的1812端口
/etc/sysconfig/iptables
-A INPUT -s 10.1.2.97 -p udp -m udp --dport 1812 -j ACCEPT
客户端
pam_radius安装配置
安装
#添加epel yum源
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
#安装
yum install pam_radius -y
配置
...
# server[:port] shared_secret timeout (s)
# 127.0.0.1 secret 1
# other-server other-secret 3
#添加认证服务器地址 认证类型
10.214.60.37:1812 macolee_sudo 10
修改sudo的pam配置
#%PAM-1.0
#添加下面一行
auth required pam_radius_auth.so
#注释下面一行
#auth include system-auth
account include system-auth
password include system-auth
session optional pam_keyinit.so revoke
session required pam_limits.so
验证
前提
客户端服务器上的用户名,在radius服务端也必须存在。比如客户端要切换为root的普通用户是test1,那么radius服务端也必须有test1这个普通用户
客户端和服务端添加用户
#添加用户
useradd test1
#给用户sudo权限
命令:visudo
#添加
macolee ALL=(ALL) /bin/su - root
测试登录
> 1. 以test1用户登录客户端服务器
> 2. 输入名sudo su - root
> 3. 输入手机app上google验证器上的验证码
> 4. 能成功切换,表示配置成功
FreeRadius+GoogleAuthenticator实现linux动态口令认证的更多相关文章
- php集成动态口令认证
这篇文章主要为大家详细介绍了php集成动态口令认证,动态口令采用一次一密.用过密码作废的方式来提高安全性能,感兴趣的小伙伴们可以参考一下 大多数系统目前均使用的静态密码进行身份认证登录,但由于静态密码 ...
- 使用OTP动态口令(每分钟变一次)进行登录认证
GIT地址:https://github.com/suyin58/otp-demo 在对外网开放的后台管理系统中,使用静态口令进行身份验证可能会存在如下问题: (1) 为了便于记忆,用户多选择有特征作 ...
- YS动态口令系统接入流程
动态口令是保护用户账户的一种常见有效手段,即用户进行敏感操作(比如登录)时,需要用户提供此动态生成的口令做二次身份验证,假设用户的口令被盗,如果没有动态口令,也无法进行登录或进行敏感操作,保护了用户的 ...
- 使用google身份验证器实现动态口令验证
最近有用户反应我们现有的短信+邮件验证,不安全及短信条数限制和邮件收验证码比较慢的问题,希望我们 也能做一个类似银行动态口令的验证方式.经过对可行性的分析及慎重考虑,可以实现一个这样的功能. 怎么实现 ...
- poptest老李谈动态口令原理
poptest老李谈动态口令原理 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908 ...
- centos7 ssh免口令认证登录
摘要:centos7, xshell, 公钥, ssh ssh登录方式有口令认证登录和密钥认证登录 接下来本次介绍是ssh密钥登录方式 (1)产生公钥 (2)将公钥放置到centos7的(/root ...
- Google authenticator 谷歌身份验证,实现动态口令
Google authenticator 谷歌身份验证,实现动态口令 google authenticator php 服务端 使用PHP类 require_once '../PHPGangsta/G ...
- 静态数据认证(SDA)与动态数据认证(DDA)的区别
PBOC/EMV里有两个非常重要的概念,SDA(staticdataauthentication)和DDA(dynamicdataauthentication),分别叫做静态数据认证和动态数据认证.这 ...
- linux动态库默认搜索路径设置的三种方法
众所周知, Linux 动态库的默认搜索路径是 /lib 和 /usr/lib .动态库被创建后,一般都复制到这两个目录中.当程序执行时需要某动态库, 并且该动态库还未加载到内存中,则系统会自动到这两 ...
随机推荐
- 多态 与 鸭子类型 duck duck duck
# --> ''' 多态 与 鸭子类型 --> 什么是多态 对象的多种状态,父类对象的多种 (子类对象) 状态 --> 什么是鸭子类型: 长的像就是 1.规定有什么属性及什么方法的对 ...
- SpringBoot中的ajax跨域问题
在控制类加入注释@CrossOrigin(allowCredentials = "true",allowedHeaders = "*",origins = {& ...
- 转换流 InputStreamReader
通常接触到字节流和字符流,但是有一个流是这两个流的桥梁,inputStreamReader 字符流的结构如下 可以看到inputStreamReader是继承Reader ,它的子类是FileRead ...
- 2018-No.7-SicnuCtf
5月份的比赛现在才有时间在博客贴出来,这是我第二次出题了,第一次是上届的初赛,这次是决赛的题. 签到(base_or_base) 解压得到两个文件小明.zip和......txt,根据文件名提示猜测是 ...
- 结对编程总结(胡超慧&&王宇)
在分析完需求的几秒中内,我和搭档就蒙了,因为之前并没有做过UI,因此这次的项目对于我们来说无疑是一个陌生的挑战. 为了最大程度实现曾经代码的复用,我们最开始考虑使用可以支持C++的QT来进行相关的设计 ...
- JDBC 链接mysql 8 的问题
转载:jdbc连接mysql 8 的一些坑 1.驱动包要升级为 mysql-connector-java-8.0.11.jar 2.JDBC driver 由“com.mysql.jdbc.Drive ...
- scrollview中edittext失去焦点问题
//edittext获取焦点后会瞬间失去,暂时使用这种笨方法解决(获取到焦点后过300ms再获取一次) public void requesFocus() { mEditName.setOnFocus ...
- border边框属性
边框属性: 边框宽度(border-width):thin.medium.thick.长度值 边框颜色(border-color):颜色.transparent(透明) 边框样式(border-sty ...
- springcould 微服务 搭建
摘自:https://www.cnblogs.com/lori/p/10615654.html (完整) springcloud~服务注册与发现Eureka的使用 服务注册与发现是微服务里的 ...
- linux文本处理命令
linux文本处理命令 1.wc命令 基本介绍 文件的行统计.字符统计.字节统计 基本语法 wc [OPTION]... [FILE]... wc [OPTION]... --files0-f ...