使用WinSCP .NET程序集运行命令sudo bash

时间:2015-05-25 13:41:28

标签: .net ssh sudo winscp winscp-net

我正在尝试使用VB.NET和WinSCP运行命令sudo bash

我正在使用此代码:

Try
    Dim mySessionOptions As New SessionOptions
    With mySessionOptions
        .Protocol = Protocol.Sftp
        .HostName = "10.5...."
        .UserName = "hereGoesUsername"
        .Password = "hereGoesPassword"
        .SshHostKeyFingerprint = "ssh-rsa 2048 ......"
    End With
    mySession.Open(mySessionOptions)
    Try
        mySession.ExecuteCommand("sudo bash").Check()

最后一行给我一个错误

  

sudo:没有tty存在且没有指定askpass程序。

我无法输入密码。如果我在Windows上使用命令行,如ssh username@host,那么它要求输入密码,我输入然后我可以运行sudo bash并再次输入密码,但如何使用WinSCP进行操作?

1 个答案:

答案 0 :(得分:1)

您无法使用WinSCP提供密码。阅读technical limitations of WinSCP when executing remote commands

唯一的选择是允许用户在不提供密码的情况下执行命令。

有关一般建议,请参阅How do I change user after login (e.g. su root)?

这篇文章是关于允许一般访问。对于您的特定情况,您可能只能启用特定命令。

但你并没有真正告诉我们你想要实现的目标。我认为sudo bash不是最终目标。你宁愿执行一些命令,对吧?如果您向我们提供更多详细信息,您可能会得到更具体的答案。

相关问题