2

I have done some searching on connecting to servers and running commands on servers using SSH in Python.

Most, if not all, recommended using Paramiko. However the servers on which the script will be running are heavily secured and it is near-impossible to install custom python libraries.

Is there a way to connect through SSH using Python without using any libraries that aren't native to Python 2.7?

1
  • 1
    Always you can execute directly ssh command. It is almost on every machine Commented Sep 9, 2015 at 10:41

2 Answers 2

4

There's no native support for the SSH in Python.

All you can to is:

  • Implement the SSH/SFTP from a scratch by yourself. That's an insane task.

  • Run a command-line SFTP client (e.g. the OpenSSH sftp) from Python code.

  • Paramiko uses the LGPL license, so you might be able to take its source code and use it directly, without installing any module.

Sign up to request clarification or add additional context in comments.

Comments

3

Another option: https://stackoverflow.com/a/1233872/524743

If you want to avoid any extra modules, you can use the subprocess module to run.

ssh [host] [command]

and capture the output.

Try something like:

process = subprocess.Popen("ssh example.com ls", shell=True,
    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output,stderr = process.communicate()
status = process.poll()
print output

To deal with usernames and passwords, you can use subprocess to interact with the ssh process, or you could install a public key on the server to avoid the password prompt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.