Tag: root

Bash: Check if you are root

Using the following you can check if you are root or not when you run bash scripts.

Exmaple 1:

[php]
#!/bin/bash
if [ $(whoami) != 'root' ]; then
echo "Must be root to run $0"
exit 1;
fi
[/php]

Example 2:

[php]
#!/bin/bash
ROOT_UID=0 # Only users with $UID 0 have root privileges.
E_NOTROOT=87 # Non-root exit error.

if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script!"
exit $E_NOTROOT
fi
echo "You are root!"
[/php]

You can also use this in your bash scripts.


How to recover a forgotten root password

First, don’t panic! This is usually a simple matter so long as you have physical access to the console.

Simply follow the steps below to boot the system bypassing login, and then set a new password:

Step 1. Reboot the system. Make sure your physically present.

Step 2. When the Grub menu comes up, press “e” to edit the menu selections.

Step 3. Select the kernel you would usually boot and press “e” to edit the settings.


How to Recover MySQL Root Password

Do you want to recover the MySQL root password. its by no means, easy. But its quite simple if you follow the procedure. You will have to follow this step-by-step processes.

  1. Step 1: Stop the MySQL server process.
  2. Step 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for a password.
  3. Step 3: Connect to the MySQL server as the root user.
  4. Step 4: Set a new root password.
  5. Step 5: Exit and restart the MySQL server.

Here are the commands you need to type for each step (log in as the root user):

Step 1 : Stop the MySQL service:


Social Media

  
FeedBurner Subscribe



Categories

Page 1 of 11
Copyright © 2012 Linux Debian Tutorials | Debian Squeeze Tutorials. All rights reserved.
↑ Back to Top