统计各节点ssh免密登录授权信息
2018-06-03 13:42
411 查看
为了维护方便,生产环境ansible到其他所有节点所有账号做了免密登录,根据安全需求,现需要统计所有节点所有账号的ssh免密登录授权信息。为了省时省力,将以ansible+shell的形式实现,如下:
1、准备好ansible的hosts文件,根据账号名称分成多个组,其中root组包括所有节点的IP地址。
2、准备一个文件包括所有节点的IP地址
3、playbook文件,authfile.yml
--- - hosts: root gather_facts: false remote_user: root tasks: - name: cp root auth file shell: source ~/.bash_profile && source /etc/profile && mkdir -p /tmp/myauthdir && cp /root/.ssh/authorized_keys /tmp/myauthdir/`hostname`_root.txt - hosts: sumapay gather_facts: false remote_user: root tasks: - name: cp sumapay auth file shell: source ~/.bash_profile && source /etc/profile && cp /home/sumapay/.ssh/authorized_keys /tmp/myauthdir/`hostname`_sumapay.txt - hosts: sumapay25 gather_facts: false remote_user: root tasks: - name: cp sumapay25 auth file shell: source ~/.bash_profile && source /etc/profile && cp /home/sumapay25/.ssh/authorized_keys /tmp/myauthdir/`hostname`_sumapay25.txt - hosts: glassfish gather_facts: false remote_user: root tasks: - name: cp glassfish auth file shell: source ~/.bash_profile && source /etc/profile && cp /home/glassfish/.ssh/authorized_keys /tmp/myauthdir/`hostname`_glassfish.txt
4、shell脚本文件,authfile.sh
#!/bin/bash #授权文件归集目录 authfile_dir="authfile" #授权信息归集文件 auth_message="message.csv" #在各节点生成"主机名_用户"格式的授权文件 ansible-playbook -i /etc/ansible/hosts authfile.yml #拷贝各节点生成后的授权文件 cpauthfile(){ if [[ ! -d $authfile_dir ]];then mkdir $authfile_dir fi for i in `cat ip.txt` do scp root@${i}:/tmp/myauthdir/* $authfile_dir done } #过滤个授权文件免密登录主机,并生成列表 create_table(){ if [[ -s $auth_message ]];then echo > $auth_message fi for i in `ls $authfile_dir` do host_user=`echo $i|awk -F "." '{print $1}'` message=`cat $authfile_dir/$i|awk '{print $3}'|sort -u|awk '{{printf"%s,",$0}}'` printf "%s,%s\n" $host_user $message >> $auth_message done } cpauthfile create_table
5、执行authfile.sh,生成message.csv文件,包含所有节点、所有用户的ssh免密登录授权信息。
相关文章推荐
- 行情分发节点信息统计(登陆人数, 合约数)
- Android集成原生微信授权获取用户信息登录
- Android之QQ授权登录获取用户信息
- 支付宝开发平台之第三方授权登录与获取用户信息
- QQ的第三登录授权完获得信息
- 支付宝开发平台之第三方授权登录与获取用户信息
- 在线用户信息统计&单用户登录(update)
- Android之QQ授权登录获取用户信息
- Java 微信登录授权后获取微信用户信息昵称乱码问题解决
- 微信订阅号里实现oauth授权登录,并获取用户信息 (完整篇)
- 微信开发笔记——微信网页登录授权,获取用户信息
- 微信授权登录并获取用户信息接口开发
- ASP .NET MVC 微信授权获取用户信息并实现登录
- 查看用户登录信息并统计登陆的次数
- 微信第三方授权登录返回错误信息: 40029
- Android授权登录新浪微博获取用户个人信息
- Android 微信授权登录、获取Wx用户信息,解决无法回调问题
- Android之QQ授权登录获取用户信息
- java实现微信公众号授权登录获取用户信息流程
- jsp计数器--页面统计特定用户的登录次数或所有人的访问信息