cli icon indicating copy to clipboard operation
cli copied to clipboard

Can't run commands without sudo: "EACCES: permission denied" error

Open jonathanmorris180 opened this issue 1 year ago • 2 comments

Note Before you submit your issue, make sure that:

  • You're using the latest version of Salesforce CLI.
  • You've searched both open and closed issues for related posts.
  • You've used the doctor command to diagnose common issues.
  • You understand that GitHub Issues don't adhere to any agreement or SLA.
    • If you require immediate assistance, use official channels such as Salesforce Customer Support.

Summary

I recently updated my Salesforce CLI to the latest version. Now, whenever I run any commands, I'm getting errors like this:

$ sf --version                                                                                                                                                                                                                                                                                                                                                                           
@salesforce/cli/2.33.3 darwin-arm64 node-v20.11.1
node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/Users/jonathanmorris/.sf/sf-2024-03-23.log'
Emitted 'error' event on ThreadStream instance at:
    at Immediate.<anonymous> (/usr/local/lib/sf/node_modules/thread-stream/index.js:366:12)
    at process.processImmediate (node:internal/timers:478:21)

Node.js v20.11.1

Steps To Reproduce

IMPORTANT Provide a repository that's configured to reproduce the issue. If you are unable to provide a repo, please explain why not. The more info we have from the start, the faster we can resolve your issue. We may close your issue if you don't include proper instructions.

  • Generate a project with sf project generate or fork dreamhouse-lwc.
  • Provide detailed step-by-step instructions on how to reproduce the issue.
  • Install the latest version of the Salesforce CLI on:
ProductName:            macOS
ProductVersion:         14.4
BuildVersion:           23E214
  • Run any command (e.g. sf org list --json)

Expected result

It outputs the expected orgs as json

Actual result

You get the error above

System Information

Using shell zsh System information:

ProductName:            macOS
ProductVersion:         14.4
BuildVersion:           23E214
$ sf version --verbose --json                                                                                                                                                                                                                                                                                                                                                            
node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/Users/jonathanmorris/.sf/sf-2024-03-23.log'
Emitted 'error' event on ThreadStream instance at:
    at Immediate.<anonymous> (/usr/local/lib/sf/node_modules/thread-stream/index.js:366:12)
    at process.processImmediate (node:internal/timers:478:21)

Node.js v20.11.1

Additional information

  • I have checked the permissions of my ~/.sf directory and I have all needed permissions:
$ ls -la | grep -E "(\.sf)$"                                                                                                                                                                                                                                                                                                                                                        
drwx------   18 jonathanmorris  staff         576 Mar 22 21:00 .sf
  • I am using the installed binary from https://developer.salesforce.com/tools/salesforcecli
  • I tried uninstalling the binary and installing v2.23.0 with npm i -g @salesforce/[email protected] and still had the same issue
  • For some reason, running with sudo makes commands work
  • Output of /Users/jonathanmorris/.sf/sf-2024-03-23.log:
{"level":40,"time":1711155668955,"name":"sf:TelemetryReporter","msg":"Connection to https://dc.services.visualstudio.com timed out after 1000 ms"}
{"level":40,"time":1711164340372,"name":"sf:TelemetryReporter","msg":"Connection to https://dc.services.visualstudio.com timed out after 1000 ms"}

Update: I downgraded to @salesforce/[email protected] with npm and it started working. Would love to know what the issue is with later versions.

jonathanmorris180 avatar Mar 23 '24 04:03 jonathanmorris180

Hello @jonathanmorris180 :wave: It looks like you didn't include the full Salesforce CLI version information in your issue. Please provide the output of version --verbose --json for the CLI you're using (sf or sfdx).

A few more things to check:

  • Make sure you've provided detailed steps to reproduce your issue.
    • A repository that clearly demonstrates the bug is ideal.
  • Make sure you've installed the latest version of Salesforce CLI. (docs)
    • Better yet, try the rc or nightly versions. (docs)
  • Try running the doctor command to diagnose common issues.
  • Search GitHub for existing related issues.

Thank you!

github-actions[bot] avatar Mar 23 '24 04:03 github-actions[bot]

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

github-actions[bot] avatar Mar 23 '24 04:03 github-actions[bot]

For some reason, running with sudo makes commands work

@jonathanmorris180 did you npm install it with sudo too? see: https://github.com/forcedotcom/cli/issues/2480#issuecomment-1727981379

cristiand391 avatar Mar 27 '24 16:03 cristiand391

