Reputation: 451
I'm trying to copy a directory from my vm to my local machine's Desktop with the following command:
gcloud compute scp --recurse instance-1:~/directory ~/Desktop/
I tried reauthenticating with "gcloud auth login" however it still says
ERROR: (gcloud.compute.scp) Could not fetch resource:
- Insufficient Permission: Request had insufficient authentication scopes.
Upvotes: 23
Views: 44005
Reputation: 308
What worked for me is:
gcloud config set account <YOUR MASTER GMAIL ACCOUNT>
gcloud auth login (follow the instructions to load the provided url in a browser and get a code)
gcloud compute scp ....
Then revert back to the service account with:
gcloud config set account <SERVICE ACCOUNT>
To list credentialed accounts:
gcloud auth list (the one with austeriks is the active one)
Upvotes: 0
Reputation: 1
Try run gcloud auth login
(Make sure you have valid SSH Keys).
It will then ask to go to a link in your browser, once you open the link in your browser sign into your Google Account your instance is running on. Authorize what it asks you authorize, then input the verification code into your Machine.
Do not share the authorize code with anyone as it acts like a password in some cases.
Upvotes: 0
Reputation: 59
Providing entire code for better understanding
private static void upload() throws GeneralSecurityException, IOException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Drive driveService = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
File fileMetadata = new File();
fileMetadata.setName("My Report");
fileMetadata.setMimeType("application/vnd.google-apps.spreadsheet");
java.io.File filePath = new java.io.File("/exportData.csv");
FileContent mediaContent = new FileContent("text/csv", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
}
Upvotes: -1
Reputation: 81356
You will need roles/compute.instanceAdmin.v1
to use SSH or SCP to an instance for the credentials that you are using. The simplest method is to add Compute Instance Admin
to your credentials.
To see what credentials you are using execute gcloud auth list
. The account will have an asterisk in the left column.
To figure out what permissions you have execute gcloud projects get-iam-policy PROJECT_ID
Upvotes: 6
Reputation: 781
Try to run a "gcloud auth login" from the machine that you are trying to run the gcloud command.
For more information have a look at this old post, they are reporting the same issue.
Upvotes: 46