Skip to content

Commit 49ea9c5

Browse files
author
Yoichi Kawasaki
committed
support --params to add additional ssh-config params
1 parent 718ef4a commit 49ea9c5

File tree

3 files changed

+100
-13
lines changed

3 files changed

+100
-13
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.0
2+
3+
* support bash completion: azuresshconfig_completion.bash
4+
* support --param to add additional ssh-config params
5+
16
## 0.1.1
27

38
* fixedup bug - [Issue #1](https://github.com/yokawasa/azure-ssh-config/issues/1)

README.md

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ Assuming all required packages are installed and rightly configured, you're read
4444
```
4545
azuresshconfig --help
4646
47-
usage: azuresshconfig [-h] [--version] [--init] [--profile PROFILE]
48-
[--user USER] [--identityfile IDENTITYFILE]
49-
[--private] [--resourcegroups RESOURCEGROUPS]
47+
usage: azuresshconfig.py [-h] [--version] [--init] [--profile PROFILE]
48+
[--user USER] [--identityfile IDENTITYFILE]
49+
[--private] [--resourcegroups RESOURCEGROUPS]
50+
[--params PARAMS]
5051
5152
This program generates SSH config from Azure ARM VM inventry in subscription
5253
5354
optional arguments:
5455
-h, --help show this help message and exit
5556
--version show program's version number and exit
56-
--init Create template client profile at $HOME/.azure/azure-
57-
ssh-config.json only if there is no existing one
58-
--profile PROFILE Specify azure client profile file to use ($HOME/.azure
59-
/azuresshconfig.json by default)
57+
--init Create template client profile at
58+
$HOME/.azure/azuresshconfig.json only if there is no
59+
existing one
60+
--profile PROFILE Specify azure client profile file to use
61+
($HOME/.azure/azuresshconfig.json by default)
6062
--user USER SSH username to use for all hosts
6163
--identityfile IDENTITYFILE
6264
SSH identity file to use for all hosts
@@ -66,6 +68,8 @@ optional arguments:
6668
A comma-separated list of resource group to be
6769
considered for ssh-config generation (all resource
6870
groups by default)
71+
--params PARAMS Any ssh-config params you want to add with query-
72+
string format: key1=value1&key2=value2&...
6973
```
7074

7175

@@ -106,12 +110,12 @@ cat ~/.ssh/config
106110
107111
Host myvm1
108112
HostName 40.74.124.30
109-
IdentityFile /home/yoichika/.ssh/id_rsa
113+
IdentityFile ~/.ssh/id_rsa
110114
User yoichika
111115
112116
Host myvm2
113117
HostName 40.74.116.134
114-
IdentityFile /home/yoichika/.ssh/id_rsa
118+
IdentityFile ~/.ssh/id_rsa
115119
User yoichika
116120
....
117121
@@ -127,9 +131,74 @@ azuresshconfig --user yoichika \
127131

128132
Only host entry that belong to specified resource group are added in ssh-config
129133

134+
### 4. Running with user, identity file, and additional ssh-config params
135+
```
136+
azuresshconfig.py --user yoichika \
137+
--identityfile ~/.ssh/id_rsa \
138+
--params "Port=2222&Protocol=2&UserKnownHostsFile=~/.ssh/known_hosts&ForwardAgent=yes"
139+
```
140+
141+
Additional ssh-config params specified by --params are added to an output ssh-config file like this:
142+
143+
```
144+
cat ~/.ssh/config
145+
146+
### AZURE-SSH-CONFIG BEGIN ###
147+
148+
Host myvm1
149+
HostName 40.74.124.30
150+
IdentityFile ~/.ssh/id_rsa
151+
User yoichika
152+
Port 2222
153+
Protocol 2
154+
UserKnownHostsFile ~/.ssh/known_hosts
155+
ForwardAgent yes
156+
157+
Host myvm2
158+
HostName 40.74.116.134
159+
IdentityFile /home/yoichika/.ssh/id_rsa
160+
User yoichika
161+
Port 2222
162+
Protocol 2
163+
UserKnownHostsFile ~/.ssh/known_hosts
164+
ForwardAgent yes
165+
....
166+
167+
### AZURE-SSH-CONFIG END ###
168+
```
169+
170+
## Shell Completion
171+
### Bash
172+
Bash completion will work by loading bash/[azuresshconfig_completion.bash](https://github.com/yokawasa/azure-ssh-config/blob/master/bash/azuresshconfig_completion.bash). In order to load azuresshconfig_completion.bash, you can do like this
173+
```
174+
# copy this under either of following directories
175+
cp azuresshconfig_completion.bash (/etc/bash_completion.d | /usr/local/etc/bash_completion.d | ~/bash_completion.d)
176+
177+
# or append 'source /path/to/azuresshconfig_completion.bash' to .bashrc like this
178+
echo 'source /path/to/azuresshconfig_completion.bash' >> .bashrc
179+
```
180+
181+
Once azuresshconfig_completion.bash is loaded, Bash completion will work this:
182+
```
183+
$ azuresshconfig -[tab]
184+
-h --identityfile --params --profile --user
185+
--help --init --private --resourcegroups
186+
187+
$ azuresshconfig --i[tab]
188+
--identityfile --init
189+
190+
$ azuresshconfig --p[tab]
191+
--params --private --profile
192+
193+
$ azuresshconfig --user [tab]
194+
$ azuresshconfig --user <ssh_user>
195+
$ azuresshconfig --user <ssh_user> --identityfile [tab]
196+
$ azuresshconfig --user <ssh_user> --identityfile <ssh_identity_file>
197+
```
198+
130199
## Todo
131200

132-
* Support bash/zsh Completion
201+
* Support zsh Completion (Hopefully support it soon)
133202

134203
## Issues
135204

azuresshconfig.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
pass
1919

2020
### Global Defines
21-
_AZURE_SSH_CONFIG_VERSION = '0.1.1'
21+
_AZURE_SSH_CONFIG_VERSION = '0.2.0'
2222
_AZURE_SSH_CONFIG_HOME_SITE = 'https://github.com/yokawasa/azure-ssh-config'
2323
_DEFAULT_AZURE_SSH_CONFIG_JSON_FILE = '{}/.azure/azuresshconfig.json'.format(os.environ['HOME'])
2424
_DEFAULT_SSH_CONFIG_FILE = '{}/.ssh/config'.format(os.environ['HOME'])
@@ -29,8 +29,8 @@
2929
class SSHConfigBlock:
3030
def __init__(self):
3131
self._entries = []
32-
self._ssh_config_param_defines = [
33-
'IdentityFile','User','Port','Protocol','ForwardAgent']
32+
# definitions below are collected from man ssh_config(5)
33+
self._ssh_config_param_defines = ['Host', 'AddressFamily', 'BatchMode', 'BindAddress', 'ChallengeResponseAuthentication', 'CheckHostIP', 'Cipher', 'Ciphers', 'ClearAllForwardings', 'Compression', 'CompressionLevel', 'ConnectionAttempts', 'ConnectTimeout', 'ControlMaster', 'ControlPath', 'ControlPersist', 'DynamicForward', 'EnableSSHKeysign', 'EscapeChar', 'ExitOnForwardFailure', 'ForwardAgent', 'ForwardX11', 'ForwardX11Timeout', 'ForwardX11Trusted', 'GatewayPorts', 'GlobalKnownHostsFile', 'GSSAPIAuthentication', 'GSSAPIDelegateCredentials', 'HashKnownHosts', 'HostbasedAuthentication', 'HostKeyAlgorithms', 'HostKeyAlias', 'HostName', 'IdentitiesOnly', 'IdentityFile', 'IgnoreUnknown', 'IPQoS', 'KbdInteractiveAuthentication', 'KbdInteractiveDevices', 'KexAlgorithms', 'LocalCommand', 'LocalForward', 'LogLevel', 'MACs', 'NoHostAuthenticationForLocalhost', 'NumberOfPasswordPrompts', 'PasswordAuthentication', 'PermitLocalCommand', 'PKCS11Provider', 'Port', 'PreferredAuthentications', 'Protocol', 'ProxyCommand', 'PubkeyAuthentication', 'RekeyLimit', 'RemoteForward', 'RequestTTY', 'RhostsRSAAuthentication', 'RSAAuthentication', 'SendEnv', 'ServerAliveCountMax', 'ServerAliveInterval', 'StrictHostKeyChecking', 'TCPKeepAlive', 'Tunnel', 'TunnelDevice', 'UsePrivilegedPort', 'User', 'UserKnownHostsFile', 'VerifyHostKeyDNS', 'VersionAddendum', 'VisualHostKey', 'XAuthLocation' ]
3434

3535
def add_entry(self,entry_name, access_address, params ):
3636
entry = {
@@ -246,6 +246,9 @@ def main():
246246
parser.add_argument(
247247
'--resourcegroups',
248248
help='A comma-separated list of resource group to be considered for ssh-config generation (all resource groups by default)')
249+
parser.add_argument(
250+
'--params',
251+
help='Any ssh-config params you want to add with query-string format: key1=value1&key2=value2&...')
249252
args = parser.parse_args()
250253

251254
if args.init:
@@ -281,6 +284,13 @@ def main():
281284
rslist= lower_rg.split(',')
282285
if len(rslist) > 0:
283286
filter_resource_groups = rslist
287+
additional_params = []
288+
if args.params:
289+
pairlist = args.params.split('&')
290+
for s in pairlist:
291+
p = s.split('=')
292+
if (len(p)==2):
293+
additional_params.append(p)
284294

285295
### Load Config
286296
cconf = ClientProfileConfig(client_profile_file)
@@ -326,6 +336,9 @@ def main():
326336
params['User'] = ssh_default_user
327337
if ssh_default_identityfile:
328338
params['IdentityFile'] = ssh_default_identityfile
339+
if len(additional_params) > 0:
340+
for pset in additional_params:
341+
params[pset[0]] = pset[1]
329342
scblock.add_entry(v['name'], v['access_ip'],params)
330343
ssh_config_block = scblock.to_string()
331344

0 commit comments

Comments
 (0)