Google Cloud - accessing Linux VM via private key












1














I have created a linux VM in Google cloud, and right now I am trying to access the VM through SSH.



I can easily SSH to the server, if I am loged-in to the console via the interface, However I am trying to generate a private key file (pem) which I can use it to remote to the server from anywhere?



I can achieve this easily on AWS, or Azure during the VM creation, but this doesn't seem to be the case on GC.










share|improve this question




















  • 1




    If you have used the CLI gcloud compute ssh you will find your VM ssh keys in your home directory .ssh in the file google_compute_engine (private key) and google_compute_engine.pub (public key).
    – John Hanley
    Nov 19 '18 at 19:38


















1














I have created a linux VM in Google cloud, and right now I am trying to access the VM through SSH.



I can easily SSH to the server, if I am loged-in to the console via the interface, However I am trying to generate a private key file (pem) which I can use it to remote to the server from anywhere?



I can achieve this easily on AWS, or Azure during the VM creation, but this doesn't seem to be the case on GC.










share|improve this question




















  • 1




    If you have used the CLI gcloud compute ssh you will find your VM ssh keys in your home directory .ssh in the file google_compute_engine (private key) and google_compute_engine.pub (public key).
    – John Hanley
    Nov 19 '18 at 19:38
















1












1








1







I have created a linux VM in Google cloud, and right now I am trying to access the VM through SSH.



I can easily SSH to the server, if I am loged-in to the console via the interface, However I am trying to generate a private key file (pem) which I can use it to remote to the server from anywhere?



I can achieve this easily on AWS, or Azure during the VM creation, but this doesn't seem to be the case on GC.










share|improve this question















I have created a linux VM in Google cloud, and right now I am trying to access the VM through SSH.



I can easily SSH to the server, if I am loged-in to the console via the interface, However I am trying to generate a private key file (pem) which I can use it to remote to the server from anywhere?



I can achieve this easily on AWS, or Azure during the VM creation, but this doesn't seem to be the case on GC.







google-cloud-platform google-compute-engine ssh-keys






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 2:22









Adebisi

424




424










asked Nov 19 '18 at 16:49









Benjamin

62211027




62211027








  • 1




    If you have used the CLI gcloud compute ssh you will find your VM ssh keys in your home directory .ssh in the file google_compute_engine (private key) and google_compute_engine.pub (public key).
    – John Hanley
    Nov 19 '18 at 19:38
















  • 1




    If you have used the CLI gcloud compute ssh you will find your VM ssh keys in your home directory .ssh in the file google_compute_engine (private key) and google_compute_engine.pub (public key).
    – John Hanley
    Nov 19 '18 at 19:38










1




1




If you have used the CLI gcloud compute ssh you will find your VM ssh keys in your home directory .ssh in the file google_compute_engine (private key) and google_compute_engine.pub (public key).
– John Hanley
Nov 19 '18 at 19:38






If you have used the CLI gcloud compute ssh you will find your VM ssh keys in your home directory .ssh in the file google_compute_engine (private key) and google_compute_engine.pub (public key).
– John Hanley
Nov 19 '18 at 19:38














4 Answers
4






active

oldest

votes


















1














I understand what you mean, but google do it in a bit more automatically.



In any local computer, first get a service-account json with right access.



Authorized the gcloud by,



gcloud auth activate-service-account --key-file=KEY_FILE.json


Then,



gcloud compute config-ssh [--ssh-config-file=SSH_CONFIG_FILE] [--ssh-key-file=SSH_KEY_FILE]


You may already have ssh file, but that's fine if you simply let gcloud to generate it.



Finally you can ssh into any compute engine from this computer by,



gcloud compute ssh [USER@]INSTANCE


While, for next time in the same computer, you just need to use gcloud compute ssh to access it again.






share|improve this answer





















  • Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
    – Benjamin
    Nov 22 '18 at 7:18










  • No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
    – MatrixTai
    Nov 22 '18 at 7:33



















1














Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.



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



where:
[KEY_FILENAME] is 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-key.pub.



[USERNAME] is the user for whom you will apply this SSH key.



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.



If you created a key on a Linux workstation by using the ssh-keygen tool, the keys are saved under the following locations:



Public key file: ~/.ssh/[KEY_FILENAME].pub



Private key file: ~/.ssh/[KEY_FILENAME]



where [KEY_FILENAME] is the filename of the SSH key, which was set when the key was created.



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



In the Google Cloud Platform Console, go to the metadata page for your project. It can be found under the GCE menu.



Under SSH Keys, click Edit.



