@@ -210,6 +210,12 @@ def _inject_run(self):
210210 )
211211 self .console .expect (self .prompt )
212212
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+
213219 @step (args = ['keyfile_path' ])
214220 def _put_ssh_key (self , keyfile_path ):
215221 """Upload an SSH Key to a target"""
@@ -251,7 +257,7 @@ def _put_ssh_key(self, keyfile_path):
251257
252258 if test_write == 0 and read_keys == 0 :
253259 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" )
255261 self ._run_check ("rm ~/.test" )
256262 return
257263
@@ -263,14 +269,15 @@ def _put_ssh_key(self, keyfile_path):
263269 self ._run ("mkdir ~/.ssh/" )
264270 self ._run_check ("chmod 700 ~/.ssh/" )
265271 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" )
267274 self ._run_check ("rm ~/.test" )
268275 return
269276
270277 self .logger .debug ("Key not on target and not writeable, using bind mount..." )
271278 self ._run_check ('mkdir -m 700 /tmp/labgrid-ssh/' )
272279 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" )
274281 self ._run_check ('chmod 600 /tmp/labgrid-ssh/authorized_keys' )
275282 out , err , exitcode = self ._run ('mount --bind /tmp/labgrid-ssh/ ~/.ssh/' )
276283 if exitcode != 0 :
0 commit comments