Recent

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

dotniet

  • New Member
  • *
  • Posts: 46
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #15 on: October 21, 2009, 04:14:10 pm »
It worked also for me after I have added the poStderrToOutPut option.
THANKS A LOT!

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #16 on: January 02, 2022, 03:39:06 am »
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

The Expect program does work for ssh, and I'd be interested to know if Lazarus can easily do the same thing as this example:

https://www.thegeekstuff.com/2010/10/expect-examples/
6. SSH Login into Another Machine
The example expect program shown below automates the ssh login from one machine to another machine.

Code: Pascal  [Select][+][-]
  1. #!/usr/bin/expect
  2. set timeout 20
  3. set ip [lindex $argv 0]
  4. set user [lindex $argv 1]
  5. set password [lindex $argv 2]
  6. spawn ssh "$user\@$ip"
  7. expect "Password:"
  8. send "$password\r";
  9. interact

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #17 on: January 02, 2022, 05:16:49 am »
Do you really need to use a password? All my local and remote SSH logins are done with public keys and with passwords disabled for better security.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #18 on: January 02, 2022, 09:55:29 am »
I would look at the ssh-askpass model if you really must. I have used ssh-askpass with a lazarus app (using scp but no real diff I expect). Can find the code if you need it. Honestly its not really secure but OK in a private, non-shared access situation. Just. Similarly, password-less keys are again, OK, if its a private and non-shared. But again, only just.

If you have to get what you are doing past a well informed sys-admin, my guess is they will say "NO" !

Is it file access you need ?  sshfs may be an acceptable, you establish a sshfs mount using a real password and then Lazarus app can access files on that mountpoint as if they are local. All you need is sshfs on your desktop, and nothing special remotely.

Davo


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

The Expect program does work for ssh, and I'd be interested to know if Lazarus can easily do the same thing as this example:

https://www.thegeekstuff.com/2010/10/expect-examples/
6. SSH Login into Another Machine
The example expect program shown below automates the ssh login from one machine to another machine.

Code: Pascal  [Select][+][-]
  1. #!/usr/bin/expect
  2. set timeout 20
  3. set ip [lindex $argv 0]
  4. set user [lindex $argv 1]
  5. set password [lindex $argv 2]
  6. spawn ssh "$user\@$ip"
  7. expect "Password:"
  8. send "$password\r";
  9. interact
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #19 on: January 02, 2022, 11:26:16 am »
Thank you for your answers. I am making a small program that Mac users will send its log files to a remote server that only allows sftp. Getting them to also install ssh-askpass or sshfs is likely too difficult. They would like a program with the simplicity of captainftp (or filezilla) where their password is stored in a configuration file, and that program alone sends the file. That is why I was looking for something like TProcess to act like "expect" and send sftp the password.

I would look at the ssh-askpass model if you really must. I have used ssh-askpass with a lazarus app (using scp but no real diff I expect). Can find the code if you need it. Honestly its not really secure but OK in a private, non-shared access situation. Just. Similarly, password-less keys are again, OK, if its a private and non-shared. But again, only just.

If you have to get what you are doing past a well informed sys-admin, my guess is they will say "NO" !

Is it file access you need ?  sshfs may be an acceptable, you establish a sshfs mount using a real password and then Lazarus app can access files on that mountpoint as if they are local. All you need is sshfs on your desktop, and nothing special remotely.

Davo

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #20 on: January 02, 2022, 11:00:35 pm »
Just to be clear Anthony, both ssh-askpass and sshfs are only required on the user's machine, not the remote server. I was not sure which machine you mean when you say "Getting them to also install...".

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #21 on: January 02, 2022, 11:23:32 pm »
Just to be clear Anthony, both ssh-askpass and sshfs are only required on the user's machine, not the remote server. I was not sure which machine you mean when you say "Getting them to also install...".

Davo

Thanks Davo,

I should have been more clear. I meant that the user would be tasked with installing ssh-askpass or sshfs, and neither seem to be super-simple for a non-technical Mac user.

For now, it seems that the expect program is already installed on some Macs, so I will proceed with using that by getting Lazarus to run expect with the ssh password in that command line.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #22 on: January 03, 2022, 12:54:56 am »
Hmm, says https://www.expandrive.com/sshfs-mac/

> The go-to opensource option is the port of SSHFS from Linux by macFUSE. It is a relatively straightforward no-frills command-line appliation without any user interface,...

Without any user interface ??  Its got a perfectly good command line interface !

> One caveat is that like many solutions, it relies on a kernel extension which has been deprecated by macOS and requires a reboot into recovery mode to reduce security level on newer M1 based macs.

Ahh, run away, run away !  You sure don't want to be asking users to do things like that !  So, yep, I agree, thats not going to work.

I can remember days spent trying to get expect scripts to work reliably, so I sympathize ....

Good luck.
Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #23 on: January 03, 2022, 01:32:31 am »
Thanks for digging that up about SSHFS. I will update here if I get an expect solution working.

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: How to connect to a PC via SSH? (Is it possible?)
« Reply #24 on: January 11, 2022, 04:58:06 pm »
I managed to get expect to work on Linux and a Mac. The expect script looks like this:

Code: Pascal  [Select][+][-]
  1. set timeout 20
  2. set sftparameters [lindex $argv 0]
  3. set password [lindex $argv 1]
  4. set localdir [lindex $argv 2]
  5. set remotedir [lindex $argv 3]
  6. set filename [lindex $argv 4]
  7. spawn sftp "$sftparameters"
  8. expect "assword:"
  9. send "$password\r"
  10. expect "sftp>"
  11. send "cd ${remotedir}\r"
  12. expect "sftp>"
  13. send "put ${localdir}${filename}\r"
  14. expect "sftp>"
  15. send "quit\r"
  16. exit
  17.  

I have also attached an example project that runs the script.

 

TinyPortal © 2005-2018