@@ -210,6 +210,12 @@ def _inject_run(self):
210
210
)
211
211
self .console .expect (self .prompt )
212
212
213
+ def _write_key (self , keyline , dest ):
214
+ for i in range (0 , len (keyline ), 100 ):
215
+ part = keyline [i :i + 100 ]
216
+ self ._run_check (f'echo -n "{ part } " >> { dest } ' )
217
+ self ._run_check (f'echo "" >> { dest } ' )
218
+
213
219
@step (args = ['keyfile_path' ])
214
220
def _put_ssh_key (self , keyfile_path ):
215
221
"""Upload an SSH Key to a target"""
@@ -251,7 +257,7 @@ def _put_ssh_key(self, keyfile_path):
251
257
252
258
if test_write == 0 and read_keys == 0 :
253
259
self .logger .debug ("Key not on target and writeable, concatenating..." )
254
- self ._run_check ( f'echo " { keyline } " >> ~/.ssh/authorized_keys' )
260
+ self ._write_key ( keyline , " ~/.ssh/authorized_keys" )
255
261
self ._run_check ("rm ~/.test" )
256
262
return
257
263
@@ -263,14 +269,15 @@ def _put_ssh_key(self, keyfile_path):
263
269
self ._run ("mkdir ~/.ssh/" )
264
270
self ._run_check ("chmod 700 ~/.ssh/" )
265
271
self .logger .debug ("Creating ~/.ssh/authorized_keys" )
266
- self ._run_check (f'echo "{ keyline } " > ~/.ssh/authorized_keys' )
272
+ self ._run_check ("touch ~/.ssh/authorized_keys" )
273
+ self ._write_key (keyline , "~/.ssh/authorized_keys" )
267
274
self ._run_check ("rm ~/.test" )
268
275
return
269
276
270
277
self .logger .debug ("Key not on target and not writeable, using bind mount..." )
271
278
self ._run_check ('mkdir -m 700 /tmp/labgrid-ssh/' )
272
279
self ._run ("cp -a ~/.ssh/* /tmp/labgrid-ssh/" )
273
- self ._run_check ( f'echo " { keyline } " >> /tmp/labgrid-ssh/authorized_keys' )
280
+ self ._write_key ( keyline , " /tmp/labgrid-ssh/authorized_keys" )
274
281
self ._run_check ('chmod 600 /tmp/labgrid-ssh/authorized_keys' )
275
282
out , err , exitcode = self ._run ('mount --bind /tmp/labgrid-ssh/ ~/.ssh/' )
276
283
if exitcode != 0 :
0 commit comments