Add An SU User With Root Privileges

  • Boot the Red Hat Server with CentOS 5.1 Disk1
  • Type ‘linux rescue’ at the boot prompt
  • Use the chroot command to change the root to the existing partition chroot /mnt/sysimage
  • Backup the /etc/passwd, /etc/group, /etc/shadow and /etc/gshadow files cp -a /etc/passwd /etc/passwd.bak
cp -a /etc/group /etc/group.bak
cp -a /etc/shadow /etc/shadow.bak
cp -a /etc/gshadow /etc/gshadow.bak

These files can sometimes be protected by the ext2 immutable flag. Check to see if the immutable flag is set. If the immutable flag is set, you will see an ‘i’.

 lsattr /etc/passwd /etc/group /etc/shadow /etc/gshadow 

To Remove the immutable flag

chattr -i /etc/passwd /etc/group /etc/shadow /etc/gshadow

Add a new user and set a password

useradd username
passwd username

Add the immutable flag back if desired

chattr +i /etc/passwd /etc/group /etc/shadow /etc/gshadow

Add the new user to the /etc/sudoers file and give root privileges.

vi /etc/sudoers

Add the following line to the file to give the new user root privileges.

username All=(ALL) ALL

Exit Linux rescue mode
Login with the new account
Test various root level linux commands with ’sudo’ prefix

Log in with root access by using the command 'sudo /bin/bash/' 
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies