0

I've been trying to send a simple line that needs sudo permission on VB.net. I can't use expect inside the SSH request because it's not avaible on my server, which is a Synology

I tried two options:

Dim coString As New Renci.SshNet.PasswordConnectionInfo(serv, port, name, dsPass)
Dim sshClient As New Renci.SshNet.SshClient(coString)
Dim cmd1 As Renci.SshNet.SshCommand

Dim commandString As String = "echo ""plaintext_key"" | sudo -S synoshare --enc_mount genericFolderName myPassphrase"

Try
    sshClient.Connect()
    test.progress.Value = 10
    cmd1 = sshClient.RunCommand(commandString)
    sshClient.Disconnect()

Catch ex As Exception
    MsgBox(ex.Message)
End Try

This just skip sshClient.RunCommand(commandString) after a few seconds but does nothing.

Dim coString As New Renci.SshNet.PasswordConnectionInfo(serv, port, name, dsPass)
Dim sshClient As New Renci.SshNet.SshClient(coString)
Dim modes As New Dictionary(Of Renci.SshNet.Common.TerminalModes, UInt32)

Try
    sshClient.Connect()
    Dim stream = sshClient.CreateShellStream("xterm", 255, 50, 800, 600, 1024, modes)
    Using stream
        test.progress.Value = 10
        stream.Write("sudo synoshare --enc_unmount genericFolderName")
        stream.Expect("Password: ")
        stream.Write(dsPass)
    End Using
    sshClient.Disconnect()

Catch ex As Exception
        MsgBox(ex.Message)
End Try

This one just get stuck forever at stream.Expect("Password: "). I tried to replace Password: (What is written when you type it into the SSH Console) with Password:and passwordbut it didn't change anything.

Thryn
  • 425
  • 2
  • 14
  • 1
    See [Providing subcommands to a command (sudo/su) executed with SSH.NET SshClient.CreateShellStream](https://stackoverflow.com/q/54194139/850848) – Note the `WriteLine`. – Martin Prikryl Jun 05 '20 at 14:17
  • Thanks ! That was it, it works perfectly and is even faster than with the GUI or by Putty SSH – Thryn Jun 05 '20 at 14:24

0 Answers0