How to find out AWS EC2 instances type over SSH

See all GNU/Linux related FAQ
AWS offers various instance types, and sometimes, you need to know which one you are using or which one has been deployed by someone else (another developer or sysadmin) for a project. Don’t worry. Here are some commands to find the EC2 instance type over SSH without logging into the AWS console. These commands works with any Linux distro or FreeBSD Unix systems.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements none|Linux or Unix terminal
Category System Management
OS compatibility AlmaLinux Alpine Amazon Linux Arch CentOS Debian Fedora FreeBSD Linux Mint Mint NetBSD OpenBSD openSUSE Pop!_OS RHEL Rocky Slackware Stream SUSE Ubuntu Unix
Est. reading time 2 minutes
Please note that these commands are meant for running EC2 or Lightsail Linux, FreeBSD, or Unix instances, and you must have SSH access. Some of the commands mentioned below will not work with all cloud providers or bare metal servers, except the dmidecode command, which works on every type of system.

Finding out aws EC2 instances type over ssh

  1. Log into your EC2 sever using the ssh:
    vivek@macbookair:$ ssh ec2-user@ec2-ip-here
  2. Simply type the combination of dmesg command and grep command to list instance type:
    $ sudo dmesg | grep -Ew 'DMI|Amazon|EC2'
    Outputs indicating that I'm using EC2 t3.micro instance:
    [ 0.000000] DMI: Amazon EC2 t3.micro/, BIOS 1.0 10/16/2017
  3. If above command failed, try to fetch the instance type from the instance metadata using the curl command and echo command as follows:
    $ echo "EC2 VM/instance type: $(curl -sq"
  4. There is also a file called /sys/devices/virtual/dmi/id/product_name on Linux. All you have to do is use the “bat,” “cat,” “less,” or “more commands“:
    $ more /sys/devices/virtual/dmi/id/product_name
    ## OR
    $ cat /sys/devices/virtual/dmi/id/product_name
  5. You can also check instance type using the dmidecode command on Linux or FreeBSD. You may need to install this command using your system’s package manager. This command provides lots of information like RAM, disk and other stuff. Just type:
    $ sudo dmidecode -s system-product-name
    Alternately, you can run the following bash for loop one-liner as follows:

    for d in system-manufacturer system-product-name bios-release-date bios-version
       echo "${d^} : " $(sudo dmidecode -s $d)

    Here is what it says:

    System-manufacturer :  Amazon EC2
    System-product-name :  t3.2xlarge
    Bios-release-date :  10/16/2017
    Bios-version :  1.0
  6. You can also use the ec2-metadata as follows:
    $ ec2-metadata | more
    $ ec2-metadata --instance-type
Finding EC2 instance type over SSH-based session on Linux or Unix or FreeBSD

Click to enlarge

Summing up

That is all. I hope all these commands help developers or sysadmins discover the EC2 instance type over an SSH-based session on a Linux/Unix or FreeBSD virtual machine. Also check out EC2 documentation for more info and manual pages install on your Linux, macOS or Unix desktop using the man command/help command for command featured in this quick tutorial:
$ man curl
$ man dmidecode
$ man dmesg
$ man grep

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.