Stop a script from running if it’s not root

This is a very short post and relies on the knowledge that UID of root user is always 0 regardless of the name of the root account. If the effective UID returned by id -u is not zero, the user is not executing the script with root privileges. Below simple code can be used to check against if script is running as root or not:

#!/bin/sh

if [ "$(id -u)" -ne 0 ]; then
        echo 'This script must be run by root user' > &2
        exit 1
fi

 

Become root user on Linux servers in Azure

root is the user name or account that by default has access to all commands and files on a Linux or other Unix-like operating system. It is also referred to as the root account, root user and the superuser. The root account is the most privileged on the system and has absolute power over it (i.e., complete access to all files and commands). Among root’s powers are the ability to modify the system in any way desired and to grant and revoke access permissions (i.e., the ability to read, modify and execute specific files and directories) for other users, including any of those that are by default reserved for root.

It is therefore, many times, you need to login as root in order to perform certain administrative actions. Continue reading “Become root user on Linux servers in Azure”

List of most used linux commands for various purposes

I have found some time to sit together and make a list of most used linux commands by me on a personal basis. I’m sharing the same over here (this in no way intends to be a complete list or reference list, so please don’t feel offensive). I hope you can find the same useful:

System Information

dmesg (boot message)
dmesg | less (view line by line)

sudo lshw (complete hardware info about computer!)
uname -a (server info)
cat /etc/*release (OS)
df -hT (mounted file systems)
mount -l (lists all mounted filesystems)
env | sort (environmental variables) Continue reading “List of most used linux commands for various purposes”