From 41a970c526ed588cae852aa5608957af5fb33db7 Mon Sep 17 00:00:00 2001 From: UndefinedPony Date: Mon, 6 Jan 2025 12:09:54 +0100 Subject: [PATCH] feat: add permission grant command when key generation fails --- apps/dokploy/server/wss/terminal.ts | 18 +++++++++++++++++- apps/dokploy/server/wss/utils.ts | 7 ------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/dokploy/server/wss/terminal.ts b/apps/dokploy/server/wss/terminal.ts index 87b096c07..9dafba22f 100644 --- a/apps/dokploy/server/wss/terminal.ts +++ b/apps/dokploy/server/wss/terminal.ts @@ -20,6 +20,12 @@ const COMMAND_TO_ALLOW_LOCAL_ACCESS = ` echo "✓ Dokploy SSH key added successfully. Reopen the terminal in Dokploy to reconnect." # ----------------------------------------`; +const COMMAND_TO_GRANT_PERMISSION_ACCESS = ` +# ---------------------------------------- + sudo chown -R $USER:$USER /etc/dokploy/ssh +# ---------------------------------------- +`; + export const getPublicIpWithFallback = async () => { // @ts-ignore let ip = null; @@ -105,7 +111,17 @@ export const setupTerminalWebSocketServer = ( }; } catch (error) { console.error(`Error setting up private SSH key: ${error}`); - ws.send(`Error setting up private SSH key: ${error}`); + ws.send(`Error setting up private SSH key: ${error}\n`); + + if ( + error instanceof Error && + error.message.includes("Permission denied") + ) { + ws.send( + `Please run the following command on your server to grant permission access and then reopen this window to reconnect:${COMMAND_TO_GRANT_PERMISSION_ACCESS}`, + ); + } + ws.close(); return; } diff --git a/apps/dokploy/server/wss/utils.ts b/apps/dokploy/server/wss/utils.ts index e98e50169..cd50130ca 100644 --- a/apps/dokploy/server/wss/utils.ts +++ b/apps/dokploy/server/wss/utils.ts @@ -15,13 +15,6 @@ export const getShell = () => { }; /** Returns private SSH key for dokploy local server terminal. Uses already created SSH key or generates a new SSH key. - * - * In case of permission failures when running locally, run the command below: - -``` -sudo chown -R $USER:$USER /etc/dokploy/ssh -``` - */ export const setupLocalServerSSHKey = async () => { const { SSH_PATH } = paths(true);