SSH Connection with Remote Linux devices
-
I doubt the password can be passed on the command line. Take a look on how to pass a password to ssh but for sure it's not as a simple argument.
-
@Vijaykarthikeyan said in SSH Connection with Remote Linux devices:
like this?
Did you see https://doc.qt.io/qt-6/qprocess.html#errorOccurred ?
-
@Christian-Ehrlicher yes..i thought that too.when i gone through examples,they have said sshpass for automating the authentication.But,I need to know that is that only problem..I dont know how the QProcess take the arguments..Im doubtful about the argument list. Although classes like TCP socket and sslsocket used to networking,but i dont know whether they could access passwords too.In Qt kits..There is an option for ssh feature but don't know that very well
-
@Vijaykarthikeyan said in SSH Connection with Remote Linux devices:
I dont know how the QProcess take the arguments..I
I don't see what this has to do with the password problem - you provide wrong arguments to ssh, ssh bails out with
Unknown error
- everything else would be surprising. Also ssh for sure does not simply take an argumentcd Desktop && ./ROV.sh
which is executed after the login.
You first have to inform you about the correct ssh parameters for your task. No Qt problem here. -
@Christian-Ehrlicher Yes of course..that's what i have said that i have doubtful about the arguments..i dont know how to give the arguments likewise in command line. There is no Qt documentation for this.
-
@Christian-Ehrlicher So even before im trying to read the file in the remote directory,i want to ensure that whether it is connected or not by just giving hostname and username but im receiving this:
SSH Error: "ssh: connect to host port 22: Connection refused\r\n"
-
@Vijaykarthikeyan You should not use passwords but identity files, then there is no need to provide password.
"ssh: connect to host port 22: Connection refused" - this means that there is no SSH server listening on port 22 on that machine, again nothing Qt specific.
-
@jsulm are the key files to be located on both client and server sides? or from development side?in Qt tools,there is an option for ssh connection
can i refer this.
https://doc.qt.io/qtcreator/creator-developing-generic-linux.html(or)
can we use sshpass which is helpful for scripting? -
@Vijaykarthikeyan said in SSH Connection with Remote Linux devices:
can i refer this.
What you're doing is not related to QtCreator.
Not QtCreator is accessing the device via SSH but your application using QProcess and ssh executable. You need to generate a key file and upload it to your device, see for example https://askubuntu.com/questions/46930/how-can-i-set-up-password-less-ssh-login -
@jsulm Now,I have the key and i tested in command terminal and it works well. Now,i don't know the command line arguments for linux to be used in QProcess. when goes through the documentation,it says the start function takes command line arguments but not mentioned the correct format. Can someone guide me how to use the command line arguments for linux to be run correctly in QProcess.It should open the file in desktop directory after connecting with the linux host
-
@Vijaykarthikeyan said in SSH Connection with Remote Linux devices:
not mentioned the correct format
What does this mean? You don't need to re-format the arguments in any way. Just pass them to QProcess::setArguments(). The detailed description also has an example on how to pass arguments.
-
@Christian-Ehrlicher ok..when i included this after starting the process:
qDebug() << sshProcess->state(); qDebug() << "SSH Output:" << sshProcess->readAllStandardOutput(); qDebug() << "SSH Error Output:" << sshProcess->readAllStandardError();
it gives like this:
QProcess::Running
SSH Output: ""
SSH Error Output: ""why?it is not printing..readAllStandardOutput and readAllStandardError are QBytArrays..
Can I consider this as my program executed correctly?
Because on terminal, when successfully connected and executing the shell scirpt..it runs like this:
python: no process found
No Arduino
connection reset
No Arduino
connection reset
No ArduinoIn my Qt,it should print like this
-
@Vijaykarthikeyan Now,it ic successfully connected,
SSH Output: "Linux pi 6.1.21+ #1642 Mon Apr 3 17:19:14 BST 2023 armv6l\n\nThe programs included with the Debian GNU/Linux system are free software;\nthe exact distribution terms for each program are described in the\nindividual files in /usr/share/doc/*/copyright.\n\nDebian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\npermitted by applicable law.\n\nWi-Fi is currently blocked by rfkill.\nUse raspi-config to set the country before use.\n\n"
But,when i give the command to navigate to the file directory it says too many arguments
-
@Vijaykarthikeyan said in SSH Connection with Remote Linux devices:
why?it is not printing..readAllStandardOutput and readAllStandardError
As I presume you have discovered, you will not receive any output from a subprocess if you ask for it immediately after starting it --- no output has yet been produced. You either need to
connect()
toreadyRead.,.,.()
, callwaitForReadyRead()
(yuck!) or wait until process finished.But,when i give the command to navigate to the file directory it says too many arguments
For people to help you, don't you think we need to see what "command" you are issuing, how you are issuing it, and just what the error message reads? Or do you think we can tell you what is wrong with your "command to navigate to the file directory" without knowing what you have done?
-
@JonB Please go through my code snippet which i have been already included what is the command line which im trying to pass. And I seek what is the mistake which I have been done.Ok...Do you think the people who are asking doubt are just not knowing anything at all? All these people in this conversation..gone through the snippet and corrects me in each comment
-
But,when i give the command to navigate to the file directory it says too many arguments
Evidently the other people understand what you are passing to
QProcess
, how you are specifying arguments, etc.. I don't. So you can wait for them. -
@Vijaykarthikeyan
But firstly you say you have "changed" what you are issuing at some point, and secondly your screenshot shows you issuing a command of.ROV.sh
which gives messagepython: no process found
. This hardly seems an ideal place to start from, to me.Then The only
QProcess
(assuming that is whatsshProcess
is) statement you show executes the following:ssh -T ssh "username@host" "password" "cd Desktop && ./ROV.sh"
I am not an
ssh
expert. But is it really right that you want to executessh ... ssh ...
??Then you say there is no documentation for how to pass arguments to
ssh
, which is not its job to document. Or their "format", which is not its job either.Then you seem to say you have "changed" what you do, but I don't know how, and then that it's "working".
Then you say
But,when i give the command to navigate to the file directory it says too many arguments
But rather then telling us what exactly you pass to
QProcess
you say we should look at screenshots and it is our fault for failing to understand.Then you tell me that other people can answer your questions but not me, so I suggest you wait for them to understand what I do not.
Here is what I would have expected/hoped for from you, and from myself if I were asking the question:
- I have tried a single-line
ssh
from a terminal outside of Qt. Here is the verbatim of what I typed:
ssh ...
- And here is how I tried to call that with
QProcess
:
sshArgs << ... sshProcess->start("ssh", sshArgs);
and here is the output or error message or behaviour or whatever is wrong.
And it it were me I would expect to start with a command no more than, like,
echo hello
, verify that works first, then move ontocd
ing and running a.sh
.If I am not able to give the help you want, that's fine, and if you find others understand better and you'd rather await their responses, that's fine too. But please don't belabour me for failing to know just what you are doing from your screenshots when it would take you a few seconds to provide answers to points 1. & 2. per my request instead of saying I should be able to answer without further clarification.
- I have tried a single-line