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

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