Recent

Author Topic: How to connect to a PC via SSH? (Is it possible?)  (Read 18678 times)

dotniet

  • New Member
  • *
  • Posts: 46
How to connect to a PC via SSH? (Is it possible?)
« on: October 05, 2009, 01:46:04 pm »
Hi.

I need to work (run/edit/delete files) with 12 Linux computer nodes in a cluster. Usually I use SSH to connect to those nodes.
How can I do this from Lazarus?

______________________
I am new to Lazarus but I have good experience with Delphi.

Thanks
 :)

« Last Edit: October 05, 2009, 02:04:13 pm by dotniet »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #1 on: October 05, 2009, 05:10:40 pm »
You can use TProcess that calls plink.exe or ssh. See the input/output example of http://wiki.lazarus.freepascal.org/Executing_External_Programs#Using_input_and_output_of_a_TProcess

dotniet

  • New Member
  • *
  • Posts: 46
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #2 on: October 16, 2009, 12:58:54 pm »
PLink is for Windows. I am running on Linux.

I have tried to run the 'ssh' command via TProcess (see the example here: https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/examples/process) but it is not working. I mean it launches the SSH, then it asks for password and then nothing happens. TProcess returns no output from SSH.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #3 on: October 16, 2009, 01:22:33 pm »
IIRC, when I wrote the example, I used passwordless connections, using a private key file.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #4 on: October 16, 2009, 01:48:44 pm »
ssh doesn't ask for a password through a "virtual" console like a pipe, but it wants a real console.
google on ssh-askpass, maybe it helps
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

dotniet

  • New Member
  • *
  • Posts: 46
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #5 on: October 16, 2009, 03:02:25 pm »
IIRC, when I wrote the example, I used passwordless connections, using a private key file.
Can you provide some keywords to type in google? I need a point from where to start. I have never used private keys.
Thanks.


Quote from: Mark
ssh doesn't ask for a password through a "virtual" console like a pipe, but it wants a real console.
google on ssh-askpass, maybe it helps
SSH asked for password! It pop-up a box (GUI) and let me to type the password. But after that I got no sign of life from it. 

In a different thread, I already announced that the examples for TProcess (on Lazarus web site) are not working. I used those examples to run ssh.
« Last Edit: October 16, 2009, 03:36:38 pm by dotniet »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page

dotniet

  • New Member
  • *
  • Posts: 46
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #7 on: October 16, 2009, 04:59:59 pm »
Thanks. I strated to follow a tutorial on passwordless SSH but I cannot do it bacause I don't have access to stuff. I wil let the network administrator do it. I will let you know how it worked.

I suppose you used SSH with TProcess and sent the input commands to the TProcess. Right?

Thanks again.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #8 on: October 19, 2009, 11:16:34 am »
In a different thread, I already announced that the examples for TProcess (on Lazarus web site) are not working. I used those examples to run ssh.

This was the way I used the remote ssh-debugger option in lazarus. But... I ran gdb over ssh, so I had the output of gdb.
maybe a console itself doesn't work with tprocess
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

dotniet

  • New Member
  • *
  • Posts: 46
Bug: TProcess not working with SSH
« Reply #9 on: October 19, 2009, 04:49:38 pm »
Hi.

I have tried to run SSH via TProcess but it is not working (no output is produced).
Here is the code used (it is the code provided as example on Lazarus wiki page):

Code: [Select]
program launchprogram;

 uses
   Classes, SysUtils, Process;

 var
   AProcess: TProcess;
   AStringList: TStringList;

 begin
   AProcess := TProcess.Create(nil);
   AStringList := TStringList.Create;
   AProcess.CommandLine := 'ssh';
   AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
   AProcess.Execute;
   AStringList.LoadFromStream(AProcess.Output);
   writeln(AStringList.text);
   AStringList.Free;
   AProcess.Free;
 end.
          

I am using passwordless SSH.
« Last Edit: October 19, 2009, 05:01:03 pm by dotniet »

dotniet

  • New Member
  • *
  • Posts: 46
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #10 on: October 19, 2009, 04:52:58 pm »
For me, SSH (via TProcess) didn't work. It may be a bug in this new FPC release?
I have starteda new thread about it here: http://forum.lazarus.freepascal.org/index.php/topic,7720.0.html

There is a special place where I can submit bug reports? As I told on this forum, TProcess is not running with many other programs!!

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: Bug: TProcess not working with SSH
« Reply #11 on: October 20, 2009, 12:52:36 am »
did you read the wiki about large output ?
Besides that, when running ssh, it will not exit unless you tell it to, so your program will wait forever on the line AProcess.Execute;
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #12 on: October 20, 2009, 12:53:35 am »
this is not a bug of tproccess, but a flaw in your code logic.

PS.
There is no need to create a separate topic for this, so I merged them.
Also when reporting bugs, use our bugtracker, see 4th link on the left side
« Last Edit: October 20, 2009, 12:58:06 am by Marc »
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

dotniet

  • New Member
  • *
  • Posts: 46
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #13 on: October 20, 2009, 11:57:10 am »

SSH and TProcess is not working with ANY of the "official" examples provided with Lazarus.
There are 3 "simple" examples and one for large output.

Again - the examples are not working ALSO with basic commands like ls.
I don't know how much can be my logic's fault when all I have done was to use the "official" lazarus documentation.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #14 on: October 20, 2009, 03:50:05 pm »
That's strange, since when I wrote the large output example it worked.
I recompiled my example with a 2.2.4 version of fpc and still works. However when trying with ssh, I didn't get output, unless I used the poStderrToOutPut option. It seems that ssh outputs to stderr.
Code: [Select]
[marc@giant procout]$ ./procoutlarge "ls -al"
-- executing --
.
-- executed --
-- linecount = 10 --
| total 868
| drwxrwxr-x   2 marc marc   4096 2009-10-20 15:41 .
| drwxr-xr-x 142 marc marc  20480 2009-10-12 23:16 ..
| -rw-rw-r--   1 marc marc     16 2004-09-30 19:49 out.txt
| -rw-rwxr-x   1 marc marc 386616 2004-09-30 19:44 procout
| -rwxrwxr-x   1 marc marc 441976 2009-10-20 15:41 procoutlarge
| -rw-rw-r--   1 marc marc   7096 2009-10-20 15:41 procoutlarge.o
| -rw-rw-r--   1 marc marc   2015 2004-12-28 22:34 procoutlarge.pp
| -rw-rw-r--   1 marc marc   2016 2004-12-28 22:34 procoutlarge.pp.bak
| -rw-rw-r--   1 marc marc    609 2004-09-30 19:44 procout.pp
-- end --
Code: [Select]
[marc@giant procout]$ ./procerrlarge "ssh -V"
-- executing --
.
-- executed --
-- linecount = 1 --
| OpenSSH_4.7p1, OpenSSL 0.9.8b 04 May 2006
-- end --
« Last Edit: October 20, 2009, 03:52:37 pm by Marc »
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018