FG

Run part of a bash script as a different user

Fresh3 days ago
Mar 15, 2026185758 views
Confidence Score1%
1%

Problem

I am in Ubuntu 9.04. Is there a way to make part of a script run as a different (non-root) user? If it helps, the part to be run as a different user occurs at the end of the script.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Run part of a bash script as a different user

Low Risk

Use the sudo command in the script. In the form: the sudo command runs command as the user username. If the script is being run as root, I don't think it will prompt for a password. Otherwise, this article discusses how to use sudo with password in one command line?, and this article discusses how to use sudo without password?

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment