https://github.com/52cik/ssh-exec-async
Execute a script/file over ssh using Node.JS
https://github.com/52cik/ssh-exec-async
Last synced: 2 months ago
JSON representation
Execute a script/file over ssh using Node.JS
- Host: GitHub
- URL: https://github.com/52cik/ssh-exec-async
- Owner: 52cik
- License: mit
- Created: 2018-11-15T03:34:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-15T04:13:24.000Z (over 6 years ago)
- Last Synced: 2025-03-18T14:08:20.798Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ssh-exec-async
> Execute a script/file over ssh using Node.JS and pipe to and from it
## Install
```sh
$ yarn add ssh-exec-async
```It is written in plain Javascript and uses [ssh2](https://github.com/mscdex/ssh2) for all the heavy lifting.
## Usage
```js
const Client = require('ssh-exec-async')// using ~/.ssh/id_rsa as the private key
const ssh = new Client('[email protected]');(async () => {
const res = await ssh.exec('ls -lh');
console.log(res);
const res2 = await ssh.execFile('test.sh');
console.log(res2);
})();// or using the more settings
const ssh = new Client({
user: 'ubuntu',
host: 'my-remote.com',
password: 'my-user-password',
// key: myKeyFileOrBuffer,
});(async () => {
const res = await ssh.exec('ls -lh');
console.log(res);
const res2 = await ssh.execFile('test.sh');
console.log(res2);
})();
```The test.sh file content:
```bash
cd /datapwd
ls -lh
```## License
MIT