debug: add SSH auth diagnostic logging

Logs key format, length, auth method selection, and ssh2 debug
output for auth/key events to diagnose why key auth is rejected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell 2026-03-14 01:08:54 -04:00
parent 11e1705110
commit 36c8527c28

View File

@ -75,6 +75,11 @@ export class SshConnectionService {
host: host.hostname, host: host.hostname,
port: host.port, port: host.port,
username: cred?.username || 'root', username: cred?.username || 'root',
debug: (msg: string) => {
if (msg.includes('auth') || msg.includes('Auth') || msg.includes('key') || msg.includes('Key')) {
this.logger.log(`[SSH-DEBUG] ${msg}`);
}
},
hostVerifier: (key: Buffer, verify: (accept: boolean) => void) => { hostVerifier: (key: Buffer, verify: (accept: boolean) => void) => {
const fingerprint = createHash('sha256').update(key).digest('base64'); const fingerprint = createHash('sha256').update(key).digest('base64');
const fp = `SHA256:${fingerprint}`; const fp = `SHA256:${fingerprint}`;
@ -104,8 +109,14 @@ export class SshConnectionService {
if (cred.sshKey.passphrase) { if (cred.sshKey.passphrase) {
connectConfig.passphrase = cred.sshKey.passphrase; connectConfig.passphrase = cred.sshKey.passphrase;
} }
this.logger.log(`[SSH] Using key auth for ${connectConfig.username}@${connectConfig.host}:${connectConfig.port}`);
this.logger.log(`[SSH] Key starts with: ${cred.sshKey.privateKey.substring(0, 40)}...`);
this.logger.log(`[SSH] Key length: ${cred.sshKey.privateKey.length}, has passphrase: ${!!cred.sshKey.passphrase}`);
} else if (cred?.password) { } else if (cred?.password) {
connectConfig.password = cred.password; connectConfig.password = cred.password;
this.logger.log(`[SSH] Using password auth for ${connectConfig.username}@${connectConfig.host}:${connectConfig.port}`);
} else {
this.logger.warn(`[SSH] No auth method available for host ${hostId}`);
} }
client.connect(connectConfig); client.connect(connectConfig);