tty
sjclemmy opened this issue · 5 comments
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?
I don't think it is sending the pty
option through to the exec
, 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:
sshexec: {
test: {
command: 'sudo uptime',
options: {
config: 'myhost',
pty: true
}
},
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?
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.
I'm stumped on this problem as well. Is there an example of the work around I can view?
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
}
}
}
Cool.
I started rewritting the grunt-ssh as grunt-shell commands, like so
shell: {
makeReleaseDir: {
command: 'ssh -t -t user@server "sudo mkdir -m 777 -p /path/to/site/' + dirname + '/logs"',
options: {
stdout: true
}
},
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.