I would like to run a program remotely (through ssh) but with audio going to the remote machine where the program actually runs. This would normally work with ALSA, but pulseaudio apparently checks some session authenticator before allowing connection from a client.
How to make this check less strict?
local: $ ssh remote # remote is running pulseaudio and has sound hardware remote:$ paplay something.wav Connection failure: Connection refused pa_context_connect() failed: Connection refused remote:$ audacious something.mp3 # opens on local's X11 display pulseaudio: Failed to connect to server: Connection refused pulseaudio: Failed to connect to server: Connection refused
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
In my case, the following worked for me:
pax11publish -r
Method 2
The culprit is that ssh does not set DBUS_SESSION_BUS_ADDRESS which is used to connect to Pulseaudio. A solution (based on this post) was to add the following lines to my ~/.bashrc, which are used when connecting over ssh:
if [[ -n $SSH_CLIENT ]]; then
export DBUS_SESSION_BUS_ADDRESS=`cat /proc/$(pidof nautilus)/environ | tr '' 'n' | grep DBUS_SESSION_BUS_ADDRESS | cut -d '=' -f2-`
fi
it uses the PID of nautilus (you may need to change that so to get some process which is always run in the session) and searches its environment variables for DBUS_SESSION_BUS_ADDRESS and exports it.
This make programs connecting to Pulse run fine. Other programs communicating over the session d-bus work as well (like audtool for driving audacious over command-line).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0