35

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?

  • uname -a should give you the information about the Kernel, build time, and some other info, including vendor... (courtesy of Tiernan0) – soandos May 31 '11 at 20:00
33

For distro info:

cat /etc/issue

For Kernel/architecture (as mentioned previously):

uname -a
| improve this answer | |
  • cat /etc/issue worked. – David Jun 2 '11 at 15:15
  • 1
    Well, 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 Jul 14 '17 at 22:06
  • @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 May 8 '19 at 20:45
  • @ThorSummoner - the contents of /etc/issue are displayed before the login prompt. That's the security issue. – dannysauer May 11 '19 at 22:42
13

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.

| improve this answer | |
  • 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 May 31 '11 at 21:42
  • 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 May 31 '11 at 22:17
  • 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 Jun 2 '11 at 15:15
  • 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 - forums.aws.amazon.com/message.jspa?messageID=519816 – keen Jan 18 '18 at 23:28
  • 1
    I 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 Feb 8 '18 at 4:24
8

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/"
| improve this answer | |
  • 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 Apr 3 '15 at 20:34
2

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

| improve this answer | |
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
| improve this answer | |
  • This worked for me in Amazon Linux AMI 2011.09. – Mauvis Ledford Apr 3 '15 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.