root can't access pulseaudio in recent builds
It worked on Ubuntu 18.04 pulseaudio version 11.1, and is broken on Ubuntu 20.04 pulseaudio version 13.99.1. pulseaudio daemon is started by the user in both cases. There are two issues.
First, if the pactl
command is run with sudo inheriting users home directory it prints
Home directory not accessible: Permission denied
Why? Who cares? You are running from root. Just open it! The security implications of sudo with inherited HOME dir is out of scope here.
Second, even if the home directory is set correctly, pulseaudio refuses to accept connections from root
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
Why? Why don't you let root do whatever he wants? Also it is a regression from older version where it was allowed.
There is a workaround running pulseaudio daemon from root system wide etc etc. But seriously, there is absolutely no need in this complications. Just let the god damn root access pulseaudio and it will work out of the box as it was before.