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

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

主站蜘蛛池模板: 涟水县| 三明市| 泉州市| 瑞丽市| 儋州市| 绥宁县| 锡林郭勒盟| 洛阳市| 平果县| 庆安县| 永宁县| 固始县| 蛟河市| 饶平县| 红桥区| 兴城市| 桂阳县| 棋牌| 芷江| 九龙城区| 罗定市| 醴陵市| 亚东县| 磐安县| 嵊州市| 乐安县| 襄汾县| 房产| 乌鲁木齐市| 河东区| 东源县| 芜湖县| 枞阳县| 疏勒县| 门源| 皋兰县| 孙吴县| 南乐县| 子洲县| 墨江| 阿克苏市|