@cristiand391 I can try doing that for the latest release installed with npm, but why would that be needed for the binary installation from https://developer.salesforce.com/tools/salesforcecli?

jonathanmorris180 avatar Mar 27 '24 23:03 jonathanmorris180

This issue has not received a response in 7 days. It will auto-close in 7 days unless a response is posted.

github-actions[bot] avatar Apr 04 '24 01:04 github-actions[bot]

@cristiand391 Any further info on this? Would be great to get a resolution.

jonathanmorris180 avatar Apr 04 '24 02:04 jonathanmorris180

@jonathanmorris180 sorry, I was out most of the last week.

can you check if you have a log file owned by the root user?

ls -la ~/.sf/*.log

I can repro the error when I change to owner of any log to root (chown root <filepath>):

➜  ~ ls -la | grep -E "(\.sf)$"
drwx------@   8 cdominguez  staff    256 Apr  4 12:33 .sf
➜  ~ ls -la ~/.sf/*.log
-rw-r--r--  1 root  staff  0 Apr  4 12:24 /Users/cdominguez/.sf/sf-2024-04-04.log
➜  ~ sf config list
node:events:492
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/Users/cdominguez/.sf/sf-2024-04-04.log'
Emitted 'error' event on ThreadStream instance at:
    at Immediate.<anonymous> (/Users/cdominguez/.nvm/versions/node/v20.10.0/lib/node_modules/@salesforce/cli/node_modules/thread-stream/index.js:366:12)
    at process.processImmediate (node:internal/timers:478:21)

Node.js v20.10.0

and then change the owner back to my username:

➜  ~ chown cdominguez ~/.sf/*.log
chown: /Users/cdominguez/.sf/sf-2024-04-04.log: Operation not permitted
➜  ~ sudo chown cdominguez ~/.sf/*.log
Password:
➜  ~ ls -la ~/.sf/*.log
-rw-r--r--  1 cdominguez  staff  0 Apr  4 12:24 /Users/cdominguez/.sf/sf-2024-04-04.log
➜  ~ sf config list
List Config
=====================================
| Name              Location    Value
| ───────────────── ─────────── ─────
| disable-telemetry Environment true
| target-dev-hub    Global      na40

cristiand391 avatar Apr 04 '24 15:04 cristiand391

Hi @cristiand391, no worries, thanks for looking into it. All the log files and the .sf dir are owned by my user:

ls -la ~ | grep -E "(\.sf)$"  
drwx------   16 jonathanmorris  staff         512 Apr  4 20:00 .sf
ls -la ~/.sf/*.log     
-rw-r--r--  1 jonathanmorris  staff   588 Mar 29 12:02 /Users/jonathanmorris/.sf/sf-2024-03-29.log
-rw-r--r--  1 jonathanmorris  staff  3087 Apr  1 17:59 /Users/jonathanmorris/.sf/sf-2024-04-01.log
-rw-r--r--  1 jonathanmorris  staff   735 Apr  2 16:08 /Users/jonathanmorris/.sf/sf-2024-04-02.log
-rw-r--r--  1 jonathanmorris  staff  2352 Apr  3 19:23 /Users/jonathanmorris/.sf/sf-2024-04-03.log
-rw-r--r--  1 jonathanmorris  staff  1470 Apr  4 19:58 /Users/jonathanmorris/.sf/sf-2024-04-04.log
-rw-r--r--  1 jonathanmorris  staff  1176 Apr  4 20:34 /Users/jonathanmorris/.sf/sf-2024-04-05.log
-rw-r--r--  1 jonathanmorris  staff     0 Mar 23 20:15 /Users/jonathanmorris/.sf/sf.log

Weirdly, I just tried updating to the latest version again and now somehow it's working:

npm list -g                                                                                                                                                                                                                                                                                                                                                                            
/Users/jonathanmorris/.nvm/versions/node/v20.11.1/lib
├── @salesforce/[email protected]
├── [email protected]
└── [email protected]
npm install --global @salesforce/[email protected]                                                                                                                                                                                                                                                                                                                                            

added 229 packages, removed 162 packages, and changed 808 packages in 45s

120 packages are looking for funding
  run `npm fund` for details
sf --version                                                                                                                                                                                                                                                                                                                                                                           
 ›   Warning: @salesforce/cli update available from 2.33.3 to 2.35.6.
@salesforce/cli/2.33.3 darwin-arm64 node-v20.11.1

Weird issue, but at least it was only temporary! Thanks for the help.

jonathanmorris180 avatar Apr 05 '24 03:04 jonathanmorris180