adds ability to set 'privateKey' file path

This commit is contained in:
samueleaton 2016-05-05 15:49:34 -06:00
parent 2e265ea6a8
commit 6242fadb99
3 changed files with 36 additions and 6 deletions

View file

@ -148,6 +148,28 @@ autossh({
});
```
#### Specifying the Private Key File
Select a file from which the identity (private key) for public key authentication is read. The default is `~/.ssh/id_rsa`.
You can set the private file path as `privateKey` in the object you pass to `autossh`.
```javascript
autossh({
host: '111.22.333.444',
username: 'root',
localPort: 64444,
remotePort: 5432,
privateKey: '~/.ssh/github_rsa'
})
.on('error', err => {
console.error('ERROR: ', err);
})
.on('connect', connection => {
console.log('Tunnel established on port ' + connection.localPort);
console.log('pid: ' + connection.pid);
});
```
#### Adjusting/Disabling Max Poll Count

View file

@ -49,6 +49,8 @@ var AutoSSH = function (_EventEmitter) {
_this.serverAliveCountMax = typeof conf.serverAliveCountMax === 'number' ? conf.serverAliveCountMax : 1;
_this.privateKey = conf.privateKey || null;
setImmediate(function () {
var confErrors = _this.getConfErrors(conf);
@ -180,14 +182,16 @@ var AutoSSH = function (_EventEmitter) {
key: 'generateExecString',
value: function generateExecString() {
var bindAddress = this.localPort + ':localhost:' + this.remotePort;
var userAtHost = this.username + '@' + this.host;
var exitOnFailure = '-o "ExitOnForwardFailure yes"';
var serverAliveInterval = '-o ServerAliveInterval=' + this.serverAliveInterval;
var serverAliveCountMax = '-o ServerAliveCountMax=' + this.serverAliveCountMax;
var options = exitOnFailure + ' ' + serverAliveInterval + ' ' + serverAliveCountMax;
var execString = this.execString = 'ssh -NL ' + bindAddress + ' ' + options + ' ' + userAtHost;
var privateKey = this.privateKey ? '-i ' + this.privateKey : '';
var userAtHost = this.username + '@' + this.host;
return execString;
this.execString = 'ssh -NL ' + bindAddress + ' ' + options + ' ' + privateKey + ' ' + userAtHost;
return this.execString;
}
/*

View file

@ -25,6 +25,8 @@ class AutoSSH extends EventEmitter {
this.serverAliveCountMax = typeof conf.serverAliveCountMax === 'number' ?
conf.serverAliveCountMax : 1;
this.privateKey = conf.privateKey || null;
setImmediate(() => {
const confErrors = this.getConfErrors(conf);
@ -148,14 +150,16 @@ class AutoSSH extends EventEmitter {
*/
generateExecString() {
const bindAddress = `${this.localPort}:localhost:${this.remotePort}`;
const userAtHost = `${this.username}@${this.host}`;
const exitOnFailure = '-o "ExitOnForwardFailure yes"';
const serverAliveInterval = `-o ServerAliveInterval=${this.serverAliveInterval}`;
const serverAliveCountMax = `-o ServerAliveCountMax=${this.serverAliveCountMax}`;
const options = `${exitOnFailure} ${serverAliveInterval} ${serverAliveCountMax}`;
const execString = this.execString = `ssh -NL ${bindAddress} ${options} ${userAtHost}`;
const privateKey = this.privateKey ? `-i ${this.privateKey}` : '';
const userAtHost = `${this.username}@${this.host}`;
return execString;
this.execString = `ssh -NL ${bindAddress} ${options} ${privateKey} ${userAtHost}`;
return this.execString;
}
/*