Linux/Ubuntu Failed to save 'hosts': Insufficient permissions. Select 'Retry as Sudo' to retry as superuser

Title: Cursor Editor Fails to Save Files Requiring Sudo Permissions

Error Message:
Failed to save ‘hosts’: Command failed: cd “/home/nasser”; “/usr/bin/pkexec” --disable-internal-agent /bin/bash -c “echo SUDOPROMPT; "/tmp/.mount_cursorJ2dXA6/usr/share/cursor/bin/cursor" --file-write "/home/nasser/.config/Cursor/code-elevated-3SHUG2Jz"”
/bin/bash: line 1: /tmp/.mount_cursorJ2dXA6/usr/share/cursor/bin/cursor: Permission denied

Issue Description:
When attempting to save files that require sudo permissions (like /etc/hosts), Cursor fails with a permission denied error. The error occurs because:

  1. Cursor is trying to use pkexec (graphical sudo prompt) to handle elevated permissions
  2. The command is failing because it’s trying to execute Cursor from within its temporary mount point (/tmp/.mount_cursorJ2dXA6/)
  3. The temporary mount point has restricted permissions that prevent the sudo operation from working

Steps to Reproduce:

  1. Open a file that requires sudo permissions (e.g., /etc/hosts) in Cursor
  2. Make changes to the file
  3. Attempt to save the file
  4. The error occurs when Cursor tries to use pkexec for elevated permissions

Expected Behavior:
Cursor should successfully save files requiring sudo permissions, similar to how VSCode handles it.

Actual Behavior:
The save operation fails with a permission denied error, making it impossible to edit files requiring sudo permissions directly in Cursor.

Workaround:
Currently, the only workaround is to use a different editor (like VSCode) for files requiring sudo permissions.

Environment:

  • OS: Linux 6.11.0-25-generic
  • Cursor: Latest version (AppImage)
  • File System: Ext4
1 Like

Alternative solution with extension Save as Root in Remote - SSH - Visual Studio Marketplace

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.