简体   繁体   中英

Unable to ssh via cloud shell terminal [google cloud platform]

It's a couple of days I'm trying to login and use my VM via SSH cloud shell as I always did with no issues.

here the error I got

Transferring SSH keys to the VM. The key transfer to project metadata is taking an unusually long time. Transferring instead to instance metadata may be faster, but will transfer the keys only to this VM. If you wish to SSH into other VMs from this VM, you will need to transfer the keys accordingly. Click here to transfer the key to instance metadata. Note that this setting is persistent and needs to be disabled in the Instance Details page once enabled. You can drastically improve your key transfer times by migrating to OS Login.

After digging a bit I found this more detailed error in my connection log:

Mar 5 13:46:02 ubuntu-tw google-accounts: ERROR Exception calling the response handler. [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/'].#012Traceback (most recent call last):#012 File "/usr/lib/python3/dist-packages/google_compute_engine/metadata_watcher.py", line 200, in WatchMetadata#012

I tried to increase my VM disk space, but the result is the same.

At this point I think the easy way is to simply download my scripts there, but how to access the files?

If you want to change or increase the size of your disk first you must create a new instance and recreate the boot disk from a snapshot to resize it.you can do this with this link Recovering an inaccessible instance or a full boot disk

  1. Go to the VM instances creation page

Google Cloud -> Compute Engine ->VM Instances

a. Click the instance name to open the VM instance details page.

b. Click Stop

c. In the Boot disk section, note the boot disk's size and name.

  1. In the Google Cloud Console, go to the Snapshots creation page.

Google Cloud -> Compute Engine -> Storage -> Snapshots

a. Enter a snapshot Name .

b. Select the boot disk from the Source disk drop-down list.

c. Click Create .

  1. Go to the VM instances creation page.

Google Cloud -> Compute Engine ->VM Instances

  1. Enter the instance details.

  2. Create a new boot disk from the snapshot of the old boot disk.

a. Under Boot disk , select Change .

b. Select Snapshots .

c. Select the snapshot of the old boot disk from the Snapshot drop-down list.

d. Select the Boot disk type .

e. Enter the new size for the disk.

f. Click Select to confirm your disk options.

  1. Click Create .

  2. Mount and format the disk.

Another option is attach the disk to a VM: Formatting and mounting a zonal persistent disk

Also I recommended you to do a snapshot or a clone of your disk to avoid the risk of losing the data.

to do this go to disks

Google Cloud -> Compute Engine ->Disks

select your disk and then in the actions toolbar select the option Create Snapshot or Clone disk to do this.

If you only need to resize your disk you can do it in this part: Resizing a zonal persistent disk

go to your disks page

Google Cloud -> Compute Engine ->Disks

  1. Click on your disk name

  2. Click on the edit button

  3. in Properties you can change the size of your disk

  4. Click on Save button

Then you need to restart your VM and your changes there will be applied

Edit 03082021

found this, to access via serial console: Interacting with the serial console

Edit 03092021

for add or remove the SSH keys you need to follow this next steps: Adding or removing project-wide public SSH keys

To add or remove project-wide public SSH keys from the Cloud Console:

  1. In the Google Cloud Console, go to the metadata page for your project. Go to the Metadata page

  2. Under SSH Keys , click Edit .

  3. Modify the project-wide public SSH keys:

To add a public SSH key, click Add item . A text box opens.

Copy and paste the contents of your public SSH key file into the text box.

Repeat this process for each public SSH key that you want to add.

To remove a public SSH key, click the removal button next to it: 替代文字

Repeat this process for each public SSH key that you want to remove.

  1. When you have finished editing the SSH keys, click Save .

and here you create a new SSH key Creating a new SSH key

Open a terminal on your workstation

run this command:

ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]

Replace the following:

[KEY_FILENAME] : the name that you want to use for your SSH key files. For example, a filename of my-ssh-key generates a private key file named my-ssh-key and a public key file named my-ssh

[USERNAME] : the name of the user connecting to the VM. For example, youremail@gmail.com

here is an example:

ssh-keygen -t rsa -f ~/.ssh/my-new-ssh-key -C myficticialmail@gmail.com

The next is choose a passphrase that you remember and confirm the passphrase

  1. Restrict access to your private key so that only you can read it and nobody can write to it

    chmod 400 ~/.ssh/[KEY_FILENAME]

where [KEY_FILENAME] is the name that you used for your SSH key files.

Repeat this process for every user who needs a new key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM