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

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

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