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

Function modifySSHConfig

ssh/ssh.ts:234–259  ·  view source on GitHub ↗
(
  key: string,
  value: string,
  backup: boolean = true
)

Source from the content-addressed store, hash-verified

232// 帮助文本
233// SSH服务重启通用函数
234const restartSSHService = async (): Promise<{ success: boolean; command?: string }> => {
235 const commands: Array<{ file: string; args: string[]; label: string }> = [
236 { file: "systemctl", args: ["restart", "sshd"], label: "systemctl restart sshd" },
237 { file: "systemctl", args: ["restart", "ssh"], label: "systemctl restart ssh" },
238 { file: "service", args: ["sshd", "restart"], label: "service sshd restart" },
239 { file: "service", args: ["ssh", "restart"], label: "service ssh restart" },
240 { file: "/etc/init.d/ssh", args: ["restart"], label: "/etc/init.d/ssh restart" },
241 ];
242
243 for (const command of commands) {
244 try {
245 await execFileAsync(command.file, command.args);
246 return { success: true, command: command.label };
247 } catch { }
248 }
249 return { success: false };
250};
251
252// SSH配置修改通用函数
253const modifySSHConfig = async (
254 key: string,
255 value: string,
256 backup: boolean = true
257): Promise<string> => {
258 const timestamp = dayjs().format("YYYYMMDD_HHmmss");
259 const configPath = "/etc/ssh/sshd_config";
260
261 if (backup) {
262 fs.copyFileSync(configPath, `${configPath}.backup.${timestamp}`);

Callers 6

generateSSHKeysMethod · 0.85
changeSSHPortMethod · 0.85
togglePasswordAuthMethod · 0.85
toggleKeyAuthMethod · 0.85
toggleRootLoginMethod · 0.85
enableRootAccountMethod · 0.85

Calls 1

shellEscapeFunction · 0.85

Tested by

no test coverage detected