How to use the ssh2 function in ssh2

To help you get started, we’ve selected a few ssh2 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 burgerbuds / swiff / src / Swiff.js View on Github external
handleSsh = async () => {
        // Clear the messages so they don't display in our interactive session
        this.setState({ messages: null, removeOptions: true })
        // Set some variables for later
        const serverConfig = this.state.config.server
        const { SWIFF_CUSTOM_KEY } = this.state.localEnv
        // Get the users key we'll be using to connect with
        const user = await resolveUsername()
        // Check if the key file exists
        const privateKey = !isEmpty(SWIFF_CUSTOM_KEY)
            ? SWIFF_CUSTOM_KEY
            : `/Users/${user}/.ssh/id_rsa`
        // Create an interactive shell session
        // https://github.com/mscdex/ssh2#start-an-interactive-shell-session
        let gs = null
        const conn = new ssh2()
        conn.on('ready', () => {
            conn.shell((err, stream) => {
                if (err) throw err
                // Build the commands to run once we're logged in
                const initialCommands = [
                    `cd ${serverConfig.appPath}`,
                    'clear',
                    'll',
                    `echo "\n💁  You're now connected with: ${serverConfig.user}@${serverConfig.host}\nWorking directory: ${serverConfig.appPath}\n"`,
                ].join(' && ')
                // Run the commands
                stream.write(`${initialCommands}\n`)
                stream
                    .on('close', () => {
                        console.log(
                            colourHighlight(
github teambit / bit / src / scope / network / ssh / ssh.js View on Github external
sshAuthentication(key: ?string, passphrase: ?string, skipAgent: boolean = false): Promise {
    const conn = new SSH2();
    return new Promise((resolve, reject) => {
      const sshConfig = this.composeSshAuthObject(key, skipAgent);
      if (!sshConfig) reject();
      conn
        .on('error', (err) => {
          logger.debug('SSH: connection on error event');
          Analytics.addBreadCrumb('ssh', 'connection on error event');
          if (this.hasAgentSocket() && err.message === AUTH_FAILED_MESSAGE) {
            logger.debug('SSH: retry in case ssh-agent failed');
            Analytics.addBreadCrumb('ssh', 'retry in case ssh-agent failed');
            // retry in case ssh-agent failed
            if (err.message === PASSPHRASE_MESSAGE) {
              logger.debug('SSH: Encrypted private key detected, but no passphrase given');
              Analytics.addBreadCrumb('ssh', 'Encrypted private key detected, but no passphrase given');
              if (cachedPassphrase) {
                logger.debug('SSH: trying to use cached passphrase');
github icetee / remote-ftp / lib / connectors / sftp.js View on Github external
connect(info, completed) {
    const self = this;

    self.info = info;
    self.info.debug = true;
    self.customFilePermissions = self.info.filePermissions;

    const debug = self.info.debug;
    const connectInfo = Object.assign({}, self.info);

    delete connectInfo.filePermissions;

    self.status = 'connecting';

    self.ssh2 = new SSH2();

    self.ssh2.on('banner', (msg) => {
      self.emit('greeting', msg);
    });

    self.ssh2.on('ready', () => {
      self.ssh2.sftp((err, sftp) => {
        if (err) {
          self.disconnect();
          return;
        }

        if (self.info.remoteShell) {
          self.emit('openingShell', self.info.remoteShell);

          self.ssh2.shell((shellErr, stream) => {
github teambit / bit / src / scope / network / ssh / ssh.js View on Github external
tokenAuthentication(): Promise {
    const conn = new SSH2();
    return new Promise((resolve, reject) => {
      Analytics.setExtraData('authentication_method', 'token');
      const sshConfig = this.composeTokenAuthObject();
      if (!sshConfig) reject();
      conn
        .on('error', (err) => {
          if (err.message === AUTH_FAILED_MESSAGE) {
            return reject(new AuthenticationFailed());
          }
          return reject(err);
        })
        .on('ready', () => {
          this.connection = conn;
          resolve(this);
        })
        .connect(sshConfig);
github teambit / bit / src / scope / network / ssh / ssh.js View on Github external
userPassAuthentication(): Promise {
    const conn = new SSH2();
    return new Promise((resolve, reject) => {
      return this.composeUserPassObject()
        .then((sshConfig) => {
          conn
            .on('error', (err) => {
              if (err.message === AUTH_FAILED_MESSAGE) {
                return reject(new AuthenticationFailed());
              }
              return reject(err);
            })
            .on('ready', () => {
              this.connection = conn;
              resolve(this);
            })
            .connect(sshConfig);
        })
github teambit / bit / src / scope / network / ssh / ssh.ts View on Github external
const connectWithConfigP = () => {
      const conn = new SSH2();
      return new Promise((resolve, reject) => {
        conn
          .on('error', err => {
            reject(err);
          })
          .on('ready', () => {
            resolve(conn);
          })
          .connect(sshConfig);
      });
    };
    try {