How to Run a Bash Script as a Created User?

0
6
Asked By CuriousCoder92 On

I'm putting together a bash setup script that sets up users, creates directories, and installs my main application. I want the script to create a specific user and then switch to that user to execute the remaining commands in the script. I'm stuck trying to figure out how to do this. Should I just write one script to create the user and then call a second script that runs as that newly created user?

2 Answers

Answered By ScriptMaster44 On

You should be able to do this! What specific problems are you encountering? A straightforward approach is to create one script to set up the user and another for executing commands as that user. It could help keep things organized.

Answered By TechGuru88 On

You can definitely use the `su` command in your script to switch users. Here’s a quick example:

```
sudo su -c '' -l '

your commands here
...
...
'
```

Just replace `` with the username you want to run the commands as.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.