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

Method enableRootAccount

ssh/ssh.ts:1204–1253  ·  view source on GitHub ↗
(msg: Api.Message, args: string[])

Source from the content-addressed store, hash-verified

1202
1203 // 重启SSH服务使配置生效
1204 const restartResult = await restartSSHService();
1205 if (!restartResult.success) {
1206 throw new Error("无法重启SSH服务");
1207 }
1208
1209 let statusText: string;
1210 let securityTip: string;
1211
1212 if (enable) {
1213 statusText = "✅ 允许所有登录方式";
1214 securityTip = "⚠️ <b>安全提示:</b> 已开启所有root登录方式,建议使用强密码";
1215 } else if (keyOnly) {
1216 statusText = "🔐 仅允许密钥登录";
1217 securityTip = "🛡️ <b>安全提示:</b> Root密码登录已禁用,仅允许SSH密钥登录";
1218 } else {
1219 statusText = "❌ 完全禁止登录";
1220 securityTip = "🛡️ <b>安全提示:</b> Root登录已完全禁用,请确保有其他用户账户可用";
1221 }
1222
1223 await msg.edit({
1224 text: `✅ <b>Root登录配置已更新</b>\n\n状态: ${statusText}\n配置值: <code>PermitRootLogin ${authValue}</code>\n备份文件: /etc/ssh/sshd_config.backup.${timestamp}\n\n${securityTip}`,
1225 parseMode: "html"
1226 });
1227 } catch (error: any) {
1228 throw new Error(`配置Root登录失败: ${error.message}`);
1229 }
1230 }
1231
1232 // 启用root账户直接登录
1233 private async enableRootAccount(msg: Api.Message, args: string[]): Promise<void> {
1234 const password = args.join(" ").trim();
1235
1236 if (!password) {
1237 await msg.edit({
1238 text: `❌ <b>请提供root密码</b>\n\n示例: <code>${mainPrefix}ssh enableroot 新密码123</code>\n\n⚠️ <b>说明:</b> 此命令会启用root账户并设置密码,允许直接SSH登录root`,
1239 parseMode: "html"
1240 });
1241 return;
1242 }
1243
1244 if (!validatePassword(password)) {
1245 await msg.edit({
1246 text: "❌ <b>密码不符合要求</b>\n\n• 密码长度至少8位\n• 建议包含数字、字母、特殊字符",
1247 parseMode: "html"
1248 });
1249 return;
1250 }
1251
1252 await msg.edit({ text: "🔄 正在启用root账户直接登录...", parseMode: "html" });
1253
1254 try {
1255 // 1. 解锁root账户
1256 await execFileAsync("passwd", ["-u", "root"]);

Callers 1

handleSSHMethod · 0.95

Calls 6

validatePasswordFunction · 0.85
shellEscapeFunction · 0.85
modifySSHConfigFunction · 0.85
restartSSHServiceFunction · 0.85
htmlEscapeFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected