gpt4 book ai didi

ssh - 将 SSH key 部署到服务器

转载 作者:行者123 更新时间:2023-12-02 13:51:14 27 4
gpt4 key购买 nike

我有以下剧本:

---
- name: provision toms keys
hosts: ssh4.demo.com
tasks:
- name: ensure user tom is present
user: name=tom state=present

- name: ensure private key and public one are present
copy: src=ssh_keys/tom dest=/.ssh mode=0600
with_items:
- id_rsa.pub
- id_rsa

- name: provision toms public keys
hosts: ssh1.demo.com

sudo: yes

tasks:

- user: name=tom comment="Add tom" group=staff

- name: Placing key
authorized_key: user=tom key="{{ lookup('file', 'ssh_keys/tom/id_rsa.pub') }}"

我有一个本地目录,其中包含我的 ssh 公钥和私钥,如下所示:
./ssh_keys
./ssh_keys/david
./ssh_keys/david/id_rsa
./ssh_keys/david/id_rsa.pub
./ssh_keys/fred
./ssh_keys/fred/id_rsa
./ssh_keys/fred/id_rsa.pub
./ssh_keys/joe
./ssh_keys/joe/id_rsa
./ssh_keys/joe/id_rsa.pub
./ssh_keys/paul
./ssh_keys/paul/id_rsa
./ssh_keys/paul/id_rsa.pub
./ssh_keys/peter
./ssh_keys/peter/id_rsa
./ssh_keys/peter/id_rsa.pub
./ssh_keys/tom
./ssh_keys/tom/id_rsa
./ssh_keys/tom/id_rsa.pub

我需要创建一些可用于将 key 推送到主机字段中定义的各种主机的剧本。

但是,.ssh key 目录创建不正确。即在 id_rsa 和 id_rsa.pub 目录下创建了一个名为 tom 的目录。

例如
 /home/tom/.ssh/id_rsa/tom/id_rsa

有人对此有很好的示例剧本吗?

最佳答案

尝试:

 ---
- name: provision toms keys
hosts: ssh4.demo.com
tasks:
- name: ensure user tom is present
user: name=tom state=present

- name: ensure private key and public one are present
copy: src=ssh_keys/tom/ dest=/.ssh mode=0600

您可以使用“tom/”复制整个目录 tom 或 tom 的内容。
此外,当您复制完整目录时,您不需要指定文件。

关于ssh - 将 SSH key 部署到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36875628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com