19

How do I determine which RedHat Linux version I am running?

Here's what I've read:

  • /etc/redhat-release file contains the version, but anybody can tamper with that file.
  • people say uname command, but you can install any kernel on Redhat.

If I am running redhat 5.1 and someone upgrade it with 5.2 or 5.x, what determines the version of RedHat?

even lsb_release -a read /etc/redhat-release file.

Satish
  • 16,544
  • 29
  • 93
  • 149
  • 11
    This isn't a tricky question. RedHat puts the version in `/etc/redhat-release`. If people tamper with that file, you're a bad sysadmin because in reality no one should be able to change that file except for root. – Chris Eberle Mar 01 '13 at 18:34
  • Why do you want to know what version of RedHat is running? What determines the version depends on why you want to know. (For example, if you want to know what it will report as its version, then you do want to look in `/etc/redhat-release`. If you want to know if it's running the latest kernel in its release stream, then you *do* want the kernel version.) – David Schwartz Mar 01 '13 at 18:37
  • 1
    Agreed, I am just trying to find out anyway.. and trying to clear all possibilities. – Satish Mar 01 '13 at 18:37
  • My security team asking this question, its not me. They want to confirm all possibility.. – Satish Mar 01 '13 at 18:40
  • 1
    Giving someone root access to a machine is like giving them keys to your house or something. Wouldn't you only give your house keys to those you trusted? Why can't you trust people to whom you've given root access with the contents of `/etc/redhat-release`? If you can't, then you also can't be sure that running `ls` won't run `rm -rf ~/*`. – ajp15243 Mar 01 '13 at 18:53
  • I got it what all you trying to say!! cheers! – Satish Mar 01 '13 at 19:09
  • all people are not good. sometime your colleague can mass with you and you can never catch them if he did with root account :( – Satish Mar 01 '13 at 19:12
  • If you're concerned about mischievous or even malicious colleagues, you should probably bring that up with your security team. They likely have logs of all logins and the login source, and what commands were run during said login. – ajp15243 Mar 01 '13 at 19:20

9 Answers9

21

Try this command:

rpm -qa | grep release

for instance on my machine I get this

redhat-release-workstation-6Workstation-6.4.0.4.el6.x86_64

Jay
  • 18,959
  • 11
  • 53
  • 72
Tim
  • 211
  • 2
  • 2
17

If "anybody" has root access to your machine to either change /etc/redhat-release or install an alternate kernel you're most probably in bigger trouble than determining the redhat version of your system.

Just use the value pointed out by /etc/redhat-release or even better in terms of portability use the output of lsb_release as this is exactly the purpose they were made for.

With "anybody" being able to do anything with your system there is no other chance at all.

mikyra
  • 10,077
  • 1
  • 40
  • 41
  • 1
    @Satish, the essence of this answer, and everyone else's comments, is that you *should* trust (or at least be able to trust) the `/etc/redhat-release` file contents and `lsb_release`. If you argue that those outputs are untrustworthy since "anybody can tamper with that file", then your entire system is untrustworthy because editing that file requires root access to the system (and if someone changed that file to be wrong, who's to say they didn't do something else bad?). Either you trust that it's right, or you need to rethink your system's security if you can't trust those with root access. – ajp15243 Mar 01 '13 at 19:05
  • @Satish: affarmitive but it will read /wherever/whatever_file or run /wherever/whatever_program an **any** LSB compliant system, that's what I meant by better "portability" – mikyra Mar 01 '13 at 19:05
  • Got it.. Guys! no root no tempering – Satish Mar 01 '13 at 19:10
5

You can use the lsb_release command on recent linux distributions. If you issue:

lsb_release -i -r

Or

uname -r

And map the output. 2.6.9 kernels are RHEL4, 2.6.18 kernels are RHEL5. If necessary, you can map the full version to the specific update releases from Red Hat (i.e. 2.6.9-89 is RHEL5 U4).

Nullpointer
  • 1,895
  • 20
  • 26
4

Note: since July 2012, /etc/os-release should be the standard file where to look for the version of any OS.

  • It relieves application developers who just want to know the distribution they are running on to check for a multitude of individual release files.
  • It provides both a "pretty" name (i.e. one to show to the user), and machine parsable version/OS identifiers (i.e. for use in build systems).
  • It is extensible, can easily learn new fields if needed.

See its man page.

Example for RedHat:

# cat /etc/os-release 
NAME="Red Hat Enterprise Linux Server"
VERSION="7.0 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="7.0"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.0 (Maipo)"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Unfortunately this doesn't seem to work with rhel 6.x, even not with the latest patches installed. This file does not exist for that release, and probably not for older ones. – ralhei Apr 18 '16 at 14:13
2

A trick working on numerous Linux distributions:

cat /etc/issue

Example on Red Hat 6:

$ cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m

$ 
YSC
  • 38,212
  • 9
  • 96
  • 149
andreiS
  • 19
  • 3
1

The most simple command is:

lsb_release -d
Oz Bar-Shalom
  • 1,747
  • 1
  • 18
  • 33
0

try

uname -r

or

cat /etc/issue

for recent linux machines

lsb_release -d
0

For folks who are reading this today, or in the future:
The kernel version that is RUNNING is your version of RedHat. There may be other versions installed, but not running.
Thus, if RedHat 5.1, 5.2 & 5.x are installed on the machine, only 1 can be running at a time. This is the version that was booted at system start uop.To determine which version is actually running, use the uname command:
uname -r
This returns the Kernel release number. For RedHat 5, it will be 2.6.18-[something]
RH 5.1 is 2.6.18-53
RH 5.2 is 2.6.18-92

To translate kernel release numbers into Redhat Version numbers, see this link:
Red Hat Enterprise Linux Release Dates

Scottie H
  • 324
  • 1
  • 7
0

The file /etc/redhat-release is standart way to get vendor version (including 5.X). I don't think you should ignore this way. Of course, you can use various tricks from other software to display the current version of OS, but anyway many of them are parsing the /etc files. As mentioned above you can use rpm query to get version. Another way to get such information: rpm -q <vendor-name>-release

BTW I agree with the commenters above that the way you knowing the version is the least of your problems if anyone can tamper with the standard /etc/redhat-release file or other system configuration files.

Additionally since RHEL 7.X versions you can also try hostnamectl | grep 'Operating System'