我正在尝试使用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: no tty present and no askpass program specified.
我无法输入密码。如果我在Windows上像
ssh username@host
这样使用命令行,那么它会要求输入密码,然后键入,然后我可以运行sudo bash
并再次输入密码,但是如何使用WinSCP呢?
最佳答案
您不能使用WinSCP提供密码。了解有关technical limitations of WinSCP when executing remote commands的信息。
唯一的选择是允许用户在不提供密码的情况下执行您的命令。
有关一般建议,请参见How do I change user after login (e.g. su root)?
本文是关于允许常规访问的。对于您的特定情况,您可能只能启用特定的命令。
但是您并没有真正告诉我们您要达到的目标。我想sudo bash
不是最终目标。您宁愿执行一些命令,对不对?如果您向我们提供更多详细信息,则可能会得到更具体的答案。
关于.net - 使用WinSCP .NET程序集运行命令sudo bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30439776/