14

I am facing some kind of permission issue here. I am able to read a file with cat, make changes to it using nano but for some reason, jq is having permission issues. Here is what I am facing:

msp@coolpad:~/projects/lol$ jq .name lol.json
jq: error: Could not open file lol.json: Permission denied

On checking permissions, this is what I get:

msp@coolpad:~/projects/lol$ ls -l
total 4
-rw-rw-r-- 1 msp msp   0 Sep 27 04:04 lol-domains.txt
-rwxrwxrwx 1 msp msp 593 Sep 27 04:38 lol.json

As you can see, I have tried giving it 777 permission, still it's showing Permission denied. I know this is not a good idea to set 777 permission and I fully intend to change it back to 664 once the issue is resolved. Anyhelp would be appriciated.

Update 1: I have tried re-installing jq from snap but still, it doesn't solve the problem.

Update 2: Output of cat lol.json

msp@coolpad:~$ cat lol.json
{"name":"lol"}

Update 3: Output of echo '{"name":"lol"}' | jq .name

msp@coolpad:~$ echo '{"name":"lol"}' | jq .name
"lol"

Update 4: One work-around that poped up in comments:

cat lol.json | jq .name

13
  • 1
    Add output of cat lol.json to your question.
    – Cyrus
    Sep 27, 2019 at 5:08
  • @Cyrus just did!
    – Panda
    Sep 27, 2019 at 5:20
  • 1
    @anishsane, it was meant to explain the situation here. Even with all permissions, I have absolutely no idea why this is not working. Kindly read the whole question before commenting.
    – Panda
    Sep 27, 2019 at 7:12
  • 1
    Add Output of ls -lZ $(which jq)to your question.
    – Cyrus
    Sep 27, 2019 at 8:38
  • 4
    Ubuntu did something weird with snaps again. I suggest you install jq from the official website (they have a static binary) or with apt (older version but works)
    – clorz
    Oct 24, 2019 at 9:49

1 Answer 1

34
sudo snap remove jq
sudo apt install jq

Don't install command line tools with snap without --classic.

Snap packages have "confinement" which is either "strict" or "classic". jq is only packaged as "strict" meaning it has its own /tmp/snap.jq/ directory and cannot read the system /tmp directory and a bunch of other directories. Packages that want to use "classic confinement" have to be manually approved by the people in charge of Snapcraft and you must pass --classic when installing them, like this: sudo snap install <package_name> --classic.

To avoid this, just never install command line tools with snap. This error is intended behavior and they're not going to change it.

1
  • This worked for me, but I had to do one more step (jq was still pointing to /snap/bin/jq after... ¯\_(ツ)_/¯ so I had to run source ~/.profile to clear the error (leaving to help those who come after me:-) Oct 12, 2022 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.