https://pulumi.com logo
Title
b

billions-lawyer-5518

01/14/2022, 1:31 PM
Hi all, I have created a GCP - VM instance using pulumi, when I try to ssh into it using pulumi command package I am getting the following error. Can anyone help me with this ? Thank you!
error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
Code snippet:
import * as gcp from "@pulumi/gcp";
import { remote, types } from "@pulumi/command";
import { Config } from "@pulumi/pulumi";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";

const config = new Config();
const publicKey = config.get("publicKey");

const privateKeyBase64 = config.get("privateKeyBase64");

const privateKey = privateKeyBase64
  ? Buffer.from(privateKeyBase64, "base64").toString("ascii")
  : fs.readFileSync(path.join(os.homedir(), ".ssh", "id_rsa")).toString("utf8");

const svcAct = new gcp.serviceaccount.Account("my-service-account", {
  accountId: "service-account",
  displayName: "Service account for Pulumi",
});

const svcKey = new gcp.serviceaccount.Key("my-service-key", {
  serviceAccountId: svcAct.name,
  publicKeyType: "TYPE_X509_PEM_FILE",
});

const address = new gcp.compute.Address("my-address", {
  region: "us-central1",
});

// Create a Virtual Machine Instance
const computeInstance = new gcp.compute.Instance("instance", {
  machineType: "n2-standard-2",
  zone: "us-central1-a",
  bootDisk: {
    initializeParams: {
      image: "ubuntu-os-cloud/ubuntu-1804-lts",
      size: 20,
    },
  },
  networkInterfaces: [
    {
      network: "default",
      accessConfigs: [{ natIp: address.address }],
    },
  ],
  advancedMachineFeatures: { enableNestedVirtualization: true },
  serviceAccount: {
    scopes: ["<https://www.googleapis.com/auth/cloud-platform>"],
    email: svcAct.email,
  },
  metadata: {
    "enable-oslogin": "false",
    "ssh-keys": `user:${publicKey}`,
  },
});

const connection: types.input.remote.ConnectionArgs = {
  host: address.address,
  user: "user",
  privateKey: privateKey,
};

const copyFile = new remote.CopyFile("docker-install-file", {
  connection,
  localPath: "./deploy.sh",
  remotePath: "deploy.sh",
});

const execCommand = new remote.Command(
  "exec-docker-shell",
  {
    connection: connection,
    create: "sh deploy.sh",
  },
  { dependsOn: copyFile }
);

// Export the name and IP address of the Instance
export const instanceName = computeInstance.name;
b

billowy-army-68599

01/14/2022, 5:42 PM
i'm not familiar with gcp's ssh support, but are you using the correct user?
b

billions-lawyer-5518

01/16/2022, 2:16 PM
I got it resolved by using
gcp.oslogin.SshPublicKey
. Thank you!