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

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

主站蜘蛛池模板: 应城市| 临泽县| 文成县| 伊宁市| 历史| 宜州市| 尉犁县| 南涧| 文成县| 楚雄市| 安阳市| 青海省| 南召县| 鄂托克前旗| 陵川县| 平南县| 河间市| 西华县| 平凉市| 肃宁县| 黑河市| 郑州市| 酒泉市| 进贤县| 县级市| 鄯善县| 石林| 尚志市| 古田县| 龙岩市| 镇平县| 卢氏县| 玉山县| 汉川市| 商丘市| 肥城市| 晋江市| 含山县| 南充市| 监利县| 溧水县|