pty for root user and sudo commands with grunt-ssh

782 Views Asked by At

from issue 143 in grunt-ssh :

I'm trying to perform the following:

  1. connect via ssh as a regular user
  2. switch to root user and execute a command with privileges, e.g.: ls /root
  3. exit root
  4. close connection as the regular user (this is could be optional)

I have this configuration

sshexec: {
  test: {
    command: [
      'su',  // switch to root user
      'ls /root',  // execute command with privileges
      'exit',  // exit root session
    ],
    options: {
      host: '<%= env.host %>', // host connection
      username: '<%= env.username %>',  // regular user
      password: '<%= env.password %>',  // regular user password
      pty: true,
    }
  }
}

from the docs:

pty :boolean/object

Set to true to allocate a pseudo-tty with defaults, or an object containing specific pseudo-tty settings (see 'Pseudo-TTY settings'). Setting up a pseudo-tty can be useful when working with remote processes that expect input from an actual terminal (e.g. sudo's password prompt).

Apparently there are no ways (or examples at least) to perform what I'm searching for, but I think a use case like this wouldn't be odd to happen. Is it possible to achieve the above steps with this library? Can somebody provide more information about a possible pty object configuration, and the advantages/limitations about that?

Important

Due to security measures on the hosts, I cannot :

  1. connect via ssh as root directly
  2. pipe the password to sudo command e.g.: "echo | sudo -S ls /root"
0

There are 0 best solutions below