章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • linux

  • windows

  • 中间件

  • 网络

  • 安全

    • docker部署openvas
    • 白帽子讲web安全
    • ssh安全
      • 1、只允许某用户从指定 IP 地址登陆
      • 2、设置 SSH 空闲超时退出时间
      • 3、 限制登陆访问尝试的验证次数
      • 4、允许 root 用户登录
      • 5、设置登录方式
      • 6、禁止使用空白密码用户访问
      • 7、SSH 登录事件通知至 ntfy
    • 系统安全及应用基础
    • OSSEC安全监控环境搭建
    • 等保三级
  • 存储

  • 防火墙

  • 数据库

  • 系统

  • docker

  • other

  • 监控

  • 运维
  • 安全
章工运维
2023-02-24
目录

ssh安全

# 1、只允许某用户从指定 IP 地址登陆

sed -i '$a AllowUsers CR@192.168.1.12 root@192.168.1.12' /etc/ssh/sshd_config ;\
systemctl restart sshd
1
2

# 2、设置 SSH 空闲超时退出时间

/etc/ssh/sshd_config

#ClientAliveInterval 0
#ClientAliveCountMax 3
修改成
ClientAliveInterval 30    #(每30秒往客户端发送会话请求,保持连接)
ClientAliveCountMax 3     #(去掉注释即可,3表示重连3次失败后,重启SSH会话)
1
2
3
4
5

systemctl restart sshd

# 3、 限制登陆访问尝试的验证次数

MaxAuthTries 20
1

# 4、允许 root 用户登录

sed -i 's/PermitRootLogin no/PermitRootLogin yes/g'  /etc/ssh/sshd_config ;\
systemctl restart sshd
1
2

# 5、设置登录方式

# AuthorizedKeysFile   .ssh/authorized_keys   //公钥公钥认证文件
# PubkeyAuthentication yes   //可以使用公钥登录
# PasswordAuthentication no  //不允许使用密码登录
1
2
3

# 6、禁止使用空白密码用户访问

PermitEmptyPasswords no
1

# 7、SSH 登录事件通知至 ntfy

/etc/pam.d/sshd

session optional pam_exec.so /usr/local/bin/ntfy-ssh-login.sh
1

ntfy-ssh-login.sh

#!/bin/bash
TOPIC_URL=http://test.curiouser.top:18070/ssh-notify
if [ "${PAM_TYPE}" = "open_session" ]; then
  curl -H tags:warning -H prio:high -d "SSH login to $(hostname): ${PAM_USER} from ${PAM_RHOST}" "${TOPIC_URL}"
fi

1
2
3
4
5
6

部署私有的 ntfy

ntfy_server:
  image: 'binwiederhier/ntfy'
  restart: always
  container_name: ntfy_server
  command: serve --config /etc/ntfy/server.yml --cache-file /var/cache/ntfy/cache.db --listen-http :18070
  ports:
    - '18070:18070'
  volumes:
    - '/data/ntfy/data:/var/cache/ntfy'
    - '/data/ntfy/config:/etc/ntfy'
    - '/data/ntfy/data:/var/lib/ntfy/'

1
2
3
4
5
6
7
8
9
10
11
12

原文链接:

ssh安全 | Gaoyufu 's blog (opens new window)

微信 支付宝
上次更新: 2023/02/24, 20:47:23

← 白帽子讲web安全 系统安全及应用基础→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式