Can't run aplay as root!
12,209
Solution 1
Your root shell is coming from su
right? The environment variable $XDG_RUNTIME_DIR
is being inherited from your user shell. You can either run export XDG_RUNTIME_DIR=""
before aplay
to clear it, or you can use sudo -i
instead of su
to get a clean environment.
Solution 2
As the error message shows, the connection is refused if it is not the original user that requests it. As root, you can use sudo
to issue the command as that user, but the XDG_RUNTIME_DIR
also needs to be the one of that user,
sudo -u '#1000' XDG_RUNTIME_DIR=/run/user/1000 aplay ...
Check the original user ID with id -u
, it might not be 1000.
Related videos on Youtube
Author by
Bibek_G
Updated on September 18, 2022Comments
-
Bibek_G over 1 year
Not that I need to
aplay
as root but it came across me and I wondered why it shouldn't work.# aplay /home/bibek/apert.wav XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.) ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave aplay: main:722: audio open error: No such file or directory
I can see that it is giving me reasonable amount of details but I still don't understand.
-
Bibek_G over 8 yearsActually, I also tried doing a fresh login as root from tty2 and run the comand only to get the same result. this time it gives me only the last two lines of error, however! Could it be possible that alsa is not properly configured for root or something. I feel like that
No such file or directory
shouldn't be there otherwise.