getcursor / cursor

The AI-powered code editor
https://cursor.sh
20.57k stars 1.38k forks source link

[Linux] Can't save files that require elevated permissions #1442

Open Haraven opened 1 month ago

Haraven commented 1 month ago

Description

On Linux, if you try to save files in protected locations (e.g., /usr/bin/), Cursor throws an error. At first, it says I have insufficient permissions and prompts me to retry as sudo. If I retry as sudo, I get the password prompt, I enter my sudo password, then I get the following error:

Failed to save 'MY_FILE': Command failed: cd "/home/MY_USER"; "/usr/bin/pkexec" --disable-internal-agent /bin/bash -c "echo SUDOPROMPT; \"/tmp/.mount_cursorLCl8Ir/bin/cursor\" --file-write \"/home/MY_USER/.config/Cursor/code-elevated-58oyqfTF\" \"/usr/bin/MY_FILE\"" /bin/bash: line 1: /tmp/.mount_cursorLCl8Ir/bin/cursor: Permission denied

In VSCode I get the retry as sudo prompt too, but the major difference is that after I enter my password, the file saves successfully.

Steps to reproduce

  1. Create a new file in Cursor and write whatever you want in it
  2. Try to save the file in a protected location. I used /usr/bin/
  3. When you get the insufficient permissions notification in Cursor, select "Retry as Sudo"
  4. Enter your sudo password in the polkit prompt that appears
  5. Watch as you get another error notification in Cursor

OS information

Haraven commented 1 month ago

As a follow-up, after looking into this issue some more, it seems to be a problem with the way AppImages work. They run in a sandboxed environment and they don't let you run commands that require elevated permissions.

In VS Code this doesn't happen because in my case I am using an RPM version. But since Cursor is only available as an AppImage, the issue persists.

If I try to run Cursor with elevated privileges (sudo /path/to/cursor.AppImage), I get this terminal error: [0530/122225.619999:FATAL:electron_main_delegate.cc(295)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180..

If i try to add the --no-sandbox flag, it still doesn't work. Running /path/to/cursor.AppImage --no-sandbox still leads to the same permissions error. Running sudo /path/to/cursor.AppImage --no-sandbox causes another error to pop up in the terminal: [22642:0530/122312.689466:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY [22642:0530/122312.689547:ERROR:env.cc(257)] The platform failed to initialize. Exiting. fish: Job 1, 'sudo path/to/cursor.AppImage' terminated by signal SIGSEGV (Address boundary error)

So, no matter what I do, I can't save files that require elevated permissions. This is annoying, because what I end up doing is opening my file in VS Code, copy pasting my changes, saving it, then going back to Cursor.

This back and forth between Cursor and another text editor with elevated privilege access shouldn't be needed...

Haraven commented 3 weeks ago

Seems like I'm alone with this issue. I did some digging on the Cursor forums and found this thread where someone recommends installing the Save as Root in Remote VSCode extension. That adds a new command you can run via CTRL+SHIFT+P: Save as Root.

That lets you save files with elevated permissions.

It's a workaround, not a solution, though.