使用以下命令将ssh公钥从一个帐户复制到另一个帐户 [英] Ansible copying ssh public key from one account to another using

查看:434
本文介绍了使用以下命令将ssh公钥从一个帐户复制到另一个帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了在远程服务器上的两个帐户之间复制ssh密钥的问题.我有一个名为"rmt"的远程服务器,在rmt上有一个名为"clado"的帐户,我想使用Ansible将/root/.ssh/authorized_keys(在rmt上)复制到/home/clado/.ssh/authorized_keys(在rmt上).

I am facing a problem of copying ssh key between two accounts on a remote server. I have remote server called "rmt", on rmt I have one account called "clado" i want to copy the /root/.ssh/authorized_keys (on rmt) to /home/clado/.ssh/authorized_keys (on rmt) using Ansible.

我得到了以下示例代码:

I got this sample code:

- name: Set authorized key in alternate location
  authorized_key:
    user: charlie
    state: present
    key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"

但是它正在使用本地/home/charlie/.ssh/id_rsa.pub.

推荐答案

但是它使用的是本地('/home/charlie/.ssh/id_rsa.pub').

But it is using the local('/home/charlie/.ssh/id_rsa.pub').

所有查找插件都在Ansible控制机器上本地工作.

All lookup plugins work locally on the Ansible control machine.

您可以使用 slurp模块获取远程文件的内容,例如:

You can fetch the contents of a remote file with slurp module, for example:

- name: Fetch authorized key from alternate location
  slurp:
    src: /home/other_user/.ssh/id_rsa.pub
  register: slurped_key_b64

- name: Ensure the fetched key is set for charlie
  authorized_key:
    user: charlie
    state: present
    key: "{{ slurped_key_b64.content | b64decode }}"

自定义详细信息,因为您的描述和代码不匹配.

但是通常从系统管理的角度来看,这种流程没有多大意义.从控制机分配钥匙.

But generally this flow doesn't make much sense from system management point of view. Assign the key from the control machine.

这篇关于使用以下命令将ssh公钥从一个帐户复制到另一个帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