MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / restartSSH

Method restartSSH

ssh/ssh.ts:1258–1290  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

1256 await execFileAsync("passwd", ["-u", "root"]);
1257
1258 // 2. 设置root密码
1259 await runWithInput("chpasswd", [], `root:${password}\n`);
1260
1261 // 3. 确保SSH允许root登录
1262 const currentConfig = await modifySSHConfig("PermitRootLogin", "yes");
1263
1264 // 4. 确保密码登录开启
1265 await modifySSHConfig("PasswordAuthentication", "yes", false);
1266
1267 // 5. 重启SSH服务
1268 const restartResult = await restartSSHService();
1269 if (!restartResult.success) {
1270 throw new Error("无法重启SSH服务");
1271 }
1272
1273 await msg.edit({
1274 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> 提升安全性`,
1275 parseMode: "html"
1276 });
1277
1278 } catch (error: any) {
1279 throw new Error(`启用root账户失败: ${error.message}`);
1280 }
1281 }
1282
1283 // 重启SSH服务
1284 private async restartSSH(msg: Api.Message): Promise<void> {
1285 await msg.edit({ text: "🔄 正在重启SSH服务...", parseMode: "html" });
1286
1287 try {
1288 // 使用通用函数重启SSH服务
1289 const restartResult = await restartSSHService();
1290
1291 if (!restartResult.success) {
1292 throw new Error("无法重启SSH服务,请检查系统类型");
1293 }

Callers 1

handleSSHMethod · 0.95

Calls 3

restartSSHServiceFunction · 0.85
htmlEscapeFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected