4

When using "lxc-create -t ubuntu" how does one specify the user of the new container? I don't want the default ubuntu:ubuntu but to specify my own unique username and password.

I'm using lxc 1.0.0~beta3 on ubuntu 14.04.

  • FYI, you can subscribe to the mailing list. I guess there you can get better/quicker answers. – edwin Feb 5 '14 at 15:26
1

User creation is done in the template file, so you must to change ubuntu template file, i.e: lxc-ubuntu. Templates are stored in /usr/local/share/lxc/templates or /usr/lib/lxc/templates/. Open it with your favorite editor and find the following lines (They are in configure_ubuntu() function of template file):

if [ -z "$bindhome" ]; then
    chroot $rootfs useradd --create-home -s /bin/bash ubuntu
    echo "ubuntu:ubutu" | chroot $rootfs chpasswd
fi

Replace ubuntu with your own username and password, i.e these line will be:

if [ -z "$bindhome" ]; then
    chroot $rootfs useradd --create-home -s /bin/bash USERNAME
    echo "USERNAME:PASSWORD" | chroot $rootfs chpasswd
fi

Then create your container as usual.

0

A simpeler option for one-time use would be to create the user yourself. Newer (at least the ubuntu I just tried) templates don't even come with the default ubuntu/ubuntu user anymore, see this message:

You just created an Ubuntu container (release=trusty, arch=amd64, variant=default)

To enable sshd, run: apt-get install openssh-server

For security reason, container images ship without user accounts and without a root password.

Use lxc-attach or chroot directly into the rootfs to set a root password or create user accounts.

Using lxc-attach is the quickest as far as I'm conserned, just do this:

you@hostbox:/$ lxc-attach -n yourlxc
root@yourlxc:/# adduser username
0

You can pass Comandline options to the Template/Script, that is installing and configuring the Ubuntu LXC Container /usr/share/lxc/templates/lxc-ubuntu

lxc-create -t ubuntu -n <CONTAINER_NAME> -- --user <USER_NAME> --password <USER_PASSWORD>

Other Options are:

./lxc-ubuntu -h|--help [-a|--arch] [-b|--bindhome <user>] [-d|--debug]
   [-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
   [--rootfs <rootfs>] [--packages <packages>] [-u|--user <user>] [--password <password>]
   [--mirror <url>] [--security-mirror <url>]
release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
bindhome: bind <user>'s home into the container
          The ubuntu user will not be created, and <user> will have
          sudo access.
arch: the container architecture (e.g. amd64): defaults to host arch
auth-key: SSH Public key file to inject into container
packages: list of packages to add comma separated
mirror,security-mirror: mirror for download and /etc/apt/sources.list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.