Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:12:40+00:00 2026-06-13T13:12:40+00:00

I am writing a GUI program to spawn and monitor SSH tunnels for a

  • 0

I am writing a GUI program to spawn and monitor SSH tunnels for a group of users who are too intimidated to use a command-line.

Unfortunately, the servers in question are very strict. Two-factor authentication via RSA SecurID token is the only officially-endorsed way to open an SSH connection. Passwordless RSA public/private key authentication is not allowed.

Therefore, it is necessary for my program to read a password from a text entry box and send it to the child SSH process. Unfortunately, ssh goes to great lengths to ensure passwords come only from a real keyboard.

I strongly prefer not to use third-party modules. I am aware of paramiko and pexpect (which are both put forward as possible solutions to similar problems), but trying to explain to my users how to install Python modules from source is too much of a headache.

So: How can you send a password to an ssh subprocess using only the standard python subprocess module? Is there any way to fool the subprocess into thinking I’m using a TTY? Is it possible to use SSH_ASKPASS to read from my program?

Other standard-library modules (e.g., low-level commands with the os module) are also allowed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:12:41+00:00Added an answer on June 13, 2026 at 1:12 pm

    At length, I was able to use the pty module to control ssh through a pseudoterminal. I coded up a solution in pexpect, and then by looking at the pexpect source code and having some help from this StackOverflow answer I was able to figure out what to do. Here’s an excerpt of the relevant code (executed as part of an object’s method; hence the references to self).

    command = [
            '/usr/bin/ssh',
            '{0}@{1}'.format(username, hostname),
            '-L', '{0}:localhost:{1}'.format(local_port, foreign_port),
            '-o', 'NumberOfPasswordPrompts=1',
            'sleep {0}'.format(SLEEP_TIME),
    ]
    
    # PID = 0 for child, and the PID of the child for the parent    
    self.pid, child_fd = pty.fork()
    
    if not self.pid: # Child process
        # Replace child process with our SSH process
        os.execv(command[0], command)
    
    while True:
        output = os.read(child_fd, 1024).strip()
        lower = output.lower()
        # Write the password
        if lower.endswith('password:'):
            os.write(child_fd, self.password_var.get() + '\n')
            break
        elif 'are you sure you want to continue connecting' in lower:
            # Adding key to known_hosts
            os.write(child_fd, 'yes\n')
        elif 'company privacy warning' in lower:
            pass # This is an understood message
        else:
            tkMessageBox.showerror("SSH Connection Failed",
                "Encountered unrecognized message when spawning "
                "the SSH tunnel: '{0}'".format(output))
            self.disconnect()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a terminal wrapper for a command-line program in Java, and I spawn
I am trying to write a GUI program for a command line program in
I am writing a GUI which uses SSH commands. I tried to use the
I developed a command-line (non GUI) C program on Linux using QT Creator, which
I am writing a GUI program. In one part of it I show an
I've got a GUI C++ program that takes a shell command from the user,
I'm writing a Java program that's supposed to be the GUI frontend that utilizes
I'm writing a Python program with a GUI built with the Tkinter module. I'm
I am writing a gui program that allows a user to repeatedly send a
I'm writing an python program (gui in gtk) (linux btw.) I want to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.