How to launch an instance in different cloud providers and perform the SCP command

How to launch an instance in different cloud providers and perform the SCP command

Today, we will be creating a virtual machine in the different cloud providers like AWS, Google Cloud Provider (GCP), and Microsoft Azure. After creating the virtual machine we will connect to each machine via SSH protocol and we will try a demo of copying the sample file from our local machine to each VM using SCP protocol.

SSH syntax:

ssh -i private_key user@ip

SCP syntax:

scp -i private_key file_name user@ip:destination_directory

AWS: EC2 Instance

From the services choose EC2 or search for EC2 in the search bar and click the EC2 service and click on "Launch Instance".

sample details while creating the ec2 instance:

Name: ubuntuinstance

AMI: ubuntu (free tier eligible)

instance type: t2.micro (free tier eligible)

key pair: create a new key pair and download it

Remaining all keep as it is(Default). and click launch instance and view it.

Our ec2 instance is launched.

Let's connect to this ec2 instance from the local machine using the SSH command.

We are successfully connected to the ec2 instance created in the AWS cloud.

Copy a file from the Local machine to the EC2 instance

Now let's verify in the remote ec2 instance whether the file is copied or not.

We copied notes.txt from the local machine to the ec2 instance successfully.

Copy a file from the remote VM to the Local machine

command: scp -i ~/Downloads/abc.pem ubuntu@13.127.142.222:~/awsinstance.txt /home/subash/Downloads/

Hence copied successfully.

GCP: Virtual machine

Once you are logged into your Google Cloud platform. Click on the navigation menu at the top left corner or search on the search bar for "compute engine" From There you choose VM instances and click on create instance.

After this click on the Create VM instance and fill in the details as follows:

We can see our VM is successfully launched.

Let's connect to it via SSH command.

gcloud auth login #to get access to the gcp 
gcloud config set project project_id/name 
gcloud compute ssh instance_name --zone your_zone

Finally, we are inside the VM as our hostname changed from subash07 to instance-4 which is our VM's name.

Copy a file from the Local machine to the Remote VM

Here we have copied a file notes.txt from our local machine to the GCP instance successfully.

Copy a file from the Remote VM to the Local machine

We copied a file named gcpinstace.txt from the GCP instance to our local machine.

Microsoft Azure: create a virtual machine

Sign in with your Azure account credentials. Once logged in to the Azure portal we can see the following interface and click on create resource to create the instance.

After clicking on Create a virtual machine, the following interface is opened enter the details as required and create the virtual machine.

Hence our virtual machine is successfully created as below:

Let's connect to our virtual machine from our local machine via SSH command.

We are successfully connected to our Azure virtual machine.

Copy a file from the Local Machine to the remote VM

command:
scp -i ~/Downloads/testVm_key.pem /home/subash/Downloads/notes.txt azureuser@20.40.56.201:~

We copied a file named notes.txt to the virtual machine.

Let's verify it in the VM.

Copy a file from the remote AzureVM to the Local machine

command performed: scp -i ~/Downloads/testVm_key.pem azureuser@20.40.56.201:~/azureinstance.txt /home/subash/Downloads/

Here we can see our azureinstance.txt file locally in the Downloads folder.

Hence, in this blog, we did the following:

  1. Creating a virtual machine in different clouds providers: AWS, GCP, AZURE

  2. Connected to all the virtual machines via SSH command

  3. Copied a file to and from the virtual machine using SCP command

Happy Learning !!