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

标签 .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: 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/

相关文章:

c# - Google Calendar Api v3 事件日期时间

eclipse - 尝试通过 SSH 连接到个人 Git 服务器时 Eclipse 中出现 "Algorithm negotiation fail"错误

linux - 如何在两个linux系统上使用sz命令

linux - 如何使用 sudo 进行输出重定向?

Docker:为什么我需要在 Ubuntu 中使用 sudo?

c# - 是否有用于从 .NET 搜索 Amazon CloudSearch 的库?

.net - 为什么 Microsoft .NET Framework Client Profile 是 256 MB?

c# - 通过 log4net 可配置的敏感数据屏蔽

linux - Xmanager 无法在 Centos 上运行

linux - 使用 root 权限从 Perl CGI 程序运行脚本