2

In my job, I support remote employees running Linux Mint via SSH and VNC.

Each employee uses a USB headset, which is the only sound device we want to be active. The sound device we need to disable is the "Built-in Audio" device, and if I open up a terminal on the employee's desktop, I can check whether the device is disabled by running pacmd list-sinks | grep "Built-in Audio".

This command also works over SSH if I login with the employee's username and password, but if I try to SSH with our admin "IT" username, it gives me the error "No PulseAudio daemon running, or not running as session daemon." Help! For security, I don't have the local passwords of each employee, but I can't seem to check whether Built-In Audio is active when I SSH via my IT username, even when I elevate IT to root privileges with su.

I've tried using su - [employee] and then accessing the local display with the command export DISPLAY=:0, but that didn't allow me to check the sound devices either. :(

2
  • if you do xhost local:employee user, you can do then "export DISPLAY=:0 command" Nov 19, 2015 at 20:19
  • Alas, that didn't seem to work for me. :( It worked to be able to open local applications (gedit, etc) but it still isn't pointing to my sound devices with the pacmd command. Nov 19, 2015 at 20:40

2 Answers 2

1

I figured it out! It turns out that the aplay --list-devices command held the variable I needed. Running that command gave me the cards on the target computer, along with a "Subdevices 1/1" string on the next time down. That "subdevices" string would change to 0/1 if the device was on, and to 1/1 if it was off.

From there, I just had to pipe grep -A 1 so that I could parse out the card's state (in this case named "Analog") and then encase the output within an if/then statement for whether the Built-in Audio was on or off.

if aplay --list-devices|grep -A 1 Analog|grep Subdevices:\ 0/1;then echo Built-in IS ON;else echo off

1

Short answer: set XDG_RUNTIME_DIR

sudo su -l employee_login
export XDG_RUNTIME_DIR=/run/user/$(id -u)
pacmd list-sinks | grep "Built-in Audio" 

Explanation

The trick is that PulseAudio looks in ${XDG_RUNTIME_DIR} for the sockets it needs to communicate to the daemon. However, XDG_RUNTIME_DIR is set by PAM (Pluggable Authentication Modules for Linux) when a user logs in. When you use sudo or su, you've skipped PAM and so that variable is unset.

Step 1: Become the user

sudo su -l employee_login

The su command sets your effective UID (user ID) to the same as the employee you are trying to help. This is necessary because PulseAudio is persnickety about such things and will refuse to work.

The -l is not strictly necessary, but it sometimes helps with debugging possible issues as it runs the user's login scripts.

The sudo is unnecessary before su -l employee_login if you have already elevated your privileges to root.

Step 2: Set XDG_RUNTIME_DIR

export XDG_RUNTIME_DIR=/run/user/$(id -u)

Setting XDG_RUNTIME_DIR is necessary because that is where the PulseAudio daemon, which is launched when the user logs in, creates the sockets pulse/native and pulse/cli used for communication with clients. [Footnote 1]

Step 3: Use PulseAudio

pacmd list-sinks | grep "Built-in Audio"

The pacmd tool lets one introspect (or reconfigure) a running PulseAudio daemon. One can think of PulseAudio's term sink as meaning "speakers" and source as meaning "microphone".

Here we are running PulseAudio's list-sinks command which lists all available output devices. We use grep to check for the presence of "Built-in Audio" because, in the original question, the employees' machines were supposed to have that disabled and thus not available as a possible sink.

Note that pacmd (and its younger cousin pactl) are much more powerful than this and can be used to not only diagnose but remotely fix problems. For example, if the audio output is correct, but the wrong microphone is being chosen by default, one could do something like:

pactl set-default-source alsa_input.usb-USB_Camera_USB_Camera_SN0001-02.analog-mono 

Tip: pacmd and pactl are best used with bash-completion installed so one can use TAB twice to see options and once to complete long source/sink names. However, avoid the peculiar command-line builtin to pacmd as it does not use libreadline and has no history or completion.

Footnote 1

Technically, the PulseAudio daemon does not always use XDG_RUNTIME_DIR. For example, if the daemon is started when that variable is unset, it'll use /tmp with a symlink to it in ~username/.config/pulse/audiodevice-runtime. Similarly, one could configure PulseAudio to share sockets with other users or between containers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .