2

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?

David Moore
  • 90
  • 1
  • 8
  • 1
    Do you know the location home directory is referring to? – Raman Sailopal Mar 24 '21 at 09:21
  • Does this answer your question? [How to use the pulseaudio API as root?](https://stackoverflow.com/questions/42458387/how-to-use-the-pulseaudio-api-as-root) – Ruud Helderman Mar 24 '21 at 11:43
  • @RamanSailopal I do not. It should be referring to /home/username (my username is actually username on this device). If that is the case, it is owned by username:username, but I don't see why my root account wouldn't have permission over that. – David Moore Mar 25 '21 at 19:12

4 Answers4

6

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

Areg Gasparyan
  • 101
  • 1
  • 5
  • Great, this worked for me. In my case file `/etc/systemd/system/pulseaudio.service` was not there and I had to create and add the lines in the solution. – Aelian Dec 06 '22 at 08:24
1

Easy solution: https://askubuntu.com/questions/751750/pulseaudio-on-root-usermode

Run pulseaudio -D as root on each start up.

You can put the command pulseaudio -D in a startup script and run it every time you start the computer.

0

This solution has worked for me on several debian 11 servers but have a Dell r620 and r720 where the sound card causes the machine to hang after 2-3min of video. I finally got an HDMI sound extractor to work with a 25w HDMI graphics card on the r620 but fiddling with /etc/pulse/default.pa default card settings didn't fix it. Managed to get sound from alsaplayer, removed all changes to /etc/pulse/default.pa and /etc/asound.conf and started pulse as a user and it HDMI detected and can watch videos without hanging.

Added this back to /etc/systemd/services, re-enabled, and it didn't work but after manual restart of pulse service as root the HDMI showed up again. Modified the file to delay startup of pulse and now it works. So if you find it doesn't work when you first boot but does after manual restart try adding ExecStartPre=/bin/sleep 30. The changes to /etc/pulse/client.conf did not seem necessary but I haven't tested thoroughly.

File /etc/systemd/system/pulseaudio.service as follows

[Unit]
Description=PulseAudio system server

[Service]
Type=notify
ExecStartPre=/bin/sleep 30
ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal

[Install]
WantedBy=multi-user.target
sjohn
  • 1
  • 1
-2

Just to correct the last shell cmd the last writer Areg Gasparyan told, should be correctly afaic:

sudo useradd -g root pulse-access
  • Your answer actually creates a user named "pulse-access" and adds it to the "root" group. The command given by Areg Gasparyan works just fine. – tzengia Dec 14 '22 at 05:36