Skip to content

Instantly share code, notes, and snippets.

@peterkowalski
Last active October 12, 2020 16:18
Show Gist options
  • Save peterkowalski/2208fe081181fca991c8831ee113d1b2 to your computer and use it in GitHub Desktop.
Save peterkowalski/2208fe081181fca991c8831ee113d1b2 to your computer and use it in GitHub Desktop.
[Add public SSH key for different user with Ansible] This snippet adds SSH public key for other user using root account on the remote host and password authentication (-k). #ansible #adhoc
# Required by sshpass
export ANSIBLE_HOST_KEY_CHECKING=False
ansible all -i "192.168.1.1," -m authorized_key -a "user=other-user state=present key=\"{{ lookup('file', 'other-public-key.pub') }}\"" -u root -k #-CD (check and show diff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment