Carry の Blog Carry の Blog
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carry の Blog

好记性不如烂键盘
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工作笔记

  • K8S

  • Systemd

  • Nginx

  • Supervisord

  • OpenLdap

  • OpenVPN

  • GitLab

  • Sshd

    • sshd配置介绍
      • SSHD配置详细介绍
        • 什么是SSHD?
        • SSHD配置文件
        • 常见配置参数
        • 高级示例
        • 应用配置并重启SSHD服务
  • WebDev

  • Docker

  • Prometheus

  • Rclone

  • Iptables

  • Firewalld

  • Linux笔记
  • Sshd
Carry の Blog
2022-03-10
目录

sshd配置介绍

# SSHD配置详细介绍

# 什么是SSHD?

SSHD(Secure Shell Daemon)是OpenSSH软件包中的一个重要组件,它允许安全地通过网络进行远程登录和其他安全的网络服务。SSHD服务运行在服务器上,监听客户端连接,并对它们进行身份验证。

# SSHD配置文件

SSHD的主要配置文件是/etc/ssh/sshd_config,其中包含了各种参数设置,可以通过编辑这个文件来配置SSHD的行为。

# 常见配置参数

以下是一些常见的SSHD配置参数:

  1. Port

    • 定义SSHD监听的端口,默认是22。
    Port 22
    
    1
  2. PermitRootLogin

    • 是否允许root用户远程登录。为了安全,通常设置为no。
    PermitRootLogin no
    
    1
  3. PasswordAuthentication

    • 是否允许密码验证。为了更高的安全性,可以设置为no,只允许密钥认证。
    PasswordAuthentication yes
    
    1
  4. PubkeyAuthentication

    • 是否允许公钥认证。
    PubkeyAuthentication yes
    
    1
  5. MaxAuthTries

    • 定义最大认证尝试次数。
    MaxAuthTries 3
    
    1
  6. AllowUsers

    • 允许特定用户登录。
    AllowUsers user1 user2
    
    1
  7. AllowGroups

    • 允许特定用户组中的用户登录。
    AllowGroups sshusers
    
    1
  8. PermitEmptyPasswords

    • 是否允许空密码用户登录。通常设置为no。
    PermitEmptyPasswords no
    
    1

# 高级示例

# 示例1:基于密钥认证的安全配置

# 修改默认端口以增加安全性
Port 2222

# 禁用root登录
PermitRootLogin no

# 禁用密码认证,启用公钥认证
PasswordAuthentication no
PubkeyAuthentication yes

# 限制最大认证尝试次数
MaxAuthTries 3

# 限制登录用户
AllowUsers alice bob

# 配置日志级别
LogLevel VERBOSE

# 配置登录欢迎消息
Banner /etc/ssh/sshd_banner

# 禁用空密码登录
PermitEmptyPasswords no
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 示例2:允许特定组用户使用SSH登录并配置连接速率限制

# 修改默认端口以增加安全性
Port 2222

# 禁用root登录
PermitRootLogin no

# 启用密码认证和公钥认证
PasswordAuthentication yes
PubkeyAuthentication yes

# 限制登录用户组
AllowGroups sshusers

# 配置最大认证尝试次数
MaxAuthTries 3

# 配置登录失败后等待时间(秒)
LoginGraceTime 30

# 每IP连接限制和连接速率
MaxStartups 10:30:60

# 启用TCP KeepAlive,保持连接
TCPKeepAlive yes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 应用配置并重启SSHD服务

完成配置后,保存文件并重启SSHD服务以使更改生效:

sudo systemctl restart sshd
1

或

sudo service sshd restart
1
#ssh
上次更新: 4/24/2025

← Gitlab代码版本控制工具实战 nginx的webdav设置→

最近更新
01
tidb fast ddl
04-04
02
TiDB配置文件调优 原创
04-03
03
如何移除TiDB中的表分区 原创
04-03
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式