How do I start an SSH session locally using Python? -


what mean ask is, if on system "a" (linux) , want ssh system "b" (windows): on system "a", can ssh admin@xx.xx.xx.xx prompt me password , when gets authenticated, "$" of system "b" (on system "a").

  1. how send username , password single line (since want use script)
  2. how achieve scenario have above.

i paramiko, easier

import paramiko  # ssh  print 'enter ssh' ssh = paramiko.sshclient() ssh.set_missing_host_key_policy(paramiko.autoaddpolicy()) # automatically add keys ssh.connect(machinehostname, username=user, password=password)  # run commands # example 1 : ls command print 'do ls command' stdin, stdout, stderr = ssh.exec_command('ls') print stdout.readlines() time.sleep(2) # example 2 : change ip address print 'changing ip address' stdin, stdout, stderr = ssh.exec_command('sed -i -- s/'+oldip+'/'+newip+'/g /etc/sysconfig/network-scripts/ifcfg-eth0') print stdout.readlines() time.sleep(2) 

to install paramiko, can download tar.gz file here.

assuming new python, how install :

  • download tar.gz file
  • extract contents folder
  • cd extracted folder, terminal
  • execute python setup.py install
  • then can try above example

note : if stuck installation comment here, , can you.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -