60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { execSync } from 'child_process';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
function expandTilde(filepath) {
|
|
if (filepath.startsWith('~/')) {
|
|
return path.join(process.env.HOME, filepath.slice(2));
|
|
}
|
|
return filepath;
|
|
}
|
|
|
|
const keyPath = expandTilde('~/.ssh/ds3627xs_gregrjacobs');
|
|
const sshConfig = {
|
|
host: '10.0.0.81',
|
|
port: 2323,
|
|
username: 'GregRJacobs'
|
|
};
|
|
|
|
console.log('🔧 Testing SSH Connection\n');
|
|
console.log(
|
|
`📍 Target: ${sshConfig.username}@${sshConfig.host}:${sshConfig.port}`
|
|
);
|
|
console.log(`🔑 Key: ${keyPath}`);
|
|
|
|
// Check key exists
|
|
if (!fs.existsSync(keyPath)) {
|
|
console.error(`❌ SSH key not found: ${keyPath}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const keyStats = fs.statSync(keyPath);
|
|
console.log(`📂 Key file size: ${keyStats.size} bytes`);
|
|
console.log(`📅 Modified: ${keyStats.mtime}\n`);
|
|
|
|
// Test SSH connection
|
|
console.log('🧪 Testing SSH connection with verbose output:\n');
|
|
const sshCmd = `ssh -v -p ${sshConfig.port} -i "${keyPath}" -o StrictHostKeyChecking=no ${sshConfig.username}@${sshConfig.host} "echo 'SSH connection successful!' && pwd"`;
|
|
|
|
try {
|
|
const output = execSync(sshCmd, {
|
|
encoding: 'utf8',
|
|
timeout: 10000
|
|
});
|
|
console.log('✅ SUCCESS!\n');
|
|
console.log(output);
|
|
} catch (error) {
|
|
console.error('❌ FAILED\n');
|
|
console.error('Error:', error.message);
|
|
console.error('\nDebug Info:');
|
|
if (error.stderr) {
|
|
console.error('Stderr:', error.stderr);
|
|
}
|
|
process.exit(1);
|
|
}
|