Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess && ssh && write password
Qt 6.11 is out! See what's new in the release blog

QProcess && ssh && write password

Scheduled Pinned Locked Moved General and Desktop
15 Posts 8 Posters 17.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • frankcyblogic.deF Offline
      frankcyblogic.deF Offline
      frankcyblogic.de
      wrote on last edited by
      #2

      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().

      1 Reply Last reply
      2
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        I've never used QProcess this way. I only used it to star an application that didn't require input.

        Is there an example?

        1 Reply Last reply
        0
        • frankcyblogic.deF Offline
          frankcyblogic.deF Offline
          frankcyblogic.de
          wrote on last edited by
          #4

          Take a look at the official "documentation":http://doc.qt.nokia.com/4.7/qprocess.html#details . Scroll down, there is an example included.

          1 Reply Last reply
          1
          • F Offline
            F Offline
            Frank
            wrote on last edited by
            #5

            Both for improved security and improved convenience, I would use private/public key authentication.

            1 Reply Last reply
            1
            • L Offline
              L Offline
              luca
              wrote on last edited by
              #6

              [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.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                luca
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  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

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  1
                  • D Offline
                    D Offline
                    dangelog
                    wrote on last edited by
                    #9

                    [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.

                    Software Engineer
                    KDAB (UK) Ltd., a KDAB Group company

                    1 Reply Last reply
                    1
                    • frankcyblogic.deF Offline
                      frankcyblogic.deF Offline
                      frankcyblogic.de
                      wrote on last edited by
                      #10

                      @Luca: I wonder what ssh would do, if you use forkpty(3) on your beagleboard.

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        luca
                        wrote on last edited by
                        #11

                        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.

                        _ 1 Reply Last reply
                        1
                        • L luca

                          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.

                          _ Offline
                          _ Offline
                          _hunter
                          wrote on last edited by
                          #12

                          @luca can you tell me the way you solve this problem? i meet this kind of situtation,too.
                          I am exhausted.

                          aha_1980A L 2 Replies Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @_hunter Read Lucas last answer: he replaced dropbear with OpenSSH and used private/public keys.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            3
                            • _ _hunter

                              @luca can you tell me the way you solve this problem? i meet this kind of situtation,too.
                              I am exhausted.

                              aha_1980A Offline
                              aha_1980A Offline
                              aha_1980
                              Lifetime Qt Champion
                              wrote on last edited by aha_1980
                              #14

                              hi @_hunter

                              as @SGaist said, public keys are the way to go.

                              if you cannot use them for a reason, google for sshpass. i use it successfully to connect to embedded boards from customers where i cannot upload my own keys.

                              Qt has to stay free or it will die.

                              1 Reply Last reply
                              2
                              • _ _hunter

                                @luca can you tell me the way you solve this problem? i meet this kind of situtation,too.
                                I am exhausted.

                                L Offline
                                L Offline
                                luca
                                wrote on last edited by
                                #15

                                @_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.

                                1 Reply Last reply
                                2

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved