Skip to content

tty  #28

Closed
Closed
tty #28
@sjclemmy

Description

@sjclemmy

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

andrewrjones commented on Oct 15, 2013

@andrewrjones
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

sjclemmy commented on Oct 15, 2013

@sjclemmy
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

That-David-Guy commented on Nov 25, 2013

@That-David-Guy

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

sjclemmy

sjclemmy commented on Nov 25, 2013

@sjclemmy
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

That-David-Guy commented on Nov 28, 2013

@That-David-Guy

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      tty · Issue #28 · israelroldan/grunt-ssh