设为首页 收藏本站
查看: 2103|回复: 0

[经验分享] centos google authenticator 安装及配置

[复制链接]

尚未签到

发表于 2018-4-21 06:54:15 | 显示全部楼层 |阅读模式
  为了增强服务器安全性,使用google authenticator生成的动态密码进行加固,输入密码的同时需要再次验证动态密码才能登录成功。以下操作均在centos6.5环境下操作。
  

  首先:

  1、安装一些必要组件
yum install -y git make gcc libtool pam-devel qrencode ntpdate  

  2、下载编译安装
git clone https://github.com/google/google-authenticator-libpam.gitcd google-authenticator-libpam/./bootstrap.sh./configure
make && make installln -s /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/  

  3、配置ssh
vim /etc/ssh/sshd_config  修改如下的配置项:
  ChallengeResponseAuthentication yes
  UsePAM yes
  重启ssh
service sshd restart  

  4、配置PAM

  vim /etc/pam.d/sshd
  如下:
  #auth       include      password-auth
  auth       substack     password-auth
  auth       required     pam_google_authenticator.so
  第一行删除或者注释,第二行和第三行的顺序将确定先输入密码还是动态码
  

  5、配置google authenticator
  首先,切换到你需要设置的帐号:
su google
google-authenticator  Do you want authentication tokens to be time-based (y/n) y    ---输入y(会生成一个二维码和secret key,之后的操作会用到这个二维码/密钥(secret key),还有5 个紧急救助码(emergency scratch code),紧急救助码就是当你无法获取认证码时(比如手机丢了),可以当做认证码来用,每用一个少一个,但其实可以手动添加的,建议如果 root 账户使用 Google Authenticator 的话一定要把紧急救助码另外保存一份。)
  Warning: pasting the following URL into your browser exposes the OTP secret to Google:
  https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/google@ip-172-31-17-35%3Fsecret%3DEUMUWLYHE3WFDCD4FTTC4NHDWU%26issuer%3Dip-172-31-17-35
  ---如果已经安装qrencode,此处会显示二维码,该二维码也可以通过上面的网址打开---
  

  Your new secret key is: EUMUWLYHE3WFDCD4FTTC4NHDWU
  Your verification code is 102411
  Your emergency scratch codes are:
  31858704
  90298886
  63354215
  17985381
  56998209
  

  Do you want me to update your "/home/google/.google_authenticator" file? (y/n)y    ---输入y(是否更新用户的 Google Authenticator 配置文件,选择 y 才能使上面操作对当前用户生效,其实就是在对应用户的 Home 目录下生成了一个 .google_authenticator 文件,如果你想停用这个用户的 Google Authenticator 验证,只需要删除这个用户 Home 目录下的 .google_authenticator 文件就可以了。)
  

  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    ---输入y(每次生成的认证码是否同时只允许一个人使用?这里选择 y)
  

  By default, a new token is generated every 30 seconds by the mobile app.
  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. This allows for a
  time skew of up to 30 seconds between authentication server and client. If you
  experience problems with poor time synchronization, you can increase the window
  from its default size of 3 permitted codes (one previous code, the current
  code, the next code) to 17 permitted codes (the 8 previous codes, the current
  code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
  between client and server.
  Do you want to do so? (y/n)n    ---输入n(是否增加时间误差?这里选择 n )
  

  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    ---输入y(是否启用次数限制?这里选择 y,默认每 30 秒最多尝试登录 3 次)
  

  6、APP设置

  首先从google play 下载google Authenticator,打开app,点击"scan a barcode",扫一下刚刚生成的二维码,或者手动输入secret key,即可得到一个动态密码,该密码每30秒变化一次。使用ssh登录服务器时,需要先输入用户密码,再输入动态密码才可以登录。
DSC0000.png

  7、动态密码登录
  

[deploy@puppet c]$ ssh google@192.168.1.2

  Password:
  Verification code: ---此处输入动态密码---
  

  如果出现异常,请查看/var/log/secure进行排查

  

  参考内容:
  http://shenyu.me/2016/09/05/centos-google-authenticator.html
  http://www.111cn.net/sys/CentOS/88306.htm

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-449768-1-1.html 上篇帖子: Centos7 IP配置及网络排查 下篇帖子: centos7.2的网络配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表