Browse Source

ssh agent support (closes #251)

Eugene Pankov 8 years ago
parent
commit
dfd1ffbffc
2 changed files with 19 additions and 2 deletions
  1. 18 2
      terminus-ssh/src/services/ssh.service.ts
  2. 1 0
      terminus-ssh/webpack.config.js

+ 18 - 2
terminus-ssh/src/services/ssh.service.ts

@@ -2,7 +2,8 @@ import { Injectable, NgZone } from '@angular/core'
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
 import { Client } from 'ssh2'
 import * as fs from 'mz/fs'
-import { AppService } from 'terminus-core'
+import * as path from 'path'
+import { AppService, HostAppService, Platform } from 'terminus-core'
 import { TerminalTabComponent } from 'terminus-terminal'
 import { SSHConnection, SSHSession } from '../api'
 import { PromptModalComponent } from '../components/promptModal.component'
@@ -12,7 +13,6 @@ const { SSH2Stream } = require('ssh2-streams')
 let xkeychain
 let wincredmgr
 try {
-    console.log(1)
     xkeychain = require('xkeychain')
 } catch (error) {
     try {
@@ -28,6 +28,7 @@ export class SSHService {
         private app: AppService,
         private zone: NgZone,
         private ngbModal: NgbModal,
+        private hostApp: HostAppService,
     ) {
     }
 
@@ -79,6 +80,11 @@ export class SSHService {
 
     async connect (connection: SSHConnection): Promise<TerminalTabComponent> {
         let privateKey: string = null
+        let keyPath = path.join(process.env.HOME, '.ssh', 'id_rsa')
+        if (!connection.privateKey && await fs.exists(keyPath)) {
+            connection.privateKey = keyPath
+        }
+
         if (connection.privateKey) {
             try {
                 privateKey = (await fs.readFile(connection.privateKey)).toString()
@@ -117,12 +123,22 @@ export class SSHService {
                 }
                 finish(results)
             }))
+
+            let agent: string = null
+            if (this.hostApp.platform === Platform.Windows) {
+                agent = 'pageant'
+            } else {
+                agent = process.env.SSH_AUTH_SOCK
+            }
+
             ssh.connect({
                 host: connection.host,
                 username: connection.user,
                 password: privateKey ? undefined : '',
                 privateKey,
                 tryKeyboard: true,
+                agent,
+                agentForward: !!agent,
             })
 
             let keychainPasswordUsed = false

+ 1 - 0
terminus-ssh/webpack.config.js

@@ -39,6 +39,7 @@ module.exports = {
     'node-ssh',
     'xkeychain',
     'wincredmgr',
+    'path',
     /^rxjs/,
     /^@angular/,
     /^@ng-bootstrap/,