diff --git a/pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh index 0b6e95789ac..ab942215a5d 100755 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh @@ -4,7 +4,7 @@ [ "$LIMA_CIDATA_VMTYPE" = "wsl2" ] || exit 0 # create user -sudo useradd -u "${LIMA_CIDATA_UID}" "${LIMA_CIDATA_USER}" -d "${LIMA_CIDATA_HOME}" +sudo useradd -u "${LIMA_CIDATA_UID}" "${LIMA_CIDATA_USER}" -c "${LIMA_CIDATA_GECOS}" -d "${LIMA_CIDATA_HOME}" sudo mkdir "${LIMA_CIDATA_HOME}"/.ssh/ sudo cp "${LIMA_CIDATA_MNT}"/ssh_authorized_keys "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys sudo chown "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys diff --git a/pkg/cidata/cidata.TEMPLATE.d/lima.env b/pkg/cidata/cidata.TEMPLATE.d/lima.env index 0b5737fdfc4..6666b245540 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/lima.env +++ b/pkg/cidata/cidata.TEMPLATE.d/lima.env @@ -2,6 +2,7 @@ LIMA_CIDATA_DEBUG={{ .Debug }} LIMA_CIDATA_NAME={{ .Name }} LIMA_CIDATA_USER={{ .User }} LIMA_CIDATA_UID={{ .UID }} +LIMA_CIDATA_GECOS={{ .GECOS }} LIMA_CIDATA_HOME={{ .Home}} LIMA_CIDATA_HOSTHOME_MOUNTPOINT={{ .HostHomeMountPoint }} LIMA_CIDATA_MOUNTS={{ len .Mounts }} diff --git a/pkg/cidata/cidata.TEMPLATE.d/user-data b/pkg/cidata/cidata.TEMPLATE.d/user-data index d98d03591d8..d8ea69e8f20 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/user-data +++ b/pkg/cidata/cidata.TEMPLATE.d/user-data @@ -30,6 +30,9 @@ timezone: {{.TimeZone}} users: - name: "{{.User}}" uid: "{{.UID}}" +{{- if .GECOS }} + gecos: {{ printf "%q" .GECOS }} +{{- end }} homedir: "{{.Home}}" shell: /bin/bash sudo: ALL=(ALL) NOPASSWD:ALL diff --git a/pkg/cidata/cidata.go b/pkg/cidata/cidata.go index 633581d5fc5..b0e60db8fde 100644 --- a/pkg/cidata/cidata.go +++ b/pkg/cidata/cidata.go @@ -132,6 +132,7 @@ func templateArgs(bootScripts bool, instDir, name string, instConfig *limayaml.L Hostname: identifierutil.HostnameFromInstName(name), // TODO: support customization User: u.Username, UID: uid, + GECOS: u.Name, Home: fmt.Sprintf("/home/%s.linux", u.Username), GuestInstallPrefix: *instConfig.GuestInstallPrefix, UpgradePackages: *instConfig.UpgradePackages, diff --git a/pkg/cidata/template.go b/pkg/cidata/template.go index ff83386da23..a927f839509 100644 --- a/pkg/cidata/template.go +++ b/pkg/cidata/template.go @@ -59,6 +59,7 @@ type TemplateArgs struct { Hostname string // instance hostname IID string // instance id User string // user name + GECOS string // user information Home string // home directory UID int SSHPubKeys []string diff --git a/pkg/cidata/template_test.go b/pkg/cidata/template_test.go index 35c3623e991..dbe848ac06d 100644 --- a/pkg/cidata/template_test.go +++ b/pkg/cidata/template_test.go @@ -12,10 +12,11 @@ var defaultRemoveDefaults = false func TestConfig(t *testing.T) { args := &TemplateArgs{ - Name: "default", - User: "foo", - UID: 501, - Home: "/home/foo.linux", + Name: "default", + User: "foo", + UID: 501, + GECOS: "Foo", + Home: "/home/foo.linux", SSHPubKeys: []string{ "ssh-rsa dummy foo@example.com", }, @@ -29,10 +30,11 @@ func TestConfig(t *testing.T) { func TestConfigCACerts(t *testing.T) { args := &TemplateArgs{ - Name: "default", - User: "foo", - UID: 501, - Home: "/home/foo.linux", + Name: "default", + User: "foo", + UID: 501, + GECOS: "Foo", + Home: "/home/foo.linux", SSHPubKeys: []string{ "ssh-rsa dummy foo@example.com", }, diff --git a/pkg/osutil/user.go b/pkg/osutil/user.go index 7896d5e43e2..45b2b7e1ab4 100644 --- a/pkg/osutil/user.go +++ b/pkg/osutil/user.go @@ -19,6 +19,7 @@ type User struct { Uid uint32 Group string Gid uint32 + Name string // or Comment Home string } @@ -65,7 +66,7 @@ func LookupUser(name string) (User, error) { if err != nil { return User{}, err } - users[name] = User{User: u.Username, Uid: uid, Group: g.Name, Gid: gid, Home: u.HomeDir} + users[name] = User{User: u.Username, Uid: uid, Group: g.Name, Gid: gid, Name: u.Name, Home: u.HomeDir} } return users[name], nil } diff --git a/website/content/en/docs/dev/internals/_index.md b/website/content/en/docs/dev/internals/_index.md index c0c2456ea63..0d8d6ebb021 100644 --- a/website/content/en/docs/dev/internals/_index.md +++ b/website/content/en/docs/dev/internals/_index.md @@ -179,6 +179,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://docs.cl - `LIMA_CIDATA_MNT`: the mount point of the disk. `/mnt/lima-cidata`. - `LIMA_CIDATA_USER`: the username string - `LIMA_CIDATA_UID`: the numeric UID +- `LIMA_CIDATA_GECOS`: the name or comment string - `LIMA_CIDATA_HOME`: the guest home directory - `LIMA_CIDATA_HOSTHOME_MOUNTPOINT`: the mount point of the host home directory, or empty if not mounted - `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts