WEBサービス

Connect to GCP VM instance with ssh

Connect to GCP VM instance with ssh

After creating Google Cloud Compute Engine instance, we should know how to connect.
Where are user and password ?
Today I introduce how to connect to GCP VM instance with ssh or sftp.


What is Google Cloud Platform (GCP)

Google Cloud Platform is Google's cloud environment.
It is like AWS of Amazon.

It has a lot of functions like web server, database server, data warehouse for data analysis, job scheduler and container management function and so on.
We can use them through internet.
And a lot of people and companies use GCP.


Google Cloud Platform (GCP), offered by Google, is a suite of cloud computing services that runs on the same infrastructure that Google uses internally for its end-user products, such as Google Search and YouTube. Alongside a set of management tools, it provides a series of modular cloud services including computing, data storage, data analytics and machine learning. Registration requires a credit card or bank account details.


What is VM instance (Compute Engine) ?

VM instance is web server function in GCP.
It is also called Compute Engine.
It is virtual Linux server like EC2 of AWS.

In order to manage VM instance, we should know how to connect to VM instance from our local PC.


How to connect to VM instance

In order to connect to VM instance, following stepsare required.

  1. Generate Public-key and Secret-key
  2. Set Public-key to VM instance
  3. Connect to VM instance with using Secret-key


Public-key and Secret-key

Public-key and Secret-key are for security.
Public-key is public one that some users have.
And Secret-key is for limited users who want keep secret.

They are a pair of keys for encryption and decryption.
If data is encrypted by Public-key, only Secret-key owner can decrypt it.
And if data is encrypted by Secret-key, anyone can read it with Public-key. But only Secret-key owner can create same data.

So if we use Secret-key for decryption, it means keeping content secret. And if we use Secret-key for encryption, it means proving owner.

With using these keys, we can connect to VM instance.


Security certification

Public-key and Secret-key are used for test of IPA Security certification.
So it is good to remind these keys for the test.


Generate Public-key and Secret-key

In order to generate Public-key and Secret-key, you can run following command in your local machine.
(Any name is ok for "file name" and "user name".)
Then you will get (file name) and (file name).pub.

ssh-keygen -t rsa -N "" -b 2048 -C "(user name)" -f (file name)

It is Unix command. So in case of Windows, you can run it on WSL.


Set Public-key to VM instance

Next set Public-key to VM instance.
In this case, it is for proving user to connect VM instance. So client PC use Secret-key.

In order to set Public-key, firstly open GCP console and click VM instance from its menu.

VM instance
VM instance


Then if VM instance is already created, it shows list of instances. So click an instance that you want to set.

list of instances
list of instances


After opening VM instance settings, click Update/Modify to update its settings.

Detail of VM instance
Detail of VM instance


Scroll down 80%, the you can see the area of Public-key.
Then write the content of (file name).pub that we generated previously.
If you open it by text editor, it would show like "ssh-rsa AAAAB...". So copy it and paste it to Public-key area.

Public-key area
Public-key area

Save it.
Then it is finished to set Public-key.


Connect to VM instance with using Secret-key

Now we finished to set Public-key.
So next connect to VM instance with using Secret-key

We can use TeraTerm for ssh connection.

Once we start TeraTerm, it requires host information. So set International IP of VM instance and push OK to proceed.

SSH connection settings
SSH connection settings


Then it would require login information.
You can set the user name that you created when you generate keys with -C parameter.

And for certification choose RSA/DSA/ECDSA/ED25519 key and use (file name) file as Secret-key.

login information
login information

Then you can connect to VM instance with ssh.

In case of SFTP, you can use same user name and Secret-key.


Finally

In order to connect to GCP VM instance, create Public-key and Secret-key. And set Public-key to VM instance.
Then with using Secret-key, you can connect to VM instance.


コチラもオススメ

KRSW

駆け出し機械学習エンジニア。機械学習、DB、WEBと浅く広い感じ。 Junior machine learning engineer. Not a specialist but a generalist who knows DB, WEB too.

If you felt this article is useful, please share.

にほんブログ村 IT技術ブログへ

-WEBサービス
-, ,

Translate »

Copyright© ITips , 2020 All Rights Reserved.