Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make pulseaudio run as root?

If I take an mp3 file and try to hear it using my normal user account using sox file.mp3 -d , it works flawlessly. However, if I try to do the same thing after doing sudo su, it yields: Home directory not accessible: Permission denied.

The use-case is as follows:

I have my .bashrc linked between my root and my normal user accounts. A particular line in my .bashrc that works using google_speech (which leverages sox, which seems to use pulseaudio as the default):

function sayhi() {
    if [ "$EUID" -ne 0 ]; then
        printf "Hi, $USER! Your directory is currently "${PWD}""
        google_speech -l en "HELLO $USER!"
    else
        printf "Woah, we have a Superuser on our hands. Best be careful!"
        google_speech -l en "WARNING: ROOT ACTIVATED"
    fi
}
sayhi &

This means if I do something like sudo su I should end up with my computer talking to me. Instead, I get: Home directory not accessible: Permission denied.

How do I fix this?

like image 956
David Moore Avatar asked Oct 23 '25 14:10

David Moore


1 Answers

Solution run PulseAudio for all your users

Add bellow lines into /etc/systemd/system/pulseaudio.service file and save

[Unit]
Description=PulseAudio system server

[Service]
Type=notify
ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal

[Install]
WantedBy=multi-user.target

Enable service

sudo systemctl --system enable pulseaudio.service
sudo systemctl --system start pulseaudio.service
sudo systemctl --system status pulseaudio.service

Edit Client conf /etc/pulse/client.conf and replace ass bellow

default-server = /var/run/pulse/native
autospawn = no

Add root to pulse group

sudo adduser root pulse-access

And finally reboot the system

like image 62
Areg Gasparyan Avatar answered Oct 26 '25 05:10

Areg Gasparyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!