Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-02-2012, 01:23 PM   #1
LQ Newbie
Registered: Jun 2008
Distribution: Ubuntu, Debian, Mint, Fedora, Arch
Posts: 23

Rep: Reputation: 4
Python+paramiko - Can't create SSH connection when running as root


I'm trying to create a python script to automate backup of networking device configurations over SSH. Using paramiko I can create the connection when running as a normal user ( which I added to group "root" to facilitate storing the output files under /var/log ), but when run as root, it fails to authenticate. The target device is a Cisco switch. These are the relevant bits of code:

class Connection(object):
    def __init__(self,  target,  username,  password): = target
        self.username = username
        self.password = password
        self.ssh = paramiko.SSHClient()
        # I've tried all of the following, but same result
class Cisco_IOS(Connection):
    def fetch(self):
        self.ssh.connect(, username=self.username, password=self.password, )
        channel = self.ssh.invoke_shell()
        flush = channel.recv(3000)
        print flush
        catch_error = re.compile("[Ee]rror")
            log("Error authenticating to " + +". Enable password different from login password")
        channel.send("terminal length 0\n")
	channel.send("show run\n")
	config = channel.recv(20000)
        print config
	return config
Now I believe it's somehow related to the user's and root's "~/.ssh/known_hosts" files, but I'm not sure how. The public keys are in both files, and also the line
should take care of adding the keys if they were missing. Permissions on both files are the same (644).

The error I'm getting is:
File "./", line 35, in fetch
self.ssh.connect(, username=self.username, password=self.password, )
File "/usr/lib/python2.4/site-packages/paramiko/", line 327, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/usr/lib/python2.4/site-packages/paramiko/", line 481, in _auth
raise saved_exception
paramiko.AuthenticationException: Authentication failed.
As mentioned, I don't get this while running as a normal user, only as root. Any suggestions would be appreciated.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Paramiko and Python 2.6 ShaqDiesel Programming 1 03-03-2012 07:45 AM
How to create SSH user without access to root directory victorsk Linux - Networking 1 08-07-2009 06:56 PM
how can i create ssh connection bewteen my ipod touch and my pc deathalele Linux - Networking 1 01-05-2009 01:16 PM
Running a process decoupled from SSH connection? tim-f Linux - Newbie 4 07-10-2008 03:34 AM
running ssh connection into batch file jdonaldogg General 1 12-17-2005 10:25 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 AM.

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