diff --git a/terminus-ssh/src/services/ssh.service.ts b/terminus-ssh/src/services/ssh.service.ts index 9e9fa64b..69c8a9a2 100644 --- a/terminus-ssh/src/services/ssh.service.ts +++ b/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 { 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 diff --git a/terminus-ssh/webpack.config.js b/terminus-ssh/webpack.config.js index 2f0c5613..f2a8f0ae 100644 --- a/terminus-ssh/webpack.config.js +++ b/terminus-ssh/webpack.config.js @@ -39,6 +39,7 @@ module.exports = { 'node-ssh', 'xkeychain', 'wincredmgr', + 'path', /^rxjs/, /^@angular/, /^@ng-bootstrap/,