≡ Menu

root user

Reset Urchin When Prompt For a New Serial Key

Sometime Urchin may prompt for a new serial key for already configured and working system. You can reset Urchin easily and get rid of this problem.

First, log onto the server via SSH and as root user.

Once logged in type the following two commands to reset it:
# cd /usr/local/urchin/util/
# ./uconf-driver action=set_parameter recnum=1 ct_serial=0
# ./uconf-driver action=set_parameter recnum=1 ct_license=0

If you are a proud owner of IBM / Lenovo laptop / desktop computer use vpddecode command to print the "vital product data" information without opening your case or rebooting the system. This information is hardcoded on almost all IBM and Lenovo computers BIOS. It will show following information:

=> BIOS Build ID
=> Box Serial Number
=> Motherboard Serial Number
=> Machine Type/Model
=> BIOS Release Date
=> Default Flash Image File Name

Command to display BIOS information

WARNING! These examples only works on IBM/Lenovo Computer or Laptop systems

Open terminal and type the following command as the root user:

$ sudo vpddecode
OR
# vpddecode

Sometime it is necessary to find out if a shell script is being run as root user or not.

When user account created a user ID is assigned to each user. BASH shell stores the user ID in $UID variable. Your effective user ID is stored in $EUID variable. You can

Old way...

You can easily add a simple check at the start of a script:

Check the script is being run by root user

#!/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# ...

New way: Using EUID

#!/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# ...

Mount /dev/sdb1 only if you are a root

#!/bin/bash
if [[ $EUID -ne 0 ]]; then
  echo "You must be a root user" 2>&1
  exit 1
else
  mount /dev/sdb1 /mnt/disk2
fi

Updated for accuracy and more examples.

Ubuntu Linux Restore admin / root level permissions

I was writing and testing few python scripts (yes I'm moving lot of stuff from shell / perl to python these days) and accidentally I renamed my own user account from vivek to test. However, I did not noticed change until I rebooted my box. Now I cannot run sudo (or become a root user) and cannot access special devices such as sound or video.

By default your first account has all power via sudo under Ubuntu Linux. There is a special group called adm and admin which grants unlimited power via sudo.

The only solution was to boot computer in emergency mode (reboot computer and at grub menu select recovery mode kernel), open /etc/group file and add user vivek to admin and adm group:
# vi /etc/group
Add user vivek to admin and adm group:
admin:x:117:vivek
adm:x:4:vivek

Save and close the file.

Now I'm able to run sudo and do other stuff. Luckily, my scripts always backup critical files before modification. So I was able to restore permission instantly. Here is my group membership with all power and glory ;)
$ id
$ groups

Output:

vivek adm dialout cdrom floppy audio dip video plugdev scanner netdev lpadmin powerdev admin

Windows XP has a small option called Run as command.. You can add similar option to Linux desktop to open or run file as root via a right click. The following tutorial explains how to add a context menu item that enables a Linux user to open files as the root user when browsing their file system using nautilus. This script feature allows the user to navigate their file system and open or edit any file or directory as the root user of the system. It's a perfect solution for those that are not completely comfortable using terminal commands.

=> How to open files as root via a right click

nixCraft FAQ Roundup April 27, 2007

Recently updated/posted Linux and UNIX FAQ (mostly useful to Linux/UNIX new administrators or users) :

Enjoy!

FreeBSD Reset or Recover Root Password

With FreeBSD version 5.4 and above the booting procedure is slightly changed. The older version of FreeBSD uses the boot -s option at Ok prompt. However, with FreeBSD version FreeBSD 5.4+ you don't have to type any commands. Here is the procedure to boot FreeBSD into a single user mode to reset root password.
[click to continue…]