Andres Padron
Andres Padron

Reputation: 11

Permission denied (publickey) FreeBSD in Google Computer Engine

I have problems accessing my instance via SSH through the google cloud and also when trying to connect remotely, when trying to connect using the gcloud command on my mac it tells me:

Permission denied (publickey).
ERROR: (gcloud.beta.compute.ssh) [/usr/bin/ssh] exited with return code [255].

The command I am using is the following:

gcloud beta compute --project "my-instance" ssh --zone "server" "freebsd-11-1"

What can it be ?, I import the SSH keys into the metadata of my instance.

I don't know if they affect the permissions of the .ssh folder, I don't know what they are

Upvotes: 0

Views: 673

Answers (1)

dany L
dany L

Reputation: 2654

Permission denied with error code 255 can be due to the following reasons:

1.Incorrect user. Make sure to authenticate with appropriate user having the appropriate role in IAM by using the following commands

gcloud auth list

to check active user

gcloud auth login

to log in with appropriate user

2.Issue with keys. Force gcloud to recreate the user’s SSH key pair and try to SSH again. Move the existing key pair aside using these commands:

   mv ~/.ssh/google_compute_engine ~/.ssh/old-google_compute_engine
   mv ~/.ssh/google_compute_engine.pub ~/.ssh/old-google_compute_engine.pub

3.Firewall issue. Check your firewall to see if port 22 is opened for the instance in question.

4.Volume or memory issue. Make sure root volume is not out of disk space or that there are no out of memory issues by going to serial console logs [Menu>Compute Engine>Vm_name>Logs (serial port console)]. You are looking for the following clues

  • No space left on device
  • No usable temporary directory found
  • Out of memory

Increasing the boot disk size or increasing the machine type might help.

5.Linux Guest Environment scripts issue. In order to fix a guest environment issue you may check the following documentation in order to verify the expected output and how to install the required packages.

6.Permission issue. Check folder and Authorized_keys file permissions.

5 and 6 might be difficult to perform if you cannot SSH, however you can log in via serial console this way:

a). Activate the “Connect to serial console” button.

Go to VM instances, click on your VM, Edit, and active “enable connecting to serial ports” in the Remote access area and click on save.

b). Create a username and password.

Go to Vm instance, click on your Vm again, Edit, and fill up the custom metadata section with:

In key: startup-script

In value:

#! /bin/bash
adduser USERNAME
echo 'USERNAME:PASSWORD' | chpasswd
usermod -aG google-sudoers USERNAME

Note that instance might require a reboot for changes to take effect.

Upvotes: 3

Related Questions