node-ssh icon indicating copy to clipboard operation
node-ssh copied to clipboard

How do I run dd with sudo?

Open DenisVASI9 opened this issue 3 years ago • 2 comments

I run the following code: ssh.exec( 'sudo -S dd if=/mnt/storage/disks/other6 of=/mnt/storage/disks/other7', ['status=progress'], { execOptions: { pty: true }, stdin: '1234', onStdout(chunk) { console.log('stdoutChunk', chunk.toString()); }, onStderr(chunk) { console.log('stderrChunk', chunk.toString()); }, }, ); And everything hangs on this output: hello stdoutChunk 1234 stdoutChunk Password:

DenisVASI9 avatar Apr 26 '21 11:04 DenisVASI9

Try use ‘root’ user. Or Configure password-free on the target host when you use ‘sudo’ command. This is my way, If there is a better way, please let me know.

ltinerary avatar Oct 13 '21 02:10 ltinerary

About six years ago, I wrote a small tool to help with this, https://github.com/steelbrain/Expected-Write

It's not maintained tho, but you get the idea. Request a shell, execute the command, when you get the password prompt, write to the shell

steelbrain avatar Oct 13 '21 09:10 steelbrain