Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSH_AGENT option to change ssh-agent per identity #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,20 @@ DESCRIPTION
# was found. Note that ssh-ident hard codes -t 7200 to prevent your
# keys from remaining in memory for too long.
SSH_ADD_DEFAULT_OPTIONS = "-t 7200"


# This is optional - don't include any SSH_AGENT if you don't
# need it.
# Otherwise, provides option to change the 'ssh-agent' command for
# specific identities.
SSH_AGENT = {
"work": "ssh-pageant",
}

# This is optional - don't include any SSH_AGENT if you don't
# need it.
# Otherwise, provides option to change the 'ssh-agent' command.
SSH_DEFAULT_AGENT = "ssh-agent"

# Output verbosity
# valid values are: LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
VERBOSITY = LOG_INFO
Expand Down
25 changes: 22 additions & 3 deletions ssh-ident
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ To have multiple identities, all I have to do is:
# keys from remaining in memory for too long.
SSH_ADD_DEFAULT_OPTIONS = "-t 7200"

# This is optional - don't include any SSH_AGENT if you don't
# need it.
# Otherwise, provides option to change the 'ssh-agent' command for
# specific identities.
SSH_AGENT = {
"work": "ssh-pageant",
}

# This is optional - don't include any SSH_AGENT if you don't
# need it.
# Otherwise, provides option to change the 'ssh-agent' command.
SSH_DEFAULT_AGENT = "ssh-agent"

# Output verbosity
# valid values are: LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
VERBOSITY = LOG_INFO
Expand Down Expand Up @@ -434,6 +447,9 @@ class Config(object):
"MATCH_PATH": [],
"MATCH_ARGV": [],

"SSH_AGENT": {},
"SSH_DEFAULT_AGENT": "ssh-agent",

# Dictionary with identity as a key, allows to specify
# per identity options when using ssh-add.
"SSH_ADD_OPTIONS": {},
Expand Down Expand Up @@ -682,7 +698,7 @@ class AgentManager(object):
self.config = config
self.ssh_config = sshconfig
self.agents_path = os.path.abspath(config.Get("DIR_AGENTS"))
self.agent_file = self.GetAgentFile(self.agents_path, self.identity)
self.agent_file = self.GetAgentFile(config, self.agents_path, self.identity)

def LoadUnloadedKeys(self, keys):
"""Loads all the keys specified that are not loaded.
Expand Down Expand Up @@ -766,7 +782,7 @@ class AgentManager(object):
return fingerprint

@staticmethod
def GetAgentFile(path, identity):
def GetAgentFile(config, path, identity):
"""Returns the path to an agent config file.

Args:
Expand All @@ -793,10 +809,13 @@ class AgentManager(object):
loglevel=LOG_DEBUG)
return agentfile

agent = config.Get("SSH_AGENT").get(
identity, config.Get("SSH_DEFAULT_AGENT")
)
print("Preparing new agent for identity {0}".format(identity), file=sys.stderr,
loglevel=LOG_DEBUG)
retval = subprocess.call(
["/usr/bin/env", "-i", "/bin/sh", "-c", "ssh-agent > {0}".format(agentfile)])
["/usr/bin/env", "-i", "/bin/sh", "-c", "{0} > {1}".format(agent, agentfile)])
return agentfile

@staticmethod
Expand Down