From 0de8330fd2d242c9f8b7dfeaa61290637f28640a Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 25 Jul 2025 11:24:14 +0200 Subject: [PATCH] update ssh task + readme --- README.md | 12 +++++++++--- tasks/ssh.yml | 16 +++++++++++++++- templates/sshd_config.j2 | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f4583af..1a626fc 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Ce playbook installe les services suivant: ## PRE REQUIS -- Debian 11 +- Debian 12 - Accès au serveur en ssh (username sudo, password) @@ -25,6 +25,14 @@ Ce playbook installe les services suivant: sudo apt install ansible -y ``` +## CONFIGURATION + +- Editer le fichier `vars.yml` et renseigner le `user`, `ssh_port` et l'`admin_email` + +- Ajouter une clé SSH `ed25519` dans le dossier `files/` + +> Cette clé permettra l'accès au serveur une fois le playbook terminé + ## UTILISATION - échanger sa clef ssh avec la machine cible avec la commande: @@ -32,8 +40,6 @@ sudo apt install ansible -y ssh-copy-id username@ip-machine-cible ``` -- Configurer le fichier hosts avec l'adresse IP de la machine cible ainsi que sont port ssh (si non default: 22) ainsi que le port ssh utilisé dans le fichier vars.yml - - Lançer la commande avec les paramètres modifiés pour username, password et ssh_port ```bash ansible-playbook -i hosts playbook.yml --user=username --extra-vars "ansible_sudo_pass=password user=username ssh_port=2222" diff --git a/tasks/ssh.yml b/tasks/ssh.yml index b5913ad..fa44ac5 100644 --- a/tasks/ssh.yml +++ b/tasks/ssh.yml @@ -1,3 +1,17 @@ --- -- name: config ssh \ No newline at end of file +- name: Deploy SSH config + template: + src: sshd_config.j2 + dest: /etc/ssh/sshd_config + owner: root + group: root + mode: '0600' + notify: Restart SSH + +- name: SSH key for access + authorized_key: + user: "{{ user }}" + state: present + key: "{{ lookup('file', 'files/id_ed25519.pub') }}" + notify: Restart SSH \ No newline at end of file diff --git a/templates/sshd_config.j2 b/templates/sshd_config.j2 index e69de29..ce4848f 100644 --- a/templates/sshd_config.j2 +++ b/templates/sshd_config.j2 @@ -0,0 +1,15 @@ +# templates/sshd_config.j2 + +Port {{ ssh_port }} +Protocol 2 +PermitRootLogin no +PasswordAuthentication no +ChallengeResponseAuthentication no +UsePAM yes +X11Forwarding no +ClientAliveInterval 300 +ClientAliveCountMax 2 +PermitEmptyPasswords no +LoginGraceTime 30 +MaxAuthTries 3 +# AllowUsers {{ ssh_allowed_users | default('admin') }}