Link Search Menu Expand Document

Get started with Ubuntu Image

Table of contents

Prerequisite

  1. You’ll need SSH key, read on How to generate SSH on Mac
  2. Knowing and change user permission, read on User & Permission

AWS - EC2

Create and run Ubuntu Image on AWS

After navigated to EC2 console on AWS. You will follow step by step how to create image.

Note for ssh client, by default you use ubuntu as a user when SSH into the VM.

Security Group

Inbound

  1. ssh tcp 22
  2. http tcp 80
  3. https tcp 443
  4. smtp tcp 25
  5. custom tcp 587 -> for SES (AWS Simple Email Service)
  6. custom tcp 8080 -> incase if applied multilayer caching

Outbound

  1. ssh tcp 22
  2. http tcp 80
  3. https tcp 443
  4. smtp tcp 25
  5. custom tcp 587 -> for SES (AWS Simple Email Service)

SSH login

  • Generate Key

    1. Generated .pem on Amazon
    2. Download key.pem file to local PC folder

      default Mac user do: mv ~/Download/key.pem ~/.ssh/

    3. cd ~/.ssh
    4. chmod 400 key.pem
  • SSH into the VM

ssh -i ~/.ssh/key.pem ubuntu@192.25.25.0
  • Change to root as default login

    1. Using ssh into VM as ubuntu
    2. Run: vim ~/.ssh/authorized_keys
    3. Copy the authorized_keys information
    4. Change to root by running sudo -i
    5. Run: vim ~/.ssh/authorized_keys will create a new file under the root profile
    6. Paste the content of authorized_keys, then save.
    7. Exit the VM
    8. Run `ssh -i ~/.ssh/key.pem root@192.25.25.0

Digital Ocean - Droplet

  • Enabling Networking firewall

Inbound

  1. ssh tcp 22
  2. http tcp 80
  3. https tcp 443
  4. custom tcp 8080 -> incase if applied multilayer caching

Outbound

  1. ssh tcp 22
  2. http tcp 80
  3. https tcp 443
  4. dns udp udp 53 -> important to run update/upgrade in the VM

SSH login

ssh root@165.232.38.131
  • Firs time login, you will be seeing this:

    The authenticity of host ‘192.25.25.0’ can’t be established. ECDSA key fingerprint is SHA256:strings. Are you sure you want to continue connecting (yes/no/[fingerprint])?

Add public SSH key

  • Digital Ocean Dashboard » Profile » Security » Add SSH

System maintenance

top
  # to check memory usage, shift + m to sort highest usage first 
ps aux | awk '{print $6/1024 " MB\t\t" $11}' | sort -n
  # see processes memory in MB
apt-get install atop 
  # install system monitor

Rebuild Droplet

  1. Dashboard > rebuild
  2. Remove existing SSH key from local PC: ssh-keygen -R 192.25.25.0

Google Cloud Platform (GCP) - VM

Google requires gcloud command to generate keys which requires account authentications.

SSH login

ssh -i ~/.ssh/google_compute_engine root@192.25.25.0
  # ssh -i [path-to-key] [user]@[external-ip]

Get IP

curl ifconfig.me
  # outputs: 192.25.25.0 (external)
hostname -I
  # outputs: 10.146.0.3 (internal)

Install Cloud SDK command and gCloud

  1. Run curl https://sdk.cloud.google.com | bash
  2. Start the programme: exec -l $SHELL
  3. New VM setup SSH => gcloud init

Add gCloud SSH to VM for the first time

  1. Login to Google Cloud Platform console » VM instances » SSH » View GCP Command
  2. Copy and paste the command to terminal and enter
  3. First time will require authenticate with Google Account » Go Authenticate
  4. After Authenticated, gCloud to generate key
  5. Key is saved under /home/user/.ssh/, the pair of .google_compute_engine and .google_compute_engine.pub

Config gcloud command

sudo gcloud compute config-ssh 
  # without sudo not permitted