For recent (post 2020) Chromebooks that use the vivaldi driver, use the keyboard remapping script from the cros-keyboard-map
repository by WeirdTreeThing.
git clone https://github.com/WeirdTreeThing/cros-keyboard-map
cd cros-keyboard-map
./install.sh
The rest of the answer is for chromebooks older than 2019.
Disclaimer: This answer is partly based on this Reddit post.
See this answer for GNOME.
For Ubuntu 22.04 and later versions
In Ubuntu MATE, open keyboard settings, open the "Layouts" tab, and choose "Chromebook".
In Kubuntu, open System Settings -> Input Devices -> Keyboard
, and choose Google | Chromebook
as the layout.

For Ubuntu 20.04 and previous versions, the workaround is to use GalliumOS keyboard layout.
First, download the .deb file for the keyboard layout.
wget https://apt.galliumos.org/pool/main/x/xkeyboard-config/xkb-data_2.23.1-1ubuntu1-galliumos1_all.deb
Now, install it.
sudo apt install ./xkb-data_2.23.1-1ubuntu1-galliumos1_all.deb
The latest version of xkb-data
already has a Chromebook layout, but it is not as good as the GalliumOS layout, because the key for lowering brightness does not work there.
Therefore, you have to pin this particular version, so that it would not be overwritten by an update.
sudo apt-mark hold xkb_data
Then, open keyboard settings, and open the "Layouts" tab.

Choose the layout titled "Chromebook (most models) | Right alt overlay | F keys mapped to media keys". Here, the alt key acts as the "overlay" key (similar to the Fn key in usual laptop keyboards).
Finally, reboot your computer.
For more details about the keyboard layout, checkout GalliumOS wiki.