feat: новая функция

This commit is contained in:
2025-11-06 18:07:18 +03:00
parent 348dfa5f62
commit 1466de718f
4 changed files with 62 additions and 49 deletions

View File

@@ -1,6 +1,13 @@
const { exec } = require('child_process');
const os = require('os');
const path = require('path');
const log = require('./logger');
const sshDir = path.join(os.homedir(), '.ssh');
const privateKeyPath = path.join(sshDir, 'id_rsa');
const publicKeyPath = `${privateKeyPath}.pub`;
const sshConfigPath = path.join(sshDir, 'config');
/**
* Выполнение команд локально (на хосте)
*/
@@ -24,20 +31,20 @@ const createSshKeys = async (email) => {
return new Promise((resolve) => {
// Сначала исправляем права доступа к SSH конфигу
exec('chmod 600 /root/.ssh/config 2>/dev/null || true', (configError) => {
exec(`mkdir -p "${sshDir}" && chmod 700 "${sshDir}" && chmod 600 "${sshConfigPath}" 2>/dev/null || true`, (configError) => {
if (configError) {
log.warn('Не удалось исправить права доступа к SSH конфигу: ' + configError.message);
}
// Создаем SSH ключи
exec(`ssh-keygen -t rsa -b 4096 -C "${email}" -f ~/.ssh/id_rsa -N ""`, (error, stdout, stderr) => {
exec(`ssh-keygen -t rsa -b 4096 -C "${email}" -f "${privateKeyPath}" -N ""`, (error, stdout, stderr) => {
if (error) {
log.error('Ошибка создания SSH ключей: ' + error.message);
} else {
log.success('SSH ключи успешно созданы на хосте');
// Устанавливаем правильные права доступа к созданным ключам
exec('chmod 600 /root/.ssh/id_rsa && chmod 644 /root/.ssh/id_rsa.pub', (permError) => {
exec(`chmod 600 "${privateKeyPath}" && chmod 644 "${publicKeyPath}"`, (permError) => {
if (permError) {
log.warn('Не удалось установить права доступа к SSH ключам: ' + permError.message);
} else {