QProcess && ssh && write password
-
Hi all,
I need to star an ssh session from my application to a remote server.
I start the session with a QProcess.
The executed command is something like:
@
ssh -R 59000:localhost:5900 remote.server.com -f -N
@
but after I execute it, I must pass the password.How can I do that?
-
First of all, I would expect that ssh checks if its stdin is connected to an interactive terminal and only then ask for a password. Usually command line tools check of presence of a tty using the stty(2) syscall. And you can't expect to much of QProcess, for sure it won't support terminals. That said, check the documentation, it clearly states, that QProcess is a QIoDevice and you can write to stdin of your child process simply by calling QIoDevice::write(). Before writing ensure the process image is loaded already by calling QProcess::waitForStarted().
-
I've never used QProcess this way. I only used it to star an application that didn't require input.
Is there an example?
-
Take a look at the official "documentation":http://doc.qt.nokia.com/4.7/qprocess.html#details . Scroll down, there is an example included.
-
Both for improved security and improved convenience, I would use private/public key authentication.
-
[quote author="unclewerner" date="1297876342"]Take a look at the official "documentation":http://doc.qt.nokia.com/4.7/qprocess.html#details . Scroll down, there is an example included.
[/quote]I already tried that example but it seems to doesn't work for ssh.
[quote author="Frank" date="1297876571"]Both for improved security and improved convenience, I would use private/public key authentication.[/quote]
My application must works in a pc and in a BeagleBoard so I'd like to use a simple solution also if less secure.
-
I read in some forum that it's impossible to pass a password to ssh using QProcess because ssh require a console...
Can someone confirm me this?
-
ssh does not read from stdin. You can easily check that with
@
echo "password" | ssh somehost
@It asks for your password on the console. Stdin is just piped through to the remote shell or whatever program is run by ssh.
You might have a look at "libssh":http://www.libssh.org or "libssh2":http://www.libssh2.org
-
[quote author="Luca" date="1297878985"]
[quote author="unclewerner" date="1297876342"]Take a look at the official "documentation":http://doc.qt.nokia.com/4.7/qprocess.html#details . Scroll down, there is an example included.
[/quote]I already tried that example but it seems to doesn't work for ssh.
[quote author="Frank" date="1297876571"]Both for improved security and improved convenience, I would use private/public key authentication.[/quote]
My application must works in a pc and in a BeagleBoard so I'd like to use a simple solution also if less secure.
[/quote]Shipping a couple of public/private keys is VERY simple (it's just a matter of putting two files in the right place). You may also evaluate expect(1) or, if under unix with a X11 environment, create a simple SSH_ASKPASS program.
-
@Luca: I wonder what ssh would do, if you use forkpty(3) on your beagleboard.
-
Thanks all,
I finally installed openssh in the BeagleBoard replacing dropbear so now I can use ssh-keygen and a private/public key authentication while dropbear hasn't ssh-keygen. -
@luca can you tell me the way you solve this problem? i meet this kind of situtation,too.
I am exhausted. -
@_hunter Read Lucas last answer: he replaced dropbear with OpenSSH and used private/public keys.
-
-
@_hunter As I said I installed Openssh the used a public key authentication. This way it doesn't ask you for a password (if configured correctly).
Once you configure Openssh server in your remote device for a public key authentication (google is your friend for it) you can simply "ssh" from your client without password.
Hope it helps.