---
title: "Check for Root User"
description: "Checking for root privileges across different languages. Practical notes and code examples on Check for Root User by Hemanth."
url: "https://h3manth.com/scribe/check-for-root-user/"
canonical_url: "https://h3manth.com/scribe/check-for-root-user/"
markdown_url: "https://h3manth.com/scribe/blog/check-for-root-user.md"
publishDate: "2014-06-14T00:00:00.000Z"
author: "Hemanth HM"
category: "cli"
tags: ["linux","cli"]
word_count: 67
reading_time_minutes: 1
x_markdown_tokens: 219
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Check for Root User

> Checking for root privileges across different languages. Practical notes and code examples on Check for Root User by Hemanth.

The superuser UID is always 0 (from [Linux source](https://github.com/torvalds/linux/)).

## Check by UID

**Bash:** `isRoot=$(($UID == 0))`

**Node.js:** `var isRoot = process.getuid && process.getuid() === 0;`

**Ruby:** `isRoot = Process.uid.zero?`

**Python:** `isRoot = os.geteuid() == 0`

**Haskell:** `let isRoot = fmap (== 0) getRealUserID`

## Check by Write Access

**Bash:** `[[ -w / ]] && isRoot=true || isRoot=false`

**Ruby:** `isRoot = File.writable_real?("/")`

**Python:** `isRoot = os.access('/', os.W_OK)`