Modify the project-wide public SSH keys: To add a public SSH key, click Add item at the bottom of the page. This will produce a text box. Copy the contents of your public SSH key file and paste them into the text box. Repeat this process for each public SSH key that you want to add.



When you are done, click Save at the bottom of the page.



To connect to an instance using ssh



In a terminal, use the ssh command and your private SSH key file to connect to your instance. Specify your username and the external IP address of the instance that you want to connect to.



ssh -i [PATH_TO_PRIVATE_KEY] [USERNAME]@[EXTERNAL_IP_ADDRESS]



where:
[PATH_TO_PRIVATE_KEY] is the path to your private SSH key file.



[USERNAME] is the name of the user connecting to the instance. The username for your public SSH key was specified when the SSH key was created. You can connect to the instance as that user if the instance has a valid public SSH key for that user and if you have the matching private SSH key.



[EXTERNAL_IP_ADDRESS] is the external IP address for your instance.
If the connection is successful, you can use the terminal to run commands on your instance. When you are done, use the exit command to disconnect from the instance.






share|improve this answer































    0














    For SSH access, you wouldn't use a pem key. On your client machine, you should run (if in a unix/linux system) ssh-keygen which will walk you through creating your ssh key (default is RSA). You then need to add the public key (~/.ssh/id_rsa.pub or the file specified during creation) to ~/.ssh/authorized_keys on the server.






    share|improve this answer





























      0














      This is not how gcloud works.



      Google Cloud Platform actually takes public key beforehand when you create VM instance in compute service. You can generate the key on your machine by using ssh-keygen and add it by following methods to your instance.



      You have 2 options. Either you can add the ssh key instance-wide(screenshot 1) by editing your instance setting or you add ssh key project wise in the meta data section of compute service(screenshot 2).



      Screenshot1



      Screenshot 1



      Screenshot 2



      Screenshot 2






      share|improve this answer





















      • if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
        – Benjamin
        Nov 19 '18 at 18:11










      • @Benjamin you can carry same pem file to any other machine from where you wanted to login.
        – Mohit Kumar
        Nov 20 '18 at 4:44











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379244%2fgoogle-cloud-accessing-linux-vm-via-private-key%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I understand what you mean, but google do it in a bit more automatically.



      In any local computer, first get a service-account json with right access.



      Authorized the gcloud by,



      gcloud auth activate-service-account --key-file=KEY_FILE.json


      Then,



      gcloud compute config-ssh [--ssh-config-file=SSH_CONFIG_FILE] [--ssh-key-file=SSH_KEY_FILE]


      You may already have ssh file, but that's fine if you simply let gcloud to generate it.



      Finally you can ssh into any compute engine from this computer by,



      gcloud compute ssh [USER@]INSTANCE


      While, for next time in the same computer, you just need to use gcloud compute ssh to access it again.






      share|improve this answer





















      • Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
        – Benjamin
        Nov 22 '18 at 7:18










      • No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
        – MatrixTai
        Nov 22 '18 at 7:33
















      1














      I understand what you mean, but google do it in a bit more automatically.



      In any local computer, first get a service-account json with right access.



      Authorized the gcloud by,



      gcloud auth activate-service-account --key-file=KEY_FILE.json


      Then,



      gcloud compute config-ssh [--ssh-config-file=SSH_CONFIG_FILE] [--ssh-key-file=SSH_KEY_FILE]


      You may already have ssh file, but that's fine if you simply let gcloud to generate it.



      Finally you can ssh into any compute engine from this computer by,



      gcloud compute ssh [USER@]INSTANCE


      While, for next time in the same computer, you just need to use gcloud compute ssh to access it again.






      share|improve this answer





















      • Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
        – Benjamin
        Nov 22 '18 at 7:18










      • No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
        – MatrixTai
        Nov 22 '18 at 7:33














      1












      1








      1






      I understand what you mean, but google do it in a bit more automatically.



      In any local computer, first get a service-account json with right access.



      Authorized the gcloud by,



      gcloud auth activate-service-account --key-file=KEY_FILE.json


      Then,



      gcloud compute config-ssh [--ssh-config-file=SSH_CONFIG_FILE] [--ssh-key-file=SSH_KEY_FILE]


      You may already have ssh file, but that's fine if you simply let gcloud to generate it.



      Finally you can ssh into any compute engine from this computer by,



      gcloud compute ssh [USER@]INSTANCE


      While, for next time in the same computer, you just need to use gcloud compute ssh to access it again.






      share|improve this answer












      I understand what you mean, but google do it in a bit more automatically.



      In any local computer, first get a service-account json with right access.



      Authorized the gcloud by,



      gcloud auth activate-service-account --key-file=KEY_FILE.json


      Then,



      gcloud compute config-ssh [--ssh-config-file=SSH_CONFIG_FILE] [--ssh-key-file=SSH_KEY_FILE]


      You may already have ssh file, but that's fine if you simply let gcloud to generate it.



      Finally you can ssh into any compute engine from this computer by,



      gcloud compute ssh [USER@]INSTANCE


      While, for next time in the same computer, you just need to use gcloud compute ssh to access it again.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 22 '18 at 2:42









      MatrixTai

      1,926421




      1,926421












      • Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
        – Benjamin
        Nov 22 '18 at 7:18










      • No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
        – MatrixTai
        Nov 22 '18 at 7:33


















      • Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
        – Benjamin
        Nov 22 '18 at 7:18










      • No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
        – MatrixTai
        Nov 22 '18 at 7:33
















      Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
      – Benjamin
      Nov 22 '18 at 7:18




      Therefore, in any computer that I use to SSH to the VM, I must per-installed gcloud CLI. is that a fair statement?
      – Benjamin
      Nov 22 '18 at 7:18












      No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
      – MatrixTai
      Nov 22 '18 at 7:33




      No, I think you can still use the valid ssh-key generated by google for your own ssh, although I didn't tried. Once you run gcloud compute config-ssh (actually just ssh key-gen, but do one more to help you record the ssh key on the GCP metadata), the ssh-key will locate on User/.ssh/google_compute_engine, you can use it anywhere.
      – MatrixTai
      Nov 22 '18 at 7:33













      1














      Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.



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



      where:
      [KEY_FILENAME] is 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-key.pub.



      [USERNAME] is the user for whom you will apply this SSH key.



      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.



      If you created a key on a Linux workstation by using the ssh-keygen tool, the keys are saved under the following locations:



      Public key file: ~/.ssh/[KEY_FILENAME].pub



      Private key file: ~/.ssh/[KEY_FILENAME]



      where [KEY_FILENAME] is the filename of the SSH key, which was set when the key was created.



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



      In the Google Cloud Platform Console, go to the metadata page for your project. It can be found under the GCE menu.



      Under SSH Keys, click Edit.



      Modify the project-wide public SSH keys: To add a public SSH key, click Add item at the bottom of the page. This will produce a text box. Copy the contents of your public SSH key file and paste them into the text box. Repeat this process for each public SSH key that you want to add.



      When you are done, click Save at the bottom of the page.



      To connect to an instance using ssh



      In a terminal, use the ssh command and your private SSH key file to connect to your instance. Specify your username and the external IP address of the instance that you want to connect to.



      ssh -i [PATH_TO_PRIVATE_KEY] [USERNAME]@[EXTERNAL_IP_ADDRESS]



      where:
      [PATH_TO_PRIVATE_KEY] is the path to your private SSH key file.



      [USERNAME] is the name of the user connecting to the instance. The username for your public SSH key was specified when the SSH key was created. You can connect to the instance as that user if the instance has a valid public SSH key for that user and if you have the matching private SSH key.



      [EXTERNAL_IP_ADDRESS] is the external IP address for your instance.
      If the connection is successful, you can use the terminal to run commands on your instance. When you are done, use the exit command to disconnect from the instance.






      share|improve this answer




























        1














        Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.



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



        where:
        [KEY_FILENAME] is 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-key.pub.



        [USERNAME] is the user for whom you will apply this SSH key.



        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.



        If you created a key on a Linux workstation by using the ssh-keygen tool, the keys are saved under the following locations:



        Public key file: ~/.ssh/[KEY_FILENAME].pub



        Private key file: ~/.ssh/[KEY_FILENAME]



        where [KEY_FILENAME] is the filename of the SSH key, which was set when the key was created.



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



        In the Google Cloud Platform Console, go to the metadata page for your project. It can be found under the GCE menu.



        Under SSH Keys, click Edit.



        Modify the project-wide public SSH keys: To add a public SSH key, click Add item at the bottom of the page. This will produce a text box. Copy the contents of your public SSH key file and paste them into the text box. Repeat this process for each public SSH key that you want to add.



        When you are done, click Save at the bottom of the page.



        To connect to an instance using ssh



        In a terminal, use the ssh command and your private SSH key file to connect to your instance. Specify your username and the external IP address of the instance that you want to connect to.



        ssh -i [PATH_TO_PRIVATE_KEY] [USERNAME]@[EXTERNAL_IP_ADDRESS]



        where:
        [PATH_TO_PRIVATE_KEY] is the path to your private SSH key file.



        [USERNAME] is the name of the user connecting to the instance. The username for your public SSH key was specified when the SSH key was created. You can connect to the instance as that user if the instance has a valid public SSH key for that user and if you have the matching private SSH key.



        [EXTERNAL_IP_ADDRESS] is the external IP address for your instance.
        If the connection is successful, you can use the terminal to run commands on your instance. When you are done, use the exit command to disconnect from the instance.






        share|improve this answer


























          1












          1








          1






          Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.



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



          where:
          [KEY_FILENAME] is 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-key.pub.



          [USERNAME] is the user for whom you will apply this SSH key.



          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.



          If you created a key on a Linux workstation by using the ssh-keygen tool, the keys are saved under the following locations:



          Public key file: ~/.ssh/[KEY_FILENAME].pub



          Private key file: ~/.ssh/[KEY_FILENAME]



          where [KEY_FILENAME] is the filename of the SSH key, which was set when the key was created.



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



          In the Google Cloud Platform Console, go to the metadata page for your project. It can be found under the GCE menu.



          Under SSH Keys, click Edit.



          Modify the project-wide public SSH keys: To add a public SSH key, click Add item at the bottom of the page. This will produce a text box. Copy the contents of your public SSH key file and paste them into the text box. Repeat this process for each public SSH key that you want to add.



          When you are done, click Save at the bottom of the page.



          To connect to an instance using ssh



          In a terminal, use the ssh command and your private SSH key file to connect to your instance. Specify your username and the external IP address of the instance that you want to connect to.



          ssh -i [PATH_TO_PRIVATE_KEY] [USERNAME]@[EXTERNAL_IP_ADDRESS]



          where:
          [PATH_TO_PRIVATE_KEY] is the path to your private SSH key file.



          [USERNAME] is the name of the user connecting to the instance. The username for your public SSH key was specified when the SSH key was created. You can connect to the instance as that user if the instance has a valid public SSH key for that user and if you have the matching private SSH key.



          [EXTERNAL_IP_ADDRESS] is the external IP address for your instance.
          If the connection is successful, you can use the terminal to run commands on your instance. When you are done, use the exit command to disconnect from the instance.






          share|improve this answer














          Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.



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



          where:
          [KEY_FILENAME] is 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-key.pub.



          [USERNAME] is the user for whom you will apply this SSH key.



          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.



          If you created a key on a Linux workstation by using the ssh-keygen tool, the keys are saved under the following locations:



          Public key file: ~/.ssh/[KEY_FILENAME].pub



          Private key file: ~/.ssh/[KEY_FILENAME]



          where [KEY_FILENAME] is the filename of the SSH key, which was set when the key was created.



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



          In the Google Cloud Platform Console, go to the metadata page for your project. It can be found under the GCE menu.



          Under SSH Keys, click Edit.



          Modify the project-wide public SSH keys: To add a public SSH key, click Add item at the bottom of the page. This will produce a text box. Copy the contents of your public SSH key file and paste them into the text box. Repeat this process for each public SSH key that you want to add.



          When you are done, click Save at the bottom of the page.



          To connect to an instance using ssh



          In a terminal, use the ssh command and your private SSH key file to connect to your instance. Specify your username and the external IP address of the instance that you want to connect to.



          ssh -i [PATH_TO_PRIVATE_KEY] [USERNAME]@[EXTERNAL_IP_ADDRESS]



          where:
          [PATH_TO_PRIVATE_KEY] is the path to your private SSH key file.



          [USERNAME] is the name of the user connecting to the instance. The username for your public SSH key was specified when the SSH key was created. You can connect to the instance as that user if the instance has a valid public SSH key for that user and if you have the matching private SSH key.



          [EXTERNAL_IP_ADDRESS] is the external IP address for your instance.
          If the connection is successful, you can use the terminal to run commands on your instance. When you are done, use the exit command to disconnect from the instance.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 21:56









          MyStackRunnethOver

          762518




          762518










          answered Nov 21 '18 at 20:13









          Adebisi

          424




          424























              0














              For SSH access, you wouldn't use a pem key. On your client machine, you should run (if in a unix/linux system) ssh-keygen which will walk you through creating your ssh key (default is RSA). You then need to add the public key (~/.ssh/id_rsa.pub or the file specified during creation) to ~/.ssh/authorized_keys on the server.






              share|improve this answer


























                0














                For SSH access, you wouldn't use a pem key. On your client machine, you should run (if in a unix/linux system) ssh-keygen which will walk you through creating your ssh key (default is RSA). You then need to add the public key (~/.ssh/id_rsa.pub or the file specified during creation) to ~/.ssh/authorized_keys on the server.






                share|improve this answer
























                  0












                  0








                  0






                  For SSH access, you wouldn't use a pem key. On your client machine, you should run (if in a unix/linux system) ssh-keygen which will walk you through creating your ssh key (default is RSA). You then need to add the public key (~/.ssh/id_rsa.pub or the file specified during creation) to ~/.ssh/authorized_keys on the server.






                  share|improve this answer












                  For SSH access, you wouldn't use a pem key. On your client machine, you should run (if in a unix/linux system) ssh-keygen which will walk you through creating your ssh key (default is RSA). You then need to add the public key (~/.ssh/id_rsa.pub or the file specified during creation) to ~/.ssh/authorized_keys on the server.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 16:52









                  jamie schnaitter

                  846




                  846























                      0














                      This is not how gcloud works.



                      Google Cloud Platform actually takes public key beforehand when you create VM instance in compute service. You can generate the key on your machine by using ssh-keygen and add it by following methods to your instance.



                      You have 2 options. Either you can add the ssh key instance-wide(screenshot 1) by editing your instance setting or you add ssh key project wise in the meta data section of compute service(screenshot 2).



                      Screenshot1



                      Screenshot 1



                      Screenshot 2



                      Screenshot 2






                      share|improve this answer





















                      • if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
                        – Benjamin
                        Nov 19 '18 at 18:11










                      • @Benjamin you can carry same pem file to any other machine from where you wanted to login.
                        – Mohit Kumar
                        Nov 20 '18 at 4:44
















                      0














                      This is not how gcloud works.



                      Google Cloud Platform actually takes public key beforehand when you create VM instance in compute service. You can generate the key on your machine by using ssh-keygen and add it by following methods to your instance.



                      You have 2 options. Either you can add the ssh key instance-wide(screenshot 1) by editing your instance setting or you add ssh key project wise in the meta data section of compute service(screenshot 2).



                      Screenshot1



                      Screenshot 1



                      Screenshot 2



                      Screenshot 2






                      share|improve this answer





















                      • if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
                        – Benjamin
                        Nov 19 '18 at 18:11










                      • @Benjamin you can carry same pem file to any other machine from where you wanted to login.
                        – Mohit Kumar
                        Nov 20 '18 at 4:44














                      0












                      0








                      0






                      This is not how gcloud works.



                      Google Cloud Platform actually takes public key beforehand when you create VM instance in compute service. You can generate the key on your machine by using ssh-keygen and add it by following methods to your instance.



                      You have 2 options. Either you can add the ssh key instance-wide(screenshot 1) by editing your instance setting or you add ssh key project wise in the meta data section of compute service(screenshot 2).



                      Screenshot1



                      Screenshot 1



                      Screenshot 2



                      Screenshot 2






                      share|improve this answer












                      This is not how gcloud works.



                      Google Cloud Platform actually takes public key beforehand when you create VM instance in compute service. You can generate the key on your machine by using ssh-keygen and add it by following methods to your instance.



                      You have 2 options. Either you can add the ssh key instance-wide(screenshot 1) by editing your instance setting or you add ssh key project wise in the meta data section of compute service(screenshot 2).



                      Screenshot1



                      Screenshot 1



                      Screenshot 2



                      Screenshot 2







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 19 '18 at 17:53









                      Mohit Kumar

                      629521




                      629521












                      • if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
                        – Benjamin
                        Nov 19 '18 at 18:11










                      • @Benjamin you can carry same pem file to any other machine from where you wanted to login.
                        – Mohit Kumar
                        Nov 20 '18 at 4:44


















                      • if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
                        – Benjamin
                        Nov 19 '18 at 18:11










                      • @Benjamin you can carry same pem file to any other machine from where you wanted to login.
                        – Mohit Kumar
                        Nov 20 '18 at 4:44
















                      if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
                      – Benjamin
                      Nov 19 '18 at 18:11




                      if I generate the key on my machine, and add it to gcloud, I will be able to access from my own machine only.
                      – Benjamin
                      Nov 19 '18 at 18:11












                      @Benjamin you can carry same pem file to any other machine from where you wanted to login.
                      – Mohit Kumar
                      Nov 20 '18 at 4:44




                      @Benjamin you can carry same pem file to any other machine from where you wanted to login.
                      – Mohit Kumar
                      Nov 20 '18 at 4:44


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379244%2fgoogle-cloud-accessing-linux-vm-via-private-key%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith