Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tty #28

Closed
sjclemmy opened this issue Sep 18, 2013 · 5 comments
Closed

tty #28

sjclemmy opened this issue Sep 18, 2013 · 5 comments

Comments

@sjclemmy
Copy link

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?

@andrewrjones
Copy link
Collaborator

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?

@sjclemmy
Copy link
Author

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
Copy link

I'm stumped on this problem as well. Is there an example of the work around I can view?

@sjclemmy
Copy link
Author

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants