I'm trying to perform the following:
- connect via ssh as a regular user
- switch to root user and execute a command with privileges, e.g.: ls /root
- exit root
- 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 :
- connect via ssh as root directly
- pipe the password to sudo command e.g.: "echo | sudo -S ls /root"