Page 1 of 2

Problem with SSH Cmd Shell connection

Posted: Fri 04 Aug 2017 20:31
by drmoorejr
Hi,


I keep getting the "Storage is no set." pop-up. I don;t even know what this means as it doesn't seem to be a complete sentence. Here is my procedure:

Code: Select all


procedure TipiqControlForm1.sshclientCmd(CMD: String);
begin
  TnetPanel.Visible := False;
  SSHPanel.Visible := True;
  SSHclient1 := TScSSHClient.Create(self);
  ScSSHChannel1 := TScSSHChannel.Create(SSHclient1);
  SSHClient1.HostName := HOST;
  SSHClient1.Port := strtoint(PORT);
  SSHClient1.User := USER;
  SSHClient1.Password := PSWD;
  SSHclient1.Connect;
  ScSSHChannel1.Connect;
  CMDShell := TScSSHShell.Create(self);
  // This is probably redundant but here it is anyway:
  CMDShell.Client.HostName := SSHClient1.HostName;
  CMDShell.Client.Port := SSHClient1.Port;
  CMDShell.Client.User := SSHClient1.User;
  CMDShell.Client.Password := SSHClient1.Password;

  if(not SSHClient1.Connected) then
    messageDlg('NO SSH CONNECTION!',mtError, mbOKCancel, 0);

  if SSHclient1.Connected then
  begin
    CMDShell.Connect;
    sshConsole.Lines.Clear;
    sshConsole.Lines.Add('READY FOR COMMANDS!');
    if(CMD = 'daemon_restart') then
    begin
      CMDShell.WriteString('daemon_stop' + #13#10);
      //SSH.ExecuteCommand('daemon_stop');
      sleep(3000);
      CMDShell.WriteString('daemon_start' + #13#10);
      //SSH.ExecuteCommand('daemon_start');
    end
    else
    begin
      //SSH.WriteString(CMD);
      CMDShell.ExecuteCommand(CMD);
    end;
    CMDShell.Disconnect;
    SSHClient1.Disconnect;

  end
  else
    sshConsole.Lines.Add('Cannot connect.');

  SSHclient1.Destroy;
  SSHclient1.Free;
end;



What the heck am I over looking? The documentation doesn't seem to show enough about this. Do I need storage configured if I am passing in password and username in my procedure?

Please help!

Re: Problem with SSH Cmd Shell connection

Posted: Mon 07 Aug 2017 12:14
by ViktorV
This error occurs if the TScSSHClient.KeyStorage property is not set : https://www.devart.com/sbridge/docs/tsc ... torage.htm
Therefore, to solve the issue, you should use the TScStorage descendant and set the TScSSHClient.KeyStorage property.

Re: Problem with SSH Cmd Shell connection

Posted: Mon 07 Aug 2017 12:21
by drmoorejr
So I need this even if I do not use keys?

Re: Problem with SSH Cmd Shell connection

Posted: Mon 07 Aug 2017 12:40
by ViktorV
Server key verification always takes place, regardless the client authorization method, therefore you should always set the TScSSHClient.KeyStorage property.

Re: Problem with SSH Cmd Shell connection

Posted: Mon 07 Aug 2017 13:32
by drmoorejr
Hi,

That's right, in the linux/openssh/bash world it would be stored in the known_hosts file. Can you give me an example of the minimal I need to do. I see a large list of sub properties under the ScSSHClient.KeyStrorage property.


Thanks! IF this works out. I will be purchasing 2 licenses for this dev kit one for the company and one for my Rad Studio installation, since SSH connections are needed..

Re: Problem with SSH Cmd Shell connection

Posted: Tue 08 Aug 2017 06:35
by ViktorV
In general, for correct work, it is enough to use the default properties. It is enough to place the TScStorage descendant on the form and set it to the TScSSHClient.KeyStorage property. If you want to change some properties of the TScStorage descedant, please refer to SecureBridge documentation for the required information.
Note, SecureBrisge distribution includes our SSHClientApp demo project demonstrating the use of the TScSSHShell component. You can find the SSHClientApp project in the% SecureBridgeDemos%\SSHClientApp directory. %SecureBridgeDemos% is the directory where SecureBridge Demo projects are installed on your computer.

Re: Problem with SSH Cmd Shell connection

Posted: Tue 08 Aug 2017 11:46
by drmoorejr
I based my code off the example, this is why I'm puzzled as to why it's not working.

Re: Problem with SSH Cmd Shell connection

Posted: Tue 08 Aug 2017 13:16
by drmoorejr
I was able to get it to go past that last error but adding :

SSHClient1.KeyStorage := ScFileStorage1.keys.Storage;

now I am getting "Format of server server is invalid..."

Re: Problem with SSH Cmd Shell connection

Posted: Wed 09 Aug 2017 09:41
by ViktorV
Please use next code:

Code: Select all

SSHClient1.KeyStorage := ScFileStorage1;
Please specify the full error message.

Re: Problem with SSH Cmd Shell connection

Posted: Wed 09 Aug 2017 13:36
by drmoorejr
"Format of server version is invalid..."

Re: Problem with SSH Cmd Shell connection

Posted: Wed 09 Aug 2017 14:13
by ViktorV
Please provide the text, which goes after the word invalid instead of "..."

Re: Problem with SSH Cmd Shell connection

Posted: Wed 09 Aug 2017 14:33
by drmoorejr
Sorry I paste the wrong text into window twice..

The error related to the SSH connection is: "Host key not verified".

Re: Problem with SSH Cmd Shell connection

Posted: Wed 09 Aug 2017 15:33
by drmoorejr
I have been working for 2 decades in a Unix/Linux environment, mostly as a Sys Admin / Devops or C programming. This Delphi/SecureBridge is not very clear. So I fully understand the role of Keys, Cert and interactive password authentication. The API here is not very intuitive. I just need to get this to work. I did set my Authentication property in my SSHClient to "atPassword" so I am not sure why this is not working. I see another entry / post in this forum related to this issue, but nothing was stated as to EXACTLY what was done to fix. The documentation shows a lot of properties and procedures, nothing showing proper usage.


How do I use TScServerKeyValidate? It appears that this is to be used...

Re: Problem with SSH Cmd Shell connection

Posted: Wed 09 Aug 2017 17:20
by drmoorejr
Chasing down the issue, and searching lead me here: viewtopic.php?f=27&t=23115&p=124718#p124718

However.. the example is not working for me, I get an error.. I am about to give up on this library and just write my own from Indy10... A paid for product should not be this poor in support.

Re: Problem with SSH Cmd Shell connection

Posted: Thu 10 Aug 2017 07:13
by ViktorV
The "Host key not verified" error occurs if the key received from the server and the key specified in HostKeyName do not match. You should handle the TScSSHClient.OnServerKeyValidate event. You can find the more detailed information about this event in SecureBridge help. Also you can look at the sample of this event handling in the SFTPClient demo project. The SFTPClient demo project is located at %SecureBridgeDemos%\SFTPClient. %SecureBridgeDemos% is the path where SecureBridge demo projects are installed on your computer.