3

I have an issue when programming on Solaris 10 and hope to ask for help here. I have created a script to call-on "ssh" binary. This script runs some checks before running the "ssh" binary as a subprocess. The script assumes the power of "root" via SUID method.

After using this script for some time, some of the processes are left hanging like below.

root 23322 1 0 12:24:38 ? 0:00 scriptssh device321

I have logined to device321 and found no other users existing in the device.

After some read-up, I realize that the script has disconnected itself from the controlling terminal (look at the ? at "tty" and 1 at "PPID"). Is this a fallacy of subprocess in Python if I use the "communicate" method?

Anyone have a method to resolve this or identify why is this happening?

The script is written in Python.

EDIT:

Maybe it is easier to highlight the issue like this:

User A login to remote server -> SSH session is created

User A logout of remote server -> SSH session remains

SSH session eats up high CPU on current server.

Below is some snippets of the codes.

def main():
   ....
   ....
   try:
      if logic_user(username) == "privilege":
         if ip_check(src_ip,p_list):
            ssh_out(ssh_exe)
         else:
            print("You do not have access to SSH")
   except KeyboardInterrupt:
      print("Ctrl+c keyed in")
   finally:
      print("\nexiting ssh")

def ssh_out(ssh_exe):
   cmd = subprocess.Popen(ssh_exe, shell=True)
   cmd.communicate()
johnnyow
  • 49
  • 4
  • As the host closes an ssh session if nothing is sent for a while, I wonder if this is your problem. This can be prevented for terminal ssh connections by adding `ServerAliveInterval 240` into `~/.ssh/config`. I wonder if something similar would help or if you could add a periodic signal to your python script... – Ed Smith May 12 '15 at 13:05
  • Could you edit your question to include the relevant parts of this python script? Notably, how do you start these ssh processes, and what is supposed to make them exit? – Kenster May 12 '15 at 13:33

0 Answers0