mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-28 21:24:38 +00:00
ssh agent support (closes #251)
This commit is contained in:
@@ -2,7 +2,8 @@ import { Injectable, NgZone } from '@angular/core'
|
|||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { Client } from 'ssh2'
|
import { Client } from 'ssh2'
|
||||||
import * as fs from 'mz/fs'
|
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 { TerminalTabComponent } from 'terminus-terminal'
|
||||||
import { SSHConnection, SSHSession } from '../api'
|
import { SSHConnection, SSHSession } from '../api'
|
||||||
import { PromptModalComponent } from '../components/promptModal.component'
|
import { PromptModalComponent } from '../components/promptModal.component'
|
||||||
@@ -12,7 +13,6 @@ const { SSH2Stream } = require('ssh2-streams')
|
|||||||
let xkeychain
|
let xkeychain
|
||||||
let wincredmgr
|
let wincredmgr
|
||||||
try {
|
try {
|
||||||
console.log(1)
|
|
||||||
xkeychain = require('xkeychain')
|
xkeychain = require('xkeychain')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
try {
|
try {
|
||||||
@@ -28,6 +28,7 @@ export class SSHService {
|
|||||||
private app: AppService,
|
private app: AppService,
|
||||||
private zone: NgZone,
|
private zone: NgZone,
|
||||||
private ngbModal: NgbModal,
|
private ngbModal: NgbModal,
|
||||||
|
private hostApp: HostAppService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +80,11 @@ export class SSHService {
|
|||||||
|
|
||||||
async connect (connection: SSHConnection): Promise<TerminalTabComponent> {
|
async connect (connection: SSHConnection): Promise<TerminalTabComponent> {
|
||||||
let privateKey: string = null
|
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) {
|
if (connection.privateKey) {
|
||||||
try {
|
try {
|
||||||
privateKey = (await fs.readFile(connection.privateKey)).toString()
|
privateKey = (await fs.readFile(connection.privateKey)).toString()
|
||||||
@@ -117,12 +123,22 @@ export class SSHService {
|
|||||||
}
|
}
|
||||||
finish(results)
|
finish(results)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
let agent: string = null
|
||||||
|
if (this.hostApp.platform === Platform.Windows) {
|
||||||
|
agent = 'pageant'
|
||||||
|
} else {
|
||||||
|
agent = process.env.SSH_AUTH_SOCK
|
||||||
|
}
|
||||||
|
|
||||||
ssh.connect({
|
ssh.connect({
|
||||||
host: connection.host,
|
host: connection.host,
|
||||||
username: connection.user,
|
username: connection.user,
|
||||||
password: privateKey ? undefined : '',
|
password: privateKey ? undefined : '',
|
||||||
privateKey,
|
privateKey,
|
||||||
tryKeyboard: true,
|
tryKeyboard: true,
|
||||||
|
agent,
|
||||||
|
agentForward: !!agent,
|
||||||
})
|
})
|
||||||
|
|
||||||
let keychainPasswordUsed = false
|
let keychainPasswordUsed = false
|
||||||
|
@@ -39,6 +39,7 @@ module.exports = {
|
|||||||
'node-ssh',
|
'node-ssh',
|
||||||
'xkeychain',
|
'xkeychain',
|
||||||
'wincredmgr',
|
'wincredmgr',
|
||||||
|
'path',
|
||||||
/^rxjs/,
|
/^rxjs/,
|
||||||
/^@angular/,
|
/^@angular/,
|
||||||
/^@ng-bootstrap/,
|
/^@ng-bootstrap/,
|
||||||
|
Reference in New Issue
Block a user