Skip to content

Instantly share code, notes, and snippets.

@meskarune
Created July 4, 2016 19:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meskarune/fbc84b7c06dbf3c78e2ed884f898859c to your computer and use it in GitHub Desktop.
Save meskarune/fbc84b7c06dbf3c78e2ed884f898859c to your computer and use it in GitHub Desktop.
ansible playbook for setting up ssh
---
- hosts: new
vars:
- root_password: 'foo'
- minerva_password: 'bar'
tasks:
- name: Change root password
user:
name=root
password={{ root_password }}
- name: Add user minerva
user:
name=minerva
password={{ minerva_password }}
- name: Add SSH public keys to user minerva
authorized_key:
user=minerva
key="{{ lookup('file', "../keys/id_rsa.pub") }}"
- name: Add user minerva to sudoers
lineinfile:
"dest=/etc/sudoers
regexp="^minerva ALL"
line="minerva ALL=(ALL) NOPASSWD: ALL"
state=present
- name: Disallow root SSH access
lineinfile:
dest=/etc/ssh/sshd_config
regexp="^PermitRootLogin"
line="PermitRootLogin no"
state=present
notify:
- restart sshd
- name: Disallow SSH password authentication
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
@dbazhal
Copy link

dbazhal commented Feb 13, 2023

Thank you :)

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