Closed
Description
Im trying to sudo a command but I'm getting the 'sudo: sorry, you must have a tty to run sudo' error.
To fix this I can send the -t option with ssh. e.g. ssh -t me@host.com "command".
I notice that there is a 'pty' option in ssh2 (which this uses) and I see the pty option if I use the grunt -v option. But alas, it's not working.
I briefly looked at your code and it looks like it should send the option along the chain, but I'm still getting the error. Does it send this option?
Activity
andrewrjones commentedon Oct 15, 2013
I don't think it is sending the
pty
option through to theexec
, but that shouldn't be too hard to fix.I think we just need to change line 76 to
c.exec(command, options.pty, function (err, stream) {
, then pass the options like this:Or, if you want more control,
pty
can be an object with the options from here.Would you be able to give this a try?
sjclemmy commentedon Oct 15, 2013
I think I looked into it a bit more and concluded that it requires calling ssh2 with a different command (I can't remember, shell instead of exec?), so I just used a grunt shell wrapper instead and sent the raw command.
That-David-Guy commentedon Nov 25, 2013
I'm stumped on this problem as well. Is there an example of the work around I can view?
sjclemmy commentedon Nov 25, 2013
I used a different grunt plugin - https://github.com/sindresorhus/grunt-shell and configured like this:
shell: {
updateThePermissions: {
command: 'ssh -t -t user@destination.com "sudo chown -R :user:group path/to/whatever/Im/doing"',
options: {
stdout: true
}
}
}
That-David-Guy commentedon Nov 28, 2013
Cool.
I started rewritting the grunt-ssh as grunt-shell commands, like so
Then re-reading your comment again I realised I could just chown the folder so I would not need the sudo at all. So I did that, then switched back to using grunt-ssh, and it works great.
Thanks for your help.