Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Commit 104d0d8

Browse files
committed
adds agent support to ssh
1 parent c39018b commit 104d0d8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Connection.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import * as path from 'path'
2424
interface Options {
2525
username?: string
2626
privateKey?: string | Buffer,
27-
passphrase? : string,
27+
agentForward? : boolean,
2828
bastionHost?: string
2929
endHost: string
3030
}
@@ -130,8 +130,13 @@ class SSHConnection {
130130
username: this.options.username,
131131
privateKey: this.options.privateKey
132132
}
133-
if(this.options.passphrase) {
134-
options['passphrase'] = this.options.passphrase
133+
if (this.options.agentForward) {
134+
options['agentForward'] = true
135+
const agentSock = process.env['SSH_AUTH_SOCK'] // guaranteed to give the ssh agent sock if the agent is running
136+
if (agentSock === undefined) {
137+
throw new Error('SSH Agent is not running and not set in the SSH_AUTH_SOCK env variable')
138+
}
139+
options['agent'] = agentSock
135140
}
136141
if (stream) {
137142
options['sock'] = stream

0 commit comments

Comments
 (0)