How to use node-ssh - 7 common examples

To help you get started, we’ve selected a few node-ssh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikedeboer / jsDAV / lib / DAV / backends / sftp / tree.js View on Github external
initialize: function(options) {
        this.basePath = (options.sftp && options.sftp.home) || "";
        this.sftp = new Sftp();
        var self = this;
        this.timeout = 0;
        this.sftp.init(options.sftp, function(err) {
            // throw it anyway, because it's fatal...
            if (err)
                throw err;
            self.sftp.connect(function(err){
                if (err)
                    throw err;
            });
        });
        AsyncEventEmitter.DEFAULT_TIMEOUT = 10000;
    },
github EvHaus / rocketry / src / Rocketry.js View on Github external
connectToServer (): Promise {
		const {host, private_key_path, user} = this.config;
		const password = ROCKETRY_PW();

		const spinner = ora(`Connecting to ${chalk.yellow(host)}...`).start();

		// Only validate private key path if we're not using a password
		if (private_key_path && !password) validatePrivateKeyPath(private_key_path);

		const client = new nodeSSH();

		const connectConfig: SshConnectConfigType = {
			host,
			username: user,
		};

		if (password) {
			// Passwords are assumed to be base64 encoded
			const decoded = Buffer.from(password, 'base64').toString();
			connectConfig.password = decoded;
		} else {
			connectConfig.privateKey = private_key_path;
			connectConfig.passphrase = this._sshPassword;
		}

		return client.connect(connectConfig)
github getgridea / gridea / src / server / plugins / deploys / sftp.ts View on Github external
async publish() {
    const result = {
      success: true,
      message: '',
    }

    const client = new NodeSsh()

    const { setting } = this.db

    const connectConfig: sftpConnectConfig = {
      host: setting.server,
      port: Number(setting.port),
      type: 'sftp',
      username: setting.username,
    }

    // node-ssh: privateKey is path string.
    if (setting.privateKey) {
      connectConfig.privateKey = setting.privateKey
    } else {
      connectConfig.password = setting.password
    }
github burgerbuds / swiff / src / ssh.js View on Github external
const sshConnect = async ({ host, username, port, sshKeyPath }) => {
    let errorMessage
    // Get the local username so we can get the default key below (macOS path)
    const user = await resolveUsername()
    const sshKeyResolvedPath = !isEmpty(sshKeyPath)
        ? sshKeyPath
        : `/Users/${user}/.ssh/id_rsa`
    // Create a SSH connection
    const ssh = new nodeSsh()
    await ssh
        .connect({
            host: host,
            username: username,
            port: port,
            privateKey: sshKeyResolvedPath,
        })
        .catch(error => (errorMessage = error))
    if (errorMessage)
        return new Error(
            String(errorMessage).includes(
                'Error: Cannot parse privateKey: Unsupported key format'
            )
                ? `Your SSH key isn't in a format Swiff can work with\n  (${sshKeyResolvedPath})\n\n1. Generate a new one with:\n  ${colourNotice(
                      `ssh-keygen -m PEM -b 4096 -f /Users/${user}/.ssh/swiff`
                  )}\n\n2. Then add the key to the server:\n  ${colourNotice(
github garygrossgarten / github-action-scp / src / index.ts View on Github external
private async connect(
    host = "localhost",
    username: string,
    port = 22,
    privateKey: string,
    password: string,
    passphrase: string,
    tryKeyboard: boolean
  ) {
    const ssh = new node_ssh();
    const m1 = await this.colorize(
      "orange",
      `Establishing a SSH connection to ${host}.`
    );
    console.log(m1);

    try {
      await ssh.connect({
        host: host,
        port: port,
        username: username,
        password: password,
        passphrase: passphrase,
        privateKey: privateKey,
        tryKeyboard: tryKeyboard,
        onKeyboardInteractive: tryKeyboard ? keyboardFunction(password) : null
github TencentCloudBase / cloudbase-cli / src / server / node / controller.ts View on Github external
constructor(config: INodeDeployConfig) {
        this.config = {
            username: 'root',
            port: 22,
            remotePath: `/data/tcb-service/${config.name}`,
            ...config
        }
        this.ssh = new NodeSSH()
        this.deployer = new NodeDeployer(this.config)
    }
github TencentCloudBase / cloudbase-cli / src / uploader / node.ts View on Github external
constructor(options: INodeUploaderOptions) {
        this.ssh = new NodeSSH()
        this._options = options
    }

node-ssh

SSH2 with Promises

MIT
Latest version published 1 year ago

Package Health Score

64 / 100
Full package analysis

Popular node-ssh functions