How to Run a Shell Script As Root
In most Linux and Unix operating systems, the root user is the only user who can make changes to other accounts, affect system-wide processes and make changes to the operating system kernel. Even in the Ubuntu and Linux Mint operating systems, where there is no default "root" user, these tasks are protected and can only be executed through the use of the "sudo" command. If you have a script that makes system-wide changes, you can switch to the root user with the "su" command or execute the command as the root user using the "sudo" command.
Instructions
-
-
1
Open a terminal window or log into the computer via SSH.
-
2
Type the command "su -" to switch to the root user. Type the root password, when prompted. If you are using the Ubuntu or Linux Mint operating systems, skip this step and type "sudo" before the next command.
-
-
3
Type the command "sh script.sh" to execute the shell script. Replace "script" with the name of the shell script. If you have made the script executable, type the command "./script.sh" to execute it.
-
4
Type the command "exit" to close the root session. Skip this step if you are using the Ubuntu or Linux Mint operating system.
-
1