@@ -227,18 +227,30 @@ func (d *Driver) prepareSSH() error {
227227 }
228228
229229 cmder := command .NewKICRunner (d .NodeConfig .MachineName , d .NodeConfig .OCIBinary )
230- f , err := assets .NewFileAsset (d .GetSSHKeyPath ()+ ".pub" , "/home/docker/.ssh/" , "authorized_keys" , "0644" )
230+ f1 , err := assets .NewFileAsset (d .GetSSHKeyPath ()+ ".pub" , "/home/docker/.ssh/" , "authorized_keys" , "0644" )
231231 if err != nil {
232232 return fmt .Errorf ("create pubkey assetfile : %w" , err )
233233 }
234+
235+ f2 , err := assets .NewFileAsset (d .GetSSHKeyPath ()+ ".pub" , "/root/.ssh/" , "authorized_keys" , "0644" )
236+ if err != nil {
237+ return fmt .Errorf ("create pubkey assetfile : %w" , err )
238+ }
239+
234240 defer func () {
235- if err := f .Close (); err != nil {
236- klog .Warningf ("error closing the file %s: %v" , f .GetSourcePath (), err )
241+ if err := f1 .Close (); err != nil {
242+ klog .Warningf ("error closing the file %s: %v" , f1 .GetSourcePath (), err )
243+ }
244+ if err := f2 .Close (); err != nil {
245+ klog .Warningf ("error closing the file %s: %v" , f2 .GetSourcePath (), err )
237246 }
238247 }()
239248
240- if err := cmder .Copy (f ); err != nil {
241- return fmt .Errorf ("copying pub key: %w" , err )
249+ if err := cmder .Copy (f1 ); err != nil {
250+ return fmt .Errorf ("copying pub key in /home/docker/.ssh/: %w" , err )
251+ }
252+ if err := cmder .Copy (f2 ); err != nil {
253+ return fmt .Errorf ("copying pub key in /root/.ssh/: %w" , err )
242254 }
243255
244256 // Double-check that the container has not crashed so that we may give a better error message
@@ -256,6 +268,10 @@ func (d *Driver) prepareSSH() error {
256268 return fmt .Errorf ("apply authorized_keys file ownership, output %s: %w" , rr .Output (), err )
257269 }
258270
271+ if rr , err := cmder .RunCmd (exec .Command ("chown" , "root:root" , "/root/.ssh/authorized_keys" )); err != nil {
272+ return fmt .Errorf ("apply authorized_keys file ownership, output %s: %w" , rr .Output (), err )
273+ }
274+
259275 if runtime .GOOS == "windows" {
260276 path , _ := exec .LookPath ("powershell" )
261277 ctx , cancel := context .WithTimeout (context .Background (), 8 * time .Second )
0 commit comments