Skip to content

Instantly share code, notes, and snippets.

@alanreynosov
Last active August 21, 2020 23:50
Show Gist options
  • Save alanreynosov/f0ac2cf24becc1973502cd1e39a67d95 to your computer and use it in GitHub Desktop.
Save alanreynosov/f0ac2cf24becc1973502cd1e39a67d95 to your computer and use it in GitHub Desktop.
ansible playbook to disable password authentication in a raspberry pi with raspberry OS or any debian based distro
- name: Log in as pi user to disable root
hosts: nodes
user: "pi"
gather_facts: false
become: yes
tasks:
- name: Disable root login over SSH
lineinfile: dest=/etc/ssh/sshd_config regexp="^PermitRootLogin" line="PermitRootLogin no" state=present
notify:
- restart sshd
- name: Disable password login
lineinfile: dest=/etc/ssh/sshd_config regexp="^PasswordAuthentication" line="PasswordAuthentication no" state=present
notify:
- restart sshd
handlers:
- name: restart sshd
service:
name: sshd
state: restarted
@alanreynosov
Copy link
Author

ansible playbook to disable password authentication in a raspberry pi with raspberry OS or any debian based distro

  1. First you should to create an ssh keypair
  2. ssh-copy-id -i yourkey.pub pi@yourraspberryIp
  3. ansible-playbook disable-password.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment