mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: generate ssh host keys for linux guest (#15303)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -56,6 +56,8 @@ type IDiskPartition interface {
|
||||
IsReadonly() bool
|
||||
GetPhysicalPartitionType() string
|
||||
Zerofree()
|
||||
|
||||
GenerateSshHostKeys() error
|
||||
}
|
||||
|
||||
type IRootFsDriver interface {
|
||||
|
||||
@@ -337,6 +337,14 @@ func (l *sLinuxRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*ty
|
||||
return errors.Wrapf(err, "write %s fail", dockerDaemonConfPath)
|
||||
}
|
||||
}
|
||||
// deploy ssh host key
|
||||
{
|
||||
err := rootFs.GenerateSshHostKeys()
|
||||
if err != nil {
|
||||
// ignore error
|
||||
log.Errorf("rootFs.GenerateSshHostKeys fail %s", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -310,3 +310,13 @@ func (f *SLocalGuestFS) FilePutContents(sPath, content string, modAppend, caseIn
|
||||
return fmt.Errorf("Cann't put content")
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SLocalGuestFS) GenerateSshHostKeys() error {
|
||||
cmd := []string{"chroot", f.mountPath, "ssh-keygen", "-A"}
|
||||
output, err := procutils.NewCommand(cmd[0], cmd[1:]...).Output()
|
||||
if err != nil {
|
||||
log.Errorf("ssh-keygen host keys fail: %s, %s", err, output)
|
||||
return fmt.Errorf("%s", output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -610,3 +610,9 @@ func MountSSHRootfs(tool *disktool.SSHPartitionTool, term *ssh.Client, layouts [
|
||||
}
|
||||
return nil, nil, fmt.Errorf("Fail to find rootfs")
|
||||
}
|
||||
|
||||
func (p *SSHPartition) GenerateSshHostKeys() error {
|
||||
cmd := fmt.Sprintf("/usr/sbin/chroot %s /usr/bin/ssh-keygen -A", p.mountPath)
|
||||
_, err := p.term.Run(cmd)
|
||||
return errors.Wrap(err, "GenerateSshHostKeys")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user