(msg: Api.Message)
| 1256 | // 2. 设置root密码 |
| 1257 | await runWithInput("chpasswd", [], `root:${password}\n`); |
| 1258 | |
| 1259 | // 3. 确保SSH允许root登录 |
| 1260 | const currentConfig = await modifySSHConfig("PermitRootLogin", "yes"); |
| 1261 | |
| 1262 | // 4. 确保密码登录开启 |
| 1263 | await modifySSHConfig("PasswordAuthentication", "yes", false); |
| 1264 | |
| 1265 | // 5. 重启SSH服务 |
| 1266 | const restartResult = await restartSSHService(); |
| 1267 | if (!restartResult.success) { |
| 1268 | throw new Error("无法重启SSH服务"); |
| 1269 | } |
| 1270 | |
| 1271 | await msg.edit({ |
| 1272 | text: `✅ <b>Root账户已启用</b>\n\n🔑 Root密码: <code>${htmlEscape(password)}</code>\n🔓 账户状态: 已解锁\n🚪 SSH登录: 已允许\n📄 备份文件: /etc/ssh/sshd_config.backup.${currentConfig}\n\n✨ <b>现在可以直接用root登录SSH了!</b>\n\n⚠️ <b>安全提示:</b>\n• 建议设置复杂密码\n• 考虑配置SSH密钥登录\n• 可用 <code>${mainPrefix}ssh rootlogin keyonly</code> 提升安全性`, |
| 1273 | parseMode: "html" |
| 1274 | }); |
| 1275 | |
| 1276 | } catch (error: any) { |
| 1277 | throw new Error(`启用root账户失败: ${error.message}`); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | // 重启SSH服务 |
| 1282 | private async restartSSH(msg: Api.Message): Promise<void> { |
| 1283 | await msg.edit({ text: "🔄 正在重启SSH服务...", parseMode: "html" }); |
| 1284 | |
| 1285 | try { |
| 1286 | // 使用通用函数重启SSH服务 |
| 1287 | const restartResult = await restartSSHService(); |
| 1288 | |
| 1289 | if (!restartResult.success) { |
| 1290 | throw new Error("无法重启SSH服务,请检查系统类型"); |
| 1291 | } |
| 1292 | |
| 1293 | // 验证SSH服务状态 |
no test coverage detected