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 7861829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:53:36+00:00 2026-06-02T22:53:36+00:00

I need to execute several shell commands using python, but I couldn’t resolve one

  • 0

I need to execute several shell commands using python, but I couldn’t resolve one of the problems. When I scp to another machine, usually it prompts and asks whether to add this machine to known host. I want the program to input “yes” automatically, but I couldn’t get it to work. My program so far looks like this:

from subprocess import Popen, PIPE, STDOUT

def auto():
  user = "abc"
  inst_dns = "example.com"    
  private_key = "sample.sem"
  capFile = "/home/ubuntu/*.cap"

  temp = "%s@%s:~" %(user, inst_dns)
  scp_cmd = ["scp", "-i", private_key, capFile, temp]

  print ( "The scp command is: %s" %" ".join(scp_cmd) )
  scpExec = Popen(scp_cmd, shell=False, stdin=PIPE, stdout=PIPE)
  # this is the place I tried to write "yes" 
  # but doesn't work
  scpExec.stdin.write("yes\n")
  scpExec.stdin.flush()
  while True:
    output = scpExec.stdout.readline()
    print ("output: %s" %output)
    if output == "": 
      break

If I run this program, it still prompt and ask for input. How can I response to the prompt automatically? Thanks.

  • 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-02T22:53:40+00:00Added an answer on June 2, 2026 at 10:53 pm

    You’re being prompted to add the host key to your know hosts file because ssh is configured for StrictHostKeyChecking. From the man page:

    StrictHostKeyChecking

    If this flag is set to “yes”, ssh(1) will never automatically add host keys to the ~/.ssh/known_hosts
    file, and refuses to connect to hosts whose host key has changed. This provides maximum protection
    against trojan horse attacks, though it can be annoying when the /etc/ssh/ssh_known_hosts file is
    poorly maintained or when connections to new hosts are frequently made. This option forces the user
    to manually add all new hosts. If this flag is set to “no”, ssh will automatically add new host keys
    to the user known hosts files. If this flag is set to “ask”, new host keys will be added to the user
    known host files only after the user has confirmed that is what they really want to do, and ssh will

    You can set StrictHostKeyChecking to “no” if you want ssh/scp to automatically accept new keys without prompting. On the command line:

    scp -o StrictHostKeyChecking=no ...
    

    You can also enable batch mode:

    BatchMode

    If set to “yes”, passphrase/password querying will be disabled. This option is useful in scripts and
    other batch jobs where no user is present to supply the password. The argument must be “yes” or
    “no”. The default is “no”.

    With BatchMode=yes, ssh/scp will fail instead of prompting (which is often an improvement for scripts).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to execute the given commands as root and sudo user using Java.
I want to execute a Python script on several (15+) remote machine using SSH.
I need to execute a query that is highly dependent on several conditions what
I am writing a shell where I need to launch several child processes at
I need to execute basic queries on a text file which consists of several
I have a SQL stored procedure that I need to execute several times with
I need to execute some common code for several 'around' advices. So, I have
I need to access data from a webpage using several different post requests. For
I have several sql files. I need to execute them in a transaction. When
In my app, I need to execute several ajax requests at the same time,

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.