sshd_config 连接数常用的参数设置(备忘)

路径: /etc/ssh/sshd_config

ClientAliveInterval 间隔发送客户端ssh心跳alive
Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

ClientAliveInterval   60 

MaxSessions 最大连接数
Specifies the maximum number of open sessions permitted per network connection. The default is 10.

MaxSessions 60 

MaxStartups 未授权连接的最大连接数
Specifies the maximum number of concurrent unauthenticated connections to the SSH daemon. Additional connections will be dropped until authentication succeeds or the LoginGraceTime expires for a connection. The default is 10.

Alternatively, random early drop can be enabled by specifying the three colon separated values ‘‘start:rate:full’’ (e.g. “10:30:60”). sshd(8) will refuse connection attempts with a probability of ‘‘rate/100’’ (30%) if there are currently ‘‘start’’ (10) unauthenticated connections. The probability increases linearly and all connection attempts are refused if the number of unauthenticated connections reaches ‘‘full’’ (60).

MaxStartups  50:20:100 
<think>我们正在解决执行 `diff /etc/ssh_backup/sshd_config /etc/ssh/sshd_config` 时出现“没有那个文件或目录”错误的问题。 错误原因通常有两个: 1. 指定的文件或目录确实不存在 2. 路径拼写错误 根据命令,我们有两个文件路径: - `/etc/ssh_backup/sshd_config` - `/etc/ssh/sshd_config` 我们首先需要确认这两个文件是否存在。 解决方案步骤: 1. **检查文件是否存在**: 使用 `ls` 命令分别检查两个文件: ```bash ls -l /etc/ssh_backup/sshd_config ls -l /etc/ssh/sshd_config ``` 2. **根据检查结果处理**: - 如果其中一个文件不存在(很可能是`/etc/ssh_backup/sshd_config`,因为`/etc/ssh/sshd_config`是默认配置文件),则需要确定备份文件的位置。 - 如果备份文件不存在,而我们确实需要比较,那么可能需要先找到备份文件的位置,或者重新备份。 3. **可能的备份位置**: 在升级或修改SSH配置前,系统管理员有时会将配置文件备份到其他位置,常见的备份位置有: - `/etc/ssh/sshd_config.bak` - `/etc/ssh/sshd_config.orig` - `/etc/ssh/sshd_config.old` - `/root/backup/sshd_config` - 或者备份在`/etc/ssh_backup`目录下,但文件名可能不是`sshd_config`(可能是带日期后缀) 4. **如果备份目录不存在**: 如果`/etc/ssh_backup`目录不存在,那么我们需要寻找其他备份。可以尝试以下方法: - 检查系统管理员是否在升级OpenSSH时创建了备份。回顾升级步骤(参考引用[3])中是否有指定备份路径。 - 查找整个系统:`sudo find / -name sshd_config*` (注意:这可能会返回大量结果,可以尝试限制在/etc目录下) 5. **重新创建备份(如果需要)**: 如果确实没有备份,而你又需要比较,那么你可以将当前的配置文件复制一份作为备份,然后进行修改,再比较。但注意,这只能比较修改前后的差异,不能和原始版本比较。 6. **正确的比较命令**: 一旦找到正确的备份文件路径,使用正确的路径执行diff命令。例如,如果备份文件实际在`/etc/ssh/sshd_config.old`,则命令为: ```bash diff /etc/ssh/sshd_config.old /etc/ssh/sshd_config ``` 根据引用[4]中的内容,我们可以看到SSH配置文件通常位于`/etc/ssh/sshd_config`,而备份文件的位置则取决于备份方式。 注意:在修改SSH配置文件前,务必备份,以免配置错误导致无法远程连接。 因此,具体步骤总结如下: 步骤1:检查两个文件是否存在 步骤2:如果备份文件不存在,尝试寻找备份文件 步骤3:如果确实找不到备份文件,考虑使用其他方法(如从原始安装包中提取默认配置文件)或重新备份当前文件后再修改 下面我们详细说明每一步的操作命令: </think>针对执行 `diff /etc/ssh_backup/sshd_config /etc/ssh/sshd_config` 出现 "没有那个文件或目录" 错误的问题,请按以下步骤排查解决: ### 🔍 排查步骤 1. **验证备份文件是否存在** ```bash ls -l /etc/ssh_backup/sshd_config ``` - 若返回 `No such file or directory`,说明备份路径错误(常见问题) - 正确备份路径通常是 `/etc/ssh/sshd_config.bak` 或 `/etc/ssh/sshd_config.orig` 2. **检查默认配置文件位置** ```bash ls -l /etc/ssh/sshd_config # 验证主配置是否存在 ``` - 正常应显示:`-rw-------. 1 root root 3907 Aug 10 2021 /etc/ssh/sshd_config` 3. **查找实际备份文件** ```bash sudo find /etc/ssh/ -name "*sshd_config*" -type f ``` - 常见备份命名: `sshd_config.bak`、`sshd_config.old`、`sshd_config.orig` ### ✅ 解决方案 #### 情况1:备份文件路径错误(最常见) ```bash # 使用正确备份路径比较 diff /etc/ssh/sshd_config{.bak,} # 简写形式 # 或完整写法 diff /etc/ssh/sshd_config.bak /etc/ssh/sshd_config ``` #### 情况2:备份文件丢失 ```markdown 1. **从安装包提取默认配置**: ```bash rpm -ql openssh-server | grep "sshd_config$" # 输出示例:/etc/ssh/sshd_config.rpmnew diff /etc/ssh/sshd_config.rpmnew /etc/ssh/sshd_config ``` 2. **重建备份**: ```bash sudo cp /etc/ssh/sshd_config{,.backup} # 创建新备份 diff /etc/ssh/sshd_config.backup /etc/ssh/sshd_config ``` #### 情况3:配置文件被移动(参考引用[4]) ```bash # 检查非常规路径 ls -l /data/ssh/sshd_config # 引用[4]中的特殊路径 # 若存在则调整路径 diff /data/ssh/sshd_config /etc/ssh/sshd_config ``` ### ️ 操作注意事项 1. 始终使用 `sudo` 查看系统文件 2. 修改配置文件前备份: ```bash sudo cp /etc/ssh/sshd_config{,.$(date +%Y%m%d)} ``` 3. 重启SSH服务生效: ```bash sudo systemctl restart sshd # 引用[3] ``` ### 📍 关键配置路径总结 | 文件类型 | 标准路径 | 备份路径示例 | |----------------|--------------------------|----------------------------| | 主配置文件 | `/etc/ssh/sshd_config` | `/etc/ssh/sshd_config.bak` | | RPM默认配置 | `/etc/ssh/sshd_config.rpmnew` | - | | 密钥文件 | `/etc/ssh/ssh_host_*` | 引用[4] | > 通过以上步骤可解决99%的路径错误问题,若仍报错可能是文件权限问题(使用 `ls -l` 检查)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值