-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-authentication.ts
More file actions
45 lines (35 loc) · 999 Bytes
/
agent-authentication.ts
File metadata and controls
45 lines (35 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { SSHSession, AgentDetector } from '../lib';
async function main() {
// Detect available agents
console.log('Detecting SSH agents...');
const agents = AgentDetector.detectAll();
if (agents.length === 0) {
console.log('No SSH agents found!');
process.exit(1);
}
console.log(`Found ${agents.length} agent(s):`);
agents.forEach((agent) => {
console.log(` - ${agent.type}: ${agent.socketPath}`);
});
// Use the first agent
const agent = agents[0];
console.log(`\nUsing ${agent.type} agent...`);
const session = new SSHSession({
host: 'example.com',
port: 22,
user: 'username',
agentSocket: agent.socketPath
});
try {
console.log('Connecting...');
await session.connect();
console.log('Authenticating with agent...');
await session.authenticate({ useAgent: true });
console.log('Success!');
await session.disconnect();
} catch (err) {
console.error('Error:', err);
process.exit(1);
}
}
main();