views:

34

answers:

1

I'm working on a python script that stores ssh passwords only during the current session. What I'm doing is declaring a class variable credentials = {}. When the script needs access to a specific server, it checks in credentials to see if credentials['server'] exists. If it does, it uses the password there, if it doesn't, it prompts the user.

This is all working fine, but I'm just wondering if that's a bad way of implementing this? This isn't running anywhere critical that I need to be THAT concerned about security. I was just thinking it'd be nice if I could declare credentials as private.

Is this a reasonable approach? Is there a more pythonic way to do this or one that's better suited for how python deals with class member access?

+1  A: 

A bit of a digression, but when I've built scripts do this in the past, the security minded recommended using an ssh-agent approach. The agent is a background processes, independent of the python but running under the same user, that will store the credentials. Then the script doesn't need to worry about prompting or handling passwords at all.

Todd Gardner
Yeah, that's a good solution, and I'm sure there are lots of solutions that are extremely security conscious. However I'm trying to make this as portable as possible. Not across different OSes, but just across different linux distributions that I'd prefer not to have to install extra stuff.
Falmarri
ssh-agent is part of OpenSSH, so it is probably installed where ever you are using SSH. It can be more setup to get the keys in-place though.
Todd Gardner