A_Porcupine - A Blog about technology and other such geekery!

👥 Change Default Linux User in ChromeOS

February 02, 2020

Crostini (Google’s project to bring Linux containers to Chromebooks), sets your Linux username to the first half of your email address, in my case, this isn’t my preferred Linux username.

An experimental flag (chrome://flags#crostini-username) will be added to Chrome 81 and will allow you to specify the username of the default user during setup, but until then, if you want to set the default user of a new or existing container, follow these steps:

NOTE: for the purpose of this guide the following usernames will be used:

old username:  olduser
new username:  newuser

  1. Ensure you have already set up and opened the terminal application, you should be presented with the following:

  1. Open a new Chrome window and press Ctrl-Alt-T to access The Chromium OS shell (also known as crosh).

  1. Enter the following commands to access the virtual machine that hosts your Linux container (called termina), then run bash on the container (called penguin) as root:
vsh termina
lxc exec penguin bash

  1. We’ll be making some modifications to the old user, so let’s start off by killing all processes owned by olduser:
killall --user olduser

  1. We need our new user to have uid 1000, so we’ll need to move the old user out of the way. In this step the first two commands change olduser’s user and group IDs to 1002, and the second two update the ownership of all files owned by the olduser.
usermod -u 1002 olduser
groupmod -g 1002 olduser

find / -group 1000 -exec chgrp -h olduser {} \;
find / -user 1000 -exec chown -h olduser {} \;

  1. Now that we’ve moved the old user out of the way, it’s time to create the new user, follow the prompts to create newuser with the uid 1000.
adduser --uid 1000 newuser

  1. We’re almost there now, but first let’s disable linger for olduser and enable persistance for newuser:
loginctl enable-linger newuser
loginctl disable-linger olduser

  1. Log out and log back in, open the terminal app, and we’re done!

NOTE: Previously you could just create a new ‘penguin’ container and specify the user by running run_container.sh, however this is now deprecated and has stopped working when provided with the user option in recent versions.

run_container.sh has been replaced by the vmc container command in crosh, however this currently doesn’t take a user argument. Star Chromium issue 1047478 if you want to see this added.

Tom Hanson

Hey, I'm Tom Hanson! I'm a Software Engineer currently building people tools at a UK based fintech! Follow me on Twitter!