@@ -69,7 +69,7 @@ class SSHClient(object):
6969
7070 def __init__ (self , host ,
7171 user = None , password = None , port = None ,
72- pkey = None ):
72+ pkey = None , forward_ssh_agent = True ):
7373 """Connect to host honouring any user set configuration in ~/.ssh/config \
7474 or /etc/ssh/ssh_config
7575
@@ -86,6 +86,10 @@ def __init__(self, host,
8686 :type port: int
8787 :param pkey: (Optional) Client's private key to be used to connect with
8888 :type pkey: :mod:`paramiko.PKey`
89+ :param forward_ssh_agent: (Optional) Turn on SSH agent forwarding - \
90+ equivalent to `ssh -A` from the `ssh` command line utility.
91+ Defaults to True if not set.
92+ :type forward_ssh_agent: bool
8993 :raises: :mod:`pssh.AuthenticationException` on authentication error
9094 :raises: :mod:`pssh.UnknownHostException` on DNS resolution error
9195 :raises: :mod:`pssh.ConnectionErrorException` on error connecting"""
@@ -108,6 +112,7 @@ def __init__(self, host,
108112 user = _user
109113 client = paramiko .SSHClient ()
110114 client .set_missing_host_key_policy (paramiko .MissingHostKeyPolicy ())
115+ self .forward_ssh_agent = forward_ssh_agent
111116 self .client = client
112117 self .channel = None
113118 self .user = user
@@ -162,6 +167,8 @@ def exec_command(self, command, sudo=False, **kwargs):
162167 stderr are buffers containing command output.
163168 """
164169 channel = self .client .get_transport ().open_session ()
170+ if self .forward_ssh_agent :
171+ agent_handler = paramiko .agent .AgentRequestHandler (channel )
165172 channel .get_pty ()
166173 # stdin (unused), stdout, stderr
167174 (_ , stdout , stderr ) = (channel .makefile ('wb' ), channel .makefile ('rb' ),
0 commit comments