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

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

主站蜘蛛池模板: 娄底市| 中卫市| 克山县| 绥芬河市| 嘉义县| 兰西县| 神池县| 安丘市| 弥勒县| 锡林浩特市| 普格县| 黄陵县| 察隅县| 灵寿县| 彩票| 忻州市| 紫云| 海南省| 株洲市| 江西省| 霸州市| 漯河市| 抚顺县| 兴海县| 石泉县| 韶关市| 德州市| 稷山县| 浪卡子县| 原阳县| 泗洪县| 鹤庆县| 吉水县| 视频| 织金县| 彭水| 阿瓦提县| 罗江县| 江源县| 石棉县| 和龙市|