Friday, June 14, 2024
HomeHow toEnable Login & Log Out Sound in Ubuntu 24.04

Enable Login & Log Out Sound in Ubuntu 24.04

This is a step by step guide shows you how to enable the event sounds (system sound or custom sound) for login and log out actions in Ubuntu 24.04 LTS.

When booting Ubuntu 24.04 from a live USB, it plays a sound after logged into the desktop. The sound however does no longer play after installed the system on your disk. So, here I’m going to show you how to re-enable this feature.

NOTE: This tutorial is tested and works in my case in Ubuntu 24.04. It MAY also work in old Ubuntu releases and even other Linux, but for GNOME Desktop only.

Step 1. The Command for playing the event sound:

NOTE: This step is ONLY required for those who want to play a custom sound, instead of system default.

Ubuntu, definitely GNOME, uses libcanberra for event sound playback. The default Login Sound is played by the command below:

/usr/bin/canberra-gtk-play --id="desktop-login" --description="GNOME Login"

While, the log out sound is handled by command:

/usr/bin/canberra-gtk-play --id="desktop-logoff" --description="GNOME Log Out"

Tips: press Ctrl+Alt+T to open terminal, paste and run the commands above to try the sounds playback. Though, you need to enable event sound first, by going to Settings -> Sound -> Sounds -> Alert Sound in 24..04.

To configure what sound to play, you just need to change the value of --id in the commands above.

For the default sound theme, just go to /usr/share/sounds/Yaru/stereo in file manager, then you’ll see all the available event sound ids (file-names without the .oga extension).

For example, play battery low sound via:

/usr/bin/canberra-gtk-play --id="battery-low" --description="whatever text as you want"

NOTE: If you switched sound theme to “Default”, then go /usr/share/sounds/freedesktop/stereo/ for sound IDs.

Event sound audio files

If you downloaded a sound file from web, or made an audio by yourself, then use the command below instead for playback:

/usr/bin/canberra-gtk-play --file="/home/ji/Music/sounds/123.wav" --description="whatever text as you want"

Replace /home/ji/Music/sounds/123.wav with PATH to your audio file. For short sound, add --loop=3 can play it for multiple times.

Step 2. Enable Login Sound

For the login sound, either add a startup application for running the command at login for current user, or configure the login sound .desktop that works for all users.

NOTE: /usr/bin/canberra-gtk-play does NOT work if event sound (Alert Sound) disabled! If you want to play login sound but NO event sound, use mpv or other audio player instead in 2 Options below:

And, here’s the command to play login sound using mpv media player (Run sudo apt install mpv to install it first):

mpv /usr/share/sounds/Yaru/stereo/desktop-login.oga

Option 1: Add a Startup Applications

First, press Super (Windows Logo) key on keyboard to trigger overview, then search for and launch “Startup Applications“.

When the tool opens, click “Add” button to add a new startup app at login. Then, insert:

  • Name: type whatever name as you want.
  • Command: /usr/bin/canberra-gtk-play --id="desktop-login" --description="GNOME Login"
  • Comment: whatever text, or leave blank.

You may replace the command according to last step for custom sound. But, it’s BETTER to run the command in terminal (Ctrl+Alt+T) first to ensure it works!

Option 2: Edit the GNOME Autostart Config file

The libcanberra library in Ubuntu has a config file for login sound event. The sound playback is however disabled out-of-the-box.

To enable this feature, simply open terminal (Ctrl+Alt+T) and run command to edit the config file:

sudo gnome-text-editor /usr/share/gnome/autostart/libcanberra-login-sound.desktop

For Ubuntu 22.04 and earlier, replace gnome-text-editor with gedit.

When file opens, just set “X-GNOME-Autostart-enabled=true“, and change the command for “Exec” line if you want to set a custom sound.

After saving the file, login sound should play for all users with event sound (Alert Sound) enabled!

3. Enable Log Out Sound

GNOME also has a config file for log out sound playback. It’s libcanberra-ready-sound.desktop file under “/usr/share/gdm/autostart/LoginWindow” directory, which however does NOT function out-of-the-box.

In my test, moving the file into /usr/share/gdm/greeter/autostart/ makes it work for log out and boot-up into login screen in Ubuntu 24.04.

Enable Log Out sound via the steps below will work even when event sound (Alert Sound) disabled in per user basis!

1. First, press Ctrl+Alt+T on keyboard to open up a terminal window. When terminal opens, run command to edit the file:

sudo gnome-text-editor /usr/share/gdm/autostart/LoginWindow/libcanberra-ready-sound.desktop

By default, it uses “system ready” sound, which is totally same to the login sound (desktop-login) in Ubuntu! So, I changed it to “desktop-logoff”. For choice, you can replace the command to custom sound playback.

2. After saved the file, run command to copy it into /usr/share/gdm/greeter/autostart/ directory:

sudo cp /usr/share/gdm/autostart/LoginWindow/libcanberra-ready-sound.desktop /usr/share/gdm/greeter/autostart/

If you changed your mind, just run command to delete that file, thus log out sound will be disabled:

sudo rm /usr/share/gdm/greeter/autostart/libcanberra-ready-sound.desktop

Play Shutdown Sound (Need Help)

There’s also a shutdown script, under /usr/share/gnome/shutdown directory, in Ubuntu 24.04. However, I don’t figure out how to enable it for playing a sound at shutdown.

For Arch Linux, libcanberra is built with following sevices:

  • canberra-system-shutdown.service
  • canberra-system-bootup.service
  • canberra-system-shutdown-reboot.service

Just enable the services should play sound in corresponding events. However, the library in Ubuntu is built without them.

I’ve also tried custom systemd service, but with no luck. If you know how to play a sound at shutdown in Ubuntu 24.04, please leave comment below.



Please enter your comment!
Please enter your name here

Most Popular