怎样确认我的云服务器是CentOS还是Ubuntu系统?

要确认你的云服务器是 CentOS 还是 Ubuntu 系统,可以通过以下几种方法进行判断:


✅ 方法一:查看系统发行版本文件(推荐)

1. 查看 /etc/os-release 文件

这是最通用、最准确的方法:

cat /etc/os-release

输出示例:

  • Ubuntu

    NAME="Ubuntu"
    VERSION="20.04.6 LTS (Focal Fossa)"
    ID=ubuntu
    ID_LIKE=debian
    ...
  • CentOS

    NAME="CentOS Linux"
    VERSION="7 (Core)"
    ID="centos"
    ID_LIKE="rhel fedora"
    ...

根据 NAMEID 字段即可判断。


2. 查看 /etc/issue 文件

cat /etc/issue

输出可能类似:

  • Ubuntu: Ubuntu 20.04.6 LTS n l
  • CentOS: CentOS Linux release 7.9.2009 (Core)

3. 查看特定发行版文件

  • 检查是否存在 Ubuntu 特有的文件:

    ls /etc/lsb-release

    如果存在,通常是 Ubuntu 或 Debian 系。

  • 检查 CentOS/RHEL 特有的文件:

    cat /etc/redhat-release

    输出如:CentOS Linux release 7.9.2009 (Core) → 表明是 CentOS。

⚠️ 注意:新版本的 CentOS Stream 或某些最小化安装可能没有这个文件。


✅ 方法二:使用命令行工具

1. 使用 hostnamectl 命令(适用于现代系统)

hostnamectl

输出中会包含 Operating System 字段:

   Operating System: Ubuntu 20.04.6 LTS
             Kernel: Linux 5.4.0-150-generic

   Operating System: CentOS Linux 7 (Core)

2. 使用 lsb_release(主要在 Ubuntu 上可用)

lsb_release -a

如果命令存在,通常就是 Ubuntu/Debian 系统。CentOS 默认不安装此命令。


✅ 方法三:通过包管理器判断

不同系统使用的包管理器不同:

系统 包管理器 命令示例
Ubuntu APT apt --version
CentOS YUM 或 DNF yum --versiondnf --version

运行:

which yum || which dnf

如果有输出,可能是 CentOS/RHEL 系。

which apt

如果有输出,可能是 Ubuntu/Debian 系。


总结:快速判断脚本

你可以运行以下命令一键判断:

if [ -f /etc/os-release ]; then
    . /etc/os-release
    echo "系统是: $NAME ($VERSION_ID)"
else
    echo "无法识别系统"
fi

常见结论对照表

关键词 系统类型
Ubuntu Ubuntu
Debian Debian
CentOS CentOS
Red Hat RHEL/CentOS
ID=centos CentOS
ID=ubuntu Ubuntu

如果你能登录服务器并执行命令,上述任意方法都能快速帮你确认系统类型。建议优先使用 cat /etc/os-release

未经允许不得转载:云计算CLOUD » 怎样确认我的云服务器是CentOS还是Ubuntu系统?