还有其他答案,例如:centos - Linux:创建一个可以访问其他用户文件的用户 - 超级用户,但他们没有谈到从 GUI 应用程序访问这些文件。我的问题更广泛,因为我想像访问我自己的文件和目录一样顺利地访问、读取和写入其他用户的文件和目录。
背景
我想限制用户对某些文件和文件夹的访问,因为有时我会在不注销的情况下共享我的笔记本电脑。
使用,如何在没有加密的情况下使用密码保护 Unix/Linux 上的文件夹? - 超级用户,我创建了另一个用户:组
secure:secure
,并将所有权更改为该用户。并且,我递归更改了文件和目录权限,以便仅允许所有者和组对目录进行读取、写入和执行;对文件进行读取和写入。每当我想使用其他文件和文件夹时,我都想切换用户
su - secure
。
问题
- 切换用户后,当我尝试使用终端中的应用程序运行这些文件时,出现以下错误(mpv 和 cvlc 在我原来的用户下都可以正常工作)
$ mpv Hello.mp4
[vo/sdl] SDL_Init failed
Error opening/initializing the selected video_out (--vo) device.
Video: no video
Failed to create secure directory (/run/user/1001/pulse): No such file or directory
Failed to create secure directory (/run/user/1001/pulse): No such file or directory
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
[ao/alsa] Playback open error: No such file or directory
[ao/oss] Can't open audio device /dev/dsp: No such file or directory
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
[ao/jack] cannot open server
Failed to create secure directory (/run/user/1001/pulse): No such file or directory
Failed to create secure directory (/run/user/1001/pulse): No such file or directory
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
couldn't open play stream: No such file or directory
[ao/sndio] can't open sndio default
[ao] Failed to initialize audio driver 'sndio'
Could not open/initialize audio device -> no sound.
Audio: no audio
VO: [gpu] 1280x720 yuv420p
$ cvlc 1.mp4
VLC media player 3.0.9.2 Vetinari (revision 3.0.9.2-0-gd4c1aefe4d)
[0000556cff4e2d10] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[0000556cff4ec480] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0000556cff4ec480] main interface error: no suitable interface module
[0000556cff452670] main libvlc error: interface "dbus,none" initialization failed
[0000556cff516ea0] main interface error: no suitable interface module
[0000556cff452670] main libvlc error: interface "globalhotkeys,none" initialization failed
[0000556cff516ea0] dummy interface: using the dummy interface module...
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
[0000556cff4e2d10] alsa audio output error: cannot open ALSA device "default": No such file or directory
[0000556cff4e2d10] main audio output error: Audio output failed
[0000556cff4e2d10] main audio output error: The audio device "default" could not be used:
No such file or directory.
[0000556cff4e2d10] main audio output error: module not functional
[00007fd7e20afbb0] main decoder error: failed to create audio output
- 在鹦鹉螺,它甚至不让我输入其他用户的密码来浏览其他用户目录的内容。它什么都不做。
问题
我如何才能像访问我自己(主)用户的文件和文件夹一样访问、读取和写入其他用户的文件和文件夹?
另外,执行时不会创建 $XDG_RUNTIME_DIR
su
。我使用了这个替代方案:systemd - 如何在登录/注销时创建/删除 $XDG_RUNTIME_DIR - Unix & Linux Stack Exchange。但是为什么没有创建和设置 $XDG_RUNTIME_DIR?
答案1
您误解了这个问题。当您切换用户时,您就是该用户,并且可以毫无问题地访问这些文件。
您看到的错误与这些文件无关,而是因为它们试图连接到已经在您普通用户下运行的进程。X 配置为阻止不同用户的连接,因此,当 VLC 尝试连接到它时,它会失败,而不是在读取输入文件时失败。
要解决此问题,您必须使用xauth
添加权限,以便新的“安全”用户连接到您的 X11 服务器。然后,当您 su 到其他用户时,您很可能必须检查 DISPLAY 环境变量是否已设置,它应该设置为您的 IP 地址加上 :0(用于第一个显示)。