Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
simple-ssh
Advanced tools
Note: I really don't work on this project anymore. It's still fully functional, I'm just not interested in working on it anymore. If you post an issue, I might respond and I might not. If you submit a pull request, I'll most likely accept it. Hopefully it continues to help people around the world. :earth_americas:
A wrapper for the ssh2 client module by Brian White which makes it easier to run a sequence of commands over SSH.
npm install simple-ssh
PATH
:var SSH = require('simple-ssh');
var ssh = new SSH({
host: 'localhost',
user: 'username',
pass: 'password'
});
ssh.exec('echo $PATH', {
out: function(stdout) {
console.log(stdout);
}
}).start();
/*** Using the `args` options instead ***/
ssh.exec('echo', {
args: ['$PATH'],
out: function(stdout) {
console.log(stdout);
}
}).start();
var ssh = new ssh({
host: 'localhost',
user: 'username',
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
})
ssh.exec('this-does-not-exist', {
err: function(stderr) {
console.log(stderr); // this-does-not-exist: command not found
}
}).start();
ssh.exec('exit 69', {
exit: function(code) {
console.log(code); // 69
}
}).start();
ssh.exec('cat > /path/to/remote/file', {
in: fs.readFileSync('/path/to/local/file')
}).start();
ssh
.exec('echo "Node.js"', {
out: console.log.bind(console)
})
.exec('echo "is"', {
out: console.log.bind(console)
})
.exec('echo "awesome!"', {
out: console.log.bind(console)
})
.start();
// Output:
// Node.js
// is
// awesome!
ssh
.exec('exit 1')
.exec('exit 2')
.exec('exit 3');
console.log(ssh.count()); // 3
sudo
ssh.exec('sudo echo "Pseudo-sudo"', {
pty: true,
out: console.log.bind(console)
}).start();
// Echos out any messages the user sent in if 10 or more have been queued
var msgInterval = setInterval(function() {
if (ssh.count() > 10) {
ssh.start();
}
}, 1000);
socket.on('message', function(msg) {
// If a 'reset' message is received, clear previous messages
if (msg === 'reset') {
ssh.reset(function(err) {
if (err) {
throw err;
}
ssh.exec('echo "reset"');
});
} else {
ssh.exec('echo "' + msg + '"');
}
});
ssh.on('error', function(err) {
console.log('Oops, something went wrong.');
console.log(err);
ssh.end();
});
ssh
.on('error', onSSHError)
.on('ready', onSSHReady);
22
)10000
)cd ${this.baseDir}
null
)stdin
stdout
handler
stdout
stderr
handler
stderr
sudo
(default: false
)22
)10000
)baseDir
before each commandSometimes you may find yourself needing to change which commands are executed. The flow can be changed by returning false
from an exit
handler.
Note: This only works if false
is explicitly returned. "Falsy" values are not sufficient (since undefined
is implicitly returned and it's "falsy").
ssh
.exec('pwd', {
exit: function() {
return false;
}
})
.exec('echo "Not executed"')
.start();
ssh
.exec('exit', {
args: [ Math.round(Math.random()) ],
exit: function(code) {
if (code === 1) {
// Setup the new command queue
ssh.exec('echo "new queue"');
return false;
}
}
})
.exec('exit 0', {
exit: function() {
console.log('Previous command did not return false');
}
})
.start();
FAQs
A wrapper for ssh2 to make it easier to perform commands over SSH
We found that simple-ssh demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.