mirror of
https://github.com/containers/podman.git
synced 2025-05-21 17:16:22 +08:00
Add ssh connection to root user
When initing a VM, create two add connections - one to user, one to root. podman machine remove removes both connections as well. [NO TESTS NEEDED] Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -15,6 +15,8 @@ containers do not run on any other OS because containers' core functionality are
|
||||
tied to the Linux kernel.
|
||||
|
||||
**podman machine init** initializes a new Linux virtual machine where containers are run.
|
||||
SSH keys are automatically generated to access the VM, and system connections to the root account
|
||||
and a user account inside the VM are added.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
|
@ -55,10 +55,16 @@ func NewIgnitionFile(ign DynamicIgnition) error {
|
||||
}
|
||||
|
||||
ignPassword := Passwd{
|
||||
Users: []PasswdUser{{
|
||||
Users: []PasswdUser{
|
||||
{
|
||||
Name: ign.Name,
|
||||
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
|
||||
}},
|
||||
},
|
||||
{
|
||||
Name: "root",
|
||||
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ignStorage := Storage{
|
||||
|
@ -168,6 +168,11 @@ func (v *MachineVM) Init(opts machine.InitOptions) error {
|
||||
if err := machine.AddConnection(&uri, v.Name, filepath.Join(sshDir, v.Name), opts.IsDefault); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uriRoot := machine.SSHRemoteConnection.MakeSSHURL("localhost", "/run/podman/podman.sock", strconv.Itoa(v.Port), "root")
|
||||
if err := machine.AddConnection(&uriRoot, v.Name+"-root", filepath.Join(sshDir, v.Name), opts.IsDefault); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Println("An ignition path was provided. No SSH connection was added to Podman")
|
||||
}
|
||||
@ -357,6 +362,10 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun
|
||||
if err := machine.RemoveConnection(v.Name); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if err := machine.RemoveConnection(v.Name + "-root"); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
vmConfigDir, err := machine.GetConfDir(vmtype)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
|
Reference in New Issue
Block a user