LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-30-2014, 06:52 PM   #1
pix9
Member
 
Registered: Jan 2010
Location: Mumbai, India
Distribution: ArchLinux, Fedora 24, Centos 7.0
Posts: 177

Rep: Reputation: 19
python2.x : automating ssh with subporcess call


Hi Friends,
I am new to python, kind of migrating from bash to python. here is thing I am trying to do with my pythong script.

ssh system and get some info from that system. I want it all automated. here is where I am strucked
script is pormpting me for ssh password

given below is my script
OS : fedora20
sshd daemon is running.
Code:
#!/usr/bin/python
from subprocess import Popen, PIPE
from sys import argv
script, ip = argv
username="test"
passwd="password"
command = "ssh -l %r %r 'echo hello >> /tmp/test.txt'" % (username,ip)

proc = Popen([command], stdin=PIPE,stdout=PIPE,stderr=PIPE,shell=True)

#proc.communicate(passwd)
proc.communicate("password\n")
How I execute script
Code:
$python ./python_ssh.py 192.168.1.20
test@192.168.1.20's password:
when I run above script it prompts me for password. Kindly suggest me where I am doing wrong, if any good e-book or link for learning subprocess is also welcome.

regards
 
Old 10-30-2014, 07:58 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

I think your approach is less than ideal. You should not be treating passwords like that. Look into using RSA authentication. Also, using Popen or similar should be a last resort - use existing libraries. See for example https://wiki.python.org/moin/SecureShell

Evo2.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can I make Python2.7 my default Python without deleting/removing python2.6. steves504 Linux - Server 2 03-21-2014 11:57 AM
[SOLVED] Automating the SSH Login Process. pikohn Linux - Newbie 7 10-17-2011 08:42 PM
[SOLVED] Trying to install 'Gmail Backup' but it requires python2.5 - I have python2.8... Robert.Thompson Slackware 6 05-10-2011 08:23 AM
need help automating ssh-keygen linxq4u Linux - General 1 08-25-2007 11:13 AM
Python2.5-devel is unable to find installed Python2.5 Setya SUSE / openSUSE 1 06-08-2007 01:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration