How to get Amazon EC2 instance operating system info?

34

8

I just setup an EC2 instance running Linux. Is there a way to get the version/distribution of Linux that is running on the instance via the terminal?

David

Posted 2011-05-31T19:52:12.350

Reputation: 2 007

uname -a should give you the information about the Kernel, build time, and some other info, including vendor... (courtesy of Tiernan0) – soandos – 2011-05-31T20:00:31.960

Answers

32

For distro info:

cat /etc/issue

For Kernel/architecture (as mentioned previously):

uname -a

CJ Travis

Posted 2011-05-31T19:52:12.350

Reputation: 921

1Well, unless the sysadmin puts anything else in /etc/issue, as that is a locally managed file which is displayed prior to login and could literally be anything (or nothing). :) For example, my systems currently say "systems require authorization, unauthorized access is illegal" in there. Anyone who cares about security at all probably doesn't put all of the OS identifying information in /etc/issue. – dannysauer – 2017-07-14T22:06:24.160

@dannysauer where else would you put it. All information about anything is stored on the storage device. Sometimes I see this information embed in a binary executable that can print the information out, but that is little different in security measure than a plain text file, considering both any text file and any executable binary share the same filesystem based protections – ThorSummoner – 2019-05-08T20:45:33.083

@ThorSummoner - the contents of /etc/issue are displayed before the login prompt. That's the security issue. – dannysauer – 2019-05-11T22:42:58.027

cat /etc/issue worked. – David – 2011-06-02T15:15:40.070

12

The portable command for Linux Standard Base-compatible distributions (which is pretty much everything popular) is lsb_release. The distribution can be obtained by "-i" and the version comes from "-r". The "-s" option suppresses the name column and just shows the value, and -a shows everything lsb_release knows about the system. So, for example on a RHEL 5.5 system:

$ lsb_release -s -i
RedHatEnterpriseServer

$ lsb_release -s -r
5.5

$ lsb_release -a
LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Release:        5.5
Codename:       Tikanga

If you're on Red Hat, SuSE, Ubuntu, Debian, or anything else derived from those (Fedora, CentOS, whatever), this command will work. Otherwise, you'll have to figure out some distro-specific info. RedHat, for example again, installs a package named redhat-release and creates a file in /etc:

$ rpm -q redhat-release
redhat-release-5Server-5.5.0.2

$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

Here's what it looks like on a freshly-provisioned (Feb 2, 2017) Amazon Linux 2 system - after I reset the hostname:

[ec2-user@fresh-amazon-host ~]$ cat /etc/system-release
Amazon Linux release 2.0 (2017.12) LTS Release Candidate
[ec2-user@fresh-amazon-host ~]$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2.0 (2017.12)"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2.0"
PRETTY_NAME="Amazon Linux 2.0 (2017.12) LTS Release Candidate"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2.0"
HOME_URL="https://amazonlinux.com/"

IMHO, you really should use lsb_release if it's available. If you're just doing it visually, lsb_release -a is easy to remember and reasonably easy to read. But if that's not an option, /etc/os-release is populated as above on quite a few recent Linux OS versions.

dannysauer

Posted 2011-05-31T19:52:12.350

Reputation: 837

1

downvote since lsb_release isn't available on amazon linux, which generally leads to this question being asked... lsb_release requires a large dep chain that comes with redhat-lsb-core and aws chooses to leave that off - https://forums.aws.amazon.com/message.jspa?messageID=519816

– keen – 2018-01-18T23:28:53.997

1I made the rest of the answer more clear (which some people apparently weren't reading), and included the actual output from current Amazon Linux 2. – dannysauer – 2018-02-08T04:24:31.720

I your first approach and get the following error -bash: lsb_release: command not found. I also tried your second approach and can't find anything mentioning redhat in /etc. Any other suggestions? – David – 2011-05-31T21:42:04.047

Start by checking to see if rpm and apt-get are on the system; run "which rpm" and "which apt-get". If you have rpm, do an "rpm -qa | less" and see if there's anything there that sounds like a distribution. If you have apt-get, try "dpkg -l | less" and do the same thing. And try "ls -d /etc/rel" to see if there's any release file or anything in /etc. Oh, you might also do a "find / -name lsb_release" just in case lsb_release isn't in your path. – dannysauer – 2011-05-31T22:17:09.820

apt-get is not on the system. I don't see anything identifiable with rpm -qa|less. ls -d /etc/*rel* worked. I then nano /etc/system-release. In the file it tells me that the OS is Amazon Linux AMI release 2011.02.1.1. Thanks. – David – 2011-06-02T15:15:01.463

7

This worked for me:

# cat /etc/os-release

NAME="Amazon Linux AMI"
VERSION="2015.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2015.03"
PRETTY_NAME="Amazon Linux AMI 2015.03"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2015.03:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

Kevin Murray

Posted 2011-05-31T19:52:12.350

Reputation: 71

Just a heads up. I am running Amazon Linux AMI 2011.09 and this did not work but another comments cat /usr/share/doc/system-release/ReleaseNotes.txt did. This probably works on newer editions. – Mauvis Ledford – 2015-04-03T20:34:36.627

2

uname -a should give you the information about the Kernel, build time, and some other info, including vendor...

TiernanO

Posted 2011-05-31T19:52:12.350

Reputation: 678

1

As you can see when log into an AMI EC2 Amazon Linux AMI:

"See /usr/share/doc/system-release/ for latest release notes."

So... just type:

cat /usr/share/doc/system-release/ReleaseNotes.txt

frommelmak

Posted 2011-05-31T19:52:12.350

Reputation: 111

This worked for me in Amazon Linux AMI 2011.09. – Mauvis Ledford – 2015-04-03T20:34:50.813