0

I want to ssh to remote servers and execute a script which is already on the remote servers. Is it possible by python script using in-built modules? Unfortunately I can't use 3rd party modules due organization restrictions.

I believe its easier using SSH key based authentication but can't do that either. SSH login is by providing username and password.

Is there a way?

Thanks in advance!

  • With just the standard library? Without OpenSSH or similar to call? I wouldn't say it is impossible, but I guess you don't have time to re-implement the whole protocol. – Klaus D. Jul 28 '22 at 17:04
  • 3
    The whole point of downloadable modules is to provide necessary services that are not built-in to the language. The common modules are well-tested and not dangerous. In my opinion, you need to argue to management that you need this to do your job.' – Tim Roberts Jul 28 '22 at 17:04
  • How good a Python network programmer are you? What is your deadline to have this running? – Barmar Jul 28 '22 at 17:06
  • 1
    @TimRoberts is absolutely right here. Either your Team approves 3rd Party libraries or enable SSH Key based login. Using `python subprocess` you can execute commands/scripts on remote host. Also in terms of security, SSH key based authentication is much more safer than password based. It looks like there is no rationale to justify your team's ask. – Ameen Ali Shaikh Jul 28 '22 at 17:11

1 Answers1

0

Probably look into Python exec() and use sshpass for inline ssh login with username and password and the command you want to execute. Will require some experimentation on your end.

Ramit
  • 109
  • 1
  • 9