How Do I Run a Script as Root in Linux?
Contents

How do I run a command as a root in shell script?

Therefore, to run a shell script or program as root, you need to use sudo command. However, sudo only recognizes and runs commands that exist in directories specified in the secure_path in the /etc/sudoers, unless a command is present in the secure_path, you’ll counter an error such as the one below.

How do I run a script as root without sudo?

An easy way to check is to use the file command on the program. and it will run the command without asking for your password. This command will run as root. Note, you will need to replace username with you actual username.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest