Multi-user setup is finally figured
Having multiple users for different purposes really helps you separate concerns and allows for better focus. One thing that makes Linux systems shine here is that you can run multiple X sessions (e.g desktops) at the same time, and switch between them seamlessly. Today I’ve figured the latest piece of this setup which was the Pipewire audio.
Why bother with multiple users
If you are the only person accessing your device, you might think that creating more users is a crazy idea. But that’s not true - there are a lot of use-cases for this.
Here’s mine: I work as a software engineer and on my spare time I work on side projects. And guess what - it really helps to keep these things separate! The obvious benefit of this is having different config files. Overall my job “identity” is kept entirely separate from my personal one - GPG & SSH keys, .gitconfig
, .npmrc
, Downloads directory, browser profile (it can be done within one user though) and even the wallpaper!
Apart from this, both users don’t have access to each others’ files - because they don’t need to! This has a nice side-effect - if anyone gains access to my machine, let’s say I run some untrusted code as eug-vs
and get hacked - another user will stay safe 🔒 (unless there’s privilege escalation which anyway means you are screwed).
And last but not least - you get less distraction! If you are trying to focus on your work, there are a lot of things that can quickly grab your attention - personal notifications, emails, and that funny project you were working on last week. And as you might have guessed - this problem completely vanishes when using separate user - enabling the “full focus” mode.
Multiple X sessions
What I’ve mentioned so far is a basic feature of any modern operating system. But Linux takes it a step further, allowing you to run multiple X sessions (e.g desktops) at the same time. Usually you log in right in the TTY 1
, but then at any moment you can switch to say TTY 2
(CTRL + ALT + F2
) and do your stuff as another user, including running another X session. You can have up to 10 of those (bound to your F
keys). This is a really underrated feature. You may take it even further and run different desktop environments or window managers - with their own per-user customizations.
Keeping some configs in sync
I hope you already keep your .dotfiles
in git
, and if you are not, what are you waiting for?! I also suggest using stow
(app-admin/stow
) for managing your dotfiles. This way you can update dotfiles from personal profile, push
it to the remote and then pull
as another user.
Displaying current user in dwm status bar
This is deadly simple with whoami
command, here’s my block from dwmblocks
:
{" ", "whoami", 0, 0},
Mixing audio from multiple users 🔉
I run Gentoo with openrc
, and according to wiki Pipewire is recommended to be started manually in your .xinitrc
via gentoo-pipewire-launcher
command. System-wide Pipewire seems to be either unsupported, or really hard to set up properly. This means that each user that runs startx
will have his own Pipewire session. And the problem is - those sessions start fighting with each other for your audio device. In practice this means that you hear a piece of sound from one user, then a bit from the other, and so on.
Luckily I found a fix - you should enable TCP support in pipewire-pulse.conf
(requires USE="sound-server" media-video/pipewire
):
pulse.properties = {
# the addresses this server listens on
server.address = [
"unix:native"
{
# Use TCP socket for multi-user audio
address = "tcp:4713"
# Important: permissions for clients
# If not allowed, remote clients might get "access denied"
# error when trying to e.g change volume
client.access = "allowed"
}
]
}
Now add this to your .zshenv
(or whatever shell you use):
export PULSE_SERVER=tcp:127.0.0.1:4713 # Use TCP for multi-user audio
And there you are! Now your Pipewire listens on TCP port and allows for multiple client connections, giving your that seamless audio experience 🔥