官术网_书友最值得收藏!

Hardening SSH service

This will be like a more traditional approach, with a modern automated method, using Ansible. Some of the items included here are:

  • Disabling the root user login, and instead creating a different user, and, if required, providing the sudo privilege:
    - name: create new user
user:
name: "{{ new_user_name }}"
password: "{{ new_user_password }}"
        shell: /bin/bash
groups: sudo
append: yes
  • Using key-based authentication to log in. Unlike with password-based authentication, we can generate SSH keys and add the public key to the authorized keys:
    - name: add ssh key for new user
authorized_key:
user: "{{ new_user_name }}"
key: "{{ lookup('file', '/home/user/.ssh/id_rsa.pub') }}"
state: present
  • Some of the configuration tweaks using the SSH configuration file; for example, PermitRootLogin, PubkeyAuthentication, and PasswordAuthentication:
    - name: ssh configuration tweaks
lineinfile:
dest: /etc/ssh/sshd_config
state: present
line: "{{ item }}"
backups: yes

with_items:
- "PermitRootLogin no"
- "PasswordAuthentication no"

notify:
- restart ssh

The following playbook will provide more advanced features for SSH hardening by dev-sec team: https://github.com/dev-sec/ansible-ssh-hardening

主站蜘蛛池模板: 固镇县| 谷城县| 将乐县| 黔东| 张掖市| 沭阳县| 遂川县| 平湖市| 五原县| 浑源县| 广河县| 夹江县| 昌宁县| 甘洛县| 常宁市| 灌南县| 离岛区| 普兰县| 台北县| 西平县| 宁城县| 廉江市| 木兰县| 长葛市| 迁安市| 平原县| 观塘区| 涿鹿县| 肇源县| 彰化市| 星子县| 临安市| 夏津县| 彰化市| 奇台县| 呼图壁县| 郎溪县| 宁南县| 洛隆县| 雷山县| 仪陇县|