Max Baldwin
Max Baldwin

Reputation: 3472

Run gcloud without sudo

I'm on Mac OSX and I've always had to run the gcloud command with sudo. I can usually work around it, but it has started to cause me some issues. I tried following this answer here, but I am not sure where the gcloud command gets called from. It's not in /usr/bin.

I have found that my gcloud sdk is installed at /Users/Max/Desktop/google-cloud-sdk/, and I have tried adding /bin/gcloud and '/lib/gcloud.py' from that path. No luck! Any idea how I can give NOPASSWD permissions to this command?

Upvotes: 4

Views: 3240

Answers (2)

phip
phip

Reputation: 607

I'm on macOS and my issue was that my google-cloud-sdk install folder and it's config folder at ~/.config/gcloud were owned by root. The fix is to sudo chown -R <your-username> google-cloud-skd and sudo chown -R <your-username> ~/.config/gcloud. And done: no more sudo.

Upvotes: 7

Max Baldwin
Max Baldwin

Reputation: 3472

I was able to resolve this issue myself. This article was very helpful. Ultimately, you just have to add sudo privileges to the gcloud command. You will have to give those permissions by running sudo visudo and adding a line in the following format:

<yourusername> ALL=NOPASSWD: <command1>, <command2>

Mine line ended up looking like this:

Max ALL=NOPASSWD: /Users/Max/Desktop/google-cloud-sdk/bin/gcloud

The part that tripped me up was figuring out where the gcloud command was installed. You have to add that path at the end of the permissions. You can find out where it is installed by running which gcloud.

Upvotes: -3

Related Questions