Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The node-ssh npm package is a lightweight wrapper for SSH2, providing a simple and easy-to-use API for performing SSH operations. It allows you to connect to remote servers, execute commands, transfer files, and manage SSH connections programmatically.
Connecting to a remote server
This feature allows you to establish an SSH connection to a remote server using the provided host, username, and private key.
const { NodeSSH } = require('node-ssh');
const ssh = new NodeSSH();
ssh.connect({
host: 'example.com',
username: 'user',
privateKey: '/path/to/private/key'
}).then(() => {
console.log('Connected to the server');
}).catch(err => {
console.error('Error connecting to the server:', err);
});
Executing commands on a remote server
This feature allows you to execute shell commands on the connected remote server and retrieve the output.
ssh.execCommand('ls -la', { cwd: '/home/user' }).then(result => {
console.log('STDOUT: ' + result.stdout);
console.log('STDERR: ' + result.stderr);
}).catch(err => {
console.error('Error executing command:', err);
});
Transferring files to a remote server
This feature allows you to transfer files from your local machine to the remote server.
ssh.putFile('/local/path/to/file.txt', '/remote/path/to/file.txt').then(() => {
console.log('File transferred successfully');
}).catch(err => {
console.error('Error transferring file:', err);
});
Transferring files from a remote server
This feature allows you to download files from the remote server to your local machine.
ssh.getFile('/local/path/to/file.txt', '/remote/path/to/file.txt').then(() => {
console.log('File downloaded successfully');
}).catch(err => {
console.error('Error downloading file:', err);
});
The ssh2 package is a more low-level SSH client for Node.js, providing a comprehensive set of features for SSH connections, including command execution, file transfers, and tunneling. It offers more control and customization options compared to node-ssh but requires more boilerplate code.
The simple-ssh package is another lightweight SSH client for Node.js, focusing on simplicity and ease of use. It provides basic SSH functionalities like command execution and file transfers but lacks some of the advanced features and flexibility offered by node-ssh.
The ssh2-sftp-client package is a wrapper around the ssh2 package, specifically designed for SFTP operations. It simplifies file transfer operations over SFTP, making it easier to use for file management tasks compared to node-ssh, which provides a broader range of SSH functionalities.
Node-SSH is an extremely lightweight Promise wrapper for ssh2, Period.
var node_ssh, ssh;
node_ssh = require('node-ssh');
ssh = new node_ssh();
ssh.connect({
host: 'localhost',
username: 'steel',
privateKey: '/home/steel/.ssh/id_rsa'
}).then(function() {
// Source, Target
ssh.put('/home/steel/Lab/LocalSource', '/home/steel/Lab/RemoteTarget').then(function() {
console.log("The File thing is done");
}, function(error) {
console.log("Something's wrong");
console.log(error);
});
// Array<Shape('Local' => string, 'Remote' => string)>
ssh.putMulti([{'Local': '/home/steel/Lab/LocalSource', 'Remote': '/home/steel/Lab/RemoteTarget'}]).then(function() {
console.log("The File thing is done");
}, function(error) {
console.log("Something's wrong");
console.log(error);
});
// Source, Target
ssh.get('/home/steel/Lab/RemoteSource', '/home/steel/Lab/LocalTarget').then(function(Contents) {
console.log("The File's contents were successfully downloaded");
}, function(error) {
console.log("Something's wrong");
console.log(error);
});
// Command
ssh.execCommand('hh_client --json', {cwd:'/var/www', stream: 'both'}).then(function(result) {
console.log('STDOUT: ' + result.stdout);
console.log('STDERR: ' + result.stderr);
});
});
class SSH{
constructor()
connect(SSH2Configuration): Promise<void>
mkdir(Path:String): Promise<string>
exec(command: String, args: Array<string>, options: Object{cwd: String, stdin: String, stream: enum{'stdout', 'stderr', 'both'}}): Promise
execCommand(command: String, options: Object{cwd: String, stdin: String, stream: enum{'stdout', 'stderr', 'both'}}): Promise
put(localPath: String, remotePath: String, ?SFTP: SSH2SFTP, ?Retry:Boolean = true): Promise<void>
putMulti(Files:array<Object{Local: String, Remote: String}>, ?SFTP: SSH2SFTP): Promise<void>
get(remoteFile: String, localFile: String, ?SFTP: SSH2SFTP): Promise<?string>
requestSFTP(): Promise<SSH2SFTP>
requestShell(): Promise<SSH2Shell>
end():void
}
This project is licensed under the terms of MIT license. See the LICENSE file for more info.
2.0.5
FAQs
SSH2 with Promises
The npm package node-ssh receives a total of 45,559 weekly downloads. As such, node-ssh popularity was classified as popular.
We found that node-ssh demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.