侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

ansible 命令行的方式添加免密

2023-12-19 星期二 / 0 评论 / 0 点赞 / 123 阅读 / 1584 字

一.环境 1.1 操作系统 [root@host-xxxsoft]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core

一.环境

1.1 操作系统

[root@host-xxxsoft]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.6 (Final)
Release:        6.6
Codename:       Final
[root@host-xxx soft]# 

1.2 ansbile 版本

[test@host playbooks]$ ansible --version
ansible 2.1.1.0
  config file = /wls/test/playbooks/ansible.cfg
  configured module search path = Default w/o overrides
[test@host playbooks]$ 

二 添加免密

2.1 hosts 文件

[testroot]
10.59.9.2
10.59.9.3

[testroot:vars]
ansible_ssh_user="root"
ansible_ssh_pass="root"

2.2 执行命令

ansible testroot -m authorized_key -a "user=test key='{{ lookup('file', '/wls/test/.ssh/id_rsa.pub') }}' path=/wls/test/.ssh/authorized_keys manage_dir=no"

2.3 说明

我是用root用户登录到各主机,然后给各主机的test 用户添加免密

 

2.4 为什么用root 用户,因为用其他用户会报权限不足,需要修改目录权限。

 

三.验证

验证方法:ssh [email protected]   能直接登录就可以了

或者 ansible 10.59.9.2 -a who

等各种验证方法

略。

 

 

 

广告 广告

评论区