Code Monkey home page Code Monkey logo

Comments (4)

sanketbajoria avatar sanketbajoria commented on July 17, 2024

@ionush

Does sudo command require password?

Below is sample, how to call it..

ssh.exec("echo sanket | sudo -S sh -c whoami", undefined,{
               pty: true
           })

Here sanket is sudo password

from ssh2-promise.

ionush avatar ionush commented on July 17, 2024

I'm using this to perform mkdir and it still isn't working:

  try {
    const x = await ssh.exec(
      'echo p4$$w0rd | sudo -S sh -c mkdir /data/testdir',
      undefined,
      {
        pty: true
      }
    );
  } catch (error) {
    console.log('error', error.toString());
  }

I have initialised SSH2Promise with host, username, password.

Other non-sudo commands such as ls work e.g. const res = await ssh.exec('ls /data');

from ssh2-promise.

ionush avatar ionush commented on July 17, 2024

Fixed it. This is because I had special characters in my password, escape using " e.g. sudo "p4$$w0rd" | sudo -S mkdir /data/testdir

from ssh2-promise.

sanketbajoria avatar sanketbajoria commented on July 17, 2024

@ionush

Did you get any error.

try {
    const x = await ssh.exec(
      "echo p4$$w0rd | sudo -S sh -c 'mkdir /data/testdir'",
      undefined,
      {
        pty: true
      }
    );
  } catch (error) {
    console.log('error', error.toString());
  }

Please notice, how i have wrapped mkdir in single quote and outer command in double quote
and also if you do have bash in your machine, then you can use bash instead of sh.

from ssh2-promise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.