@@ -54,7 +54,7 @@ def __init__(
54
54
self .timeout = int (timeout )
55
55
super ().__init__ (self .host .name , * args , ** kwargs )
56
56
57
- def _load_ssh_config (self , client , cfg , ssh_config ):
57
+ def _load_ssh_config (self , client , cfg , ssh_config , ssh_config_dir = "~/.ssh" ):
58
58
for key , value in ssh_config .lookup (self .host .name ).items ():
59
59
if key == "hostname" :
60
60
cfg [key ] = value
@@ -74,6 +74,14 @@ def _load_ssh_config(self, client, cfg, ssh_config):
74
74
cfg ["gss_kex" ] = value == "yes"
75
75
elif key == "proxycommand" :
76
76
cfg ["sock" ] = paramiko .ProxyCommand (value )
77
+ elif key == "include" :
78
+ new_config_path = os .path .join (
79
+ os .path .expanduser (ssh_config_dir ), value
80
+ )
81
+ with open (new_config_path ) as f :
82
+ new_ssh_config = paramiko .SSHConfig ()
83
+ new_ssh_config .parse (f )
84
+ self ._load_ssh_config (client , cfg , new_ssh_config , ssh_config_dir )
77
85
78
86
@cached_property
79
87
def client (self ):
@@ -87,21 +95,25 @@ def client(self):
87
95
"password" : self .host .password ,
88
96
}
89
97
if self .ssh_config :
98
+ ssh_config_dir = os .path .dirname (self .ssh_config )
99
+
90
100
with open (self .ssh_config ) as f :
91
101
ssh_config = paramiko .SSHConfig ()
92
102
ssh_config .parse (f )
93
- self ._load_ssh_config (client , cfg , ssh_config )
103
+ self ._load_ssh_config (client , cfg , ssh_config , ssh_config_dir )
94
104
else :
95
105
# fallback reading ~/.ssh/config
96
106
default_ssh_config = os .path .join (os .path .expanduser ("~" ), ".ssh" , "config" )
107
+ ssh_config_dir = os .path .dirname (default_ssh_config )
108
+
97
109
try :
98
110
with open (default_ssh_config ) as f :
99
111
ssh_config = paramiko .SSHConfig ()
100
112
ssh_config .parse (f )
101
113
except IOError :
102
114
pass
103
115
else :
104
- self ._load_ssh_config (client , cfg , ssh_config )
116
+ self ._load_ssh_config (client , cfg , ssh_config , ssh_config_dir )
105
117
106
118
if self .ssh_identity_file :
107
119
cfg ["key_filename" ] = self .ssh_identity_file
0 commit comments