Linux in QEMU / UTM VM: davfs2 mount works but has root access only

3 min read 21-10-2024
Linux in QEMU / UTM VM: davfs2 mount works but has root access only

In the realm of virtualization, users often encounter various challenges, especially when working with different file systems and mounting protocols. A common issue arises with the davfs2 mount in a Linux environment running on QEMU or UTM VM, where the file system successfully mounts, but with access limited to the root user only. This can hinder the usability and functionality for regular users.

The Problem Scenario

In a typical setup involving davfs2 on a QEMU or UTM virtual machine, you might encounter the following situation:

# Attempting to mount a WebDAV share
sudo mount -t davfs https://example.com/webdav /mnt/webdav

After running this command, while the WebDAV share may mount correctly, regular users find that they cannot access the mounted directory due to restricted permissions.

Analysis of the Problem

The primary issue here revolves around the permissions set during the mount operation. When you mount a WebDAV share using davfs2 as the root user, it creates the mount point with root privileges. Consequently, other users lack the necessary permissions to access the mounted directory. This is not an uncommon scenario, particularly in environments that prioritize security and user access control.

Why Does It Happen?

  1. Default Permissions: By default, most mount operations reserve the mounted directory for the root user. The permissions are typically set to 755 (rwxr-xr-x), allowing only the root user to write to the directory.
  2. Davfs2 Configuration: The configuration file for davfs2, typically located at /etc/davfs2/davfs2.conf, may not have specific settings to allow user access.

Solution: Configuring davfs2 for User Access

To resolve the issue of restricted access, you can modify the davfs2 settings and user permissions accordingly. Here’s how to do that:

  1. Edit the Configuration File: Open the davfs2.conf file and ensure that you allow user mounts:

    sudo nano /etc/davfs2/davfs2.conf
    

    Look for the following line and set it to:

    # allow_other = 0
    

    Change it to:

    allow_other = 1
    

    This will allow other users to access the mounted filesystem.

  2. Set User Permissions: You can also set the mounted directory permissions so that all users can access it. After mounting the share, change the permissions as follows:

    sudo chmod 777 /mnt/webdav
    
  3. Mounting with User Option: Alternatively, consider mounting the filesystem using the user option, which allows non-root users to mount the filesystem:

    mount -t davfs -o user https://example.com/webdav /mnt/webdav
    

Practical Example

Let’s say you are using davfs2 to mount a WebDAV share located at https://example.com/webdav. Here’s a step-by-step example of how to correctly set it up for user access:

  1. Install davfs2 if you haven’t already:

    sudo apt install davfs2
    
  2. Create a mount point:

    mkdir /mnt/webdav
    
  3. Edit the configuration to allow user access:

    sudo nano /etc/davfs2/davfs2.conf
    

    Set allow_other = 1 as described above.

  4. Use mount with user options to mount the share:

    mount -t davfs -o user https://example.com/webdav /mnt/webdav
    
  5. Verify the permissions:

    ls -l /mnt/webdav
    
  6. Now, any user on the system should be able to read from and write to the mounted WebDAV share.

Conclusion

Using davfs2 with a WebDAV share in a Linux virtual machine environment like QEMU or UTM can enhance your productivity significantly. However, understanding and configuring user permissions is essential for making the most of your setup. By allowing non-root users access to the mounted directories, you can enable collaborative workflows without compromising security.

Additional Resources

By following the guidelines mentioned in this article, you can effectively troubleshoot and optimize your davfs2 setup for a seamless user experience in your virtualized Linux environment.