1

I have an external instance IP which is setup correctly with my SSH keys. If I run the following code to access the GCP instance.

>> ssh <instance IP>
# Login happens
>> gcloud <some command>
# Gcloud outputs as expected

However, I can't run the gcloud command directly over ssh. That is

>> ssh <instance IP> gcloud <some command>
bash: gcloud: command not found

I believe this is the root cause of some issues I am seeing where I have permissions to run commands if I manually ssh and run in the interactive shell, but not if I pass the command through ssh.

I have tried

>> ssh <INSTANCE IP> -t "source ~/.bashrc; gcloud auth list"
bash: gcloud: command not found
>> gcloud compute ssh instance-name -- -t "gcloud"
bash: gcloud: command not found
>> gcloud compute ssh instance-name --command="gcloud"
bash: gcloud: command not found

and similar tricks around bashrc and gcloud, but there's nothing google-related in there I can see immediately anyway.

The instances are running Ubuntu 20.04, more or less fresh images. The problem is there between instances, or on my local machine connecting to instances.

I suspect I'm missing something simple here - any takers?

3
  • Have you tried running gcloud directly from the binary? e.g.: ssh <instance-external-IP-addr> -t "/usr/bin/gcloud auth list" Commented Aug 12, 2020 at 17:40
  • gcloud is configured per user. Are you using the same identity to login via both methods. Use the Linux command env to double-check the environment under both login methods. Commented Aug 12, 2020 at 17:50
  • Thank you both - this helped track down the answer, below.
    – Mark
    Commented Aug 12, 2020 at 19:52

1 Answer 1

2

After checking the binary location on ssh

>> which gcloud
/snap/bin/gcloud

The issue is caused by /snap/bin not being on PATH, as described here.

That bug is being actively worked on now but doesn't appear to be complete yet. It specifically affects ubuntu, and the fact gcloud is installed as a snap in the default distribution.

This led to some misleading issues - in my case, gcloud was being used as an authenticator for docker, but lack of availability meant the error produced was a "missing permissions" error.

A workaround is

>> ssh <instance IP> PATH=$PATH:/snap/bin/ gcloud <some command>

Hope this helps someone!

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