general03
general03

Reputation: 863

Use sudo with SSH-Session from PowerShell

On my Windows computer I use SSH-Session module on PowerShell and I want to use sudo in order to execute special command in my server.

But when I launch my sudo command through SSH-Session I have this error:

sudo: no tty present and no askpass program specified

I don't want to use PuTTY or the ssh command, so the parameter -l is not the issue!

If it's possible I don't want to change the SSH server configuration.

I want to know how to force the pseudo allocation tty in PowerShell?

Thanks

Upvotes: 1

Views: 6683

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202168

The SSH-Session module is based on SSH.NET library.

The SSH.NET library does support pseudo terminal allocation, but the SSH-Session module does not expose the functionality.

You would have to modify SSH-Session code to make it available.

  • Either use the Shell class (SshClient.CreateShell), which implicitly requests pseudo terminal.

  • Or explicitly request pseudo terminal using the ChannelSession.SendPseudoTerminalRequest.


Or modify your sudoers configuration file not to require pseudo terminal for sudo (remove the requiretty option, which is off by default, by the way).


Or use SSH.NET directly, without the SSH-Session module.

See these questions for some code:

Upvotes: 1

general03
general03

Reputation: 863

You can now use the Open SSH exe, push by Microsoft here.

After launch PowerShell as administrator

ssh 192.168.1.123 -p 22 -l general03

Upvotes: 0

Related Questions