How to run a su command as a different user?

How to run a su command as a different user?

To run a specific command as a different user, use the –c option: su –c [command]

Can you run Su in the middle of a bash script?

You can, but bash won’t run the subsequent commands as postgres. Instead, do: The -c flag runs a command as the user (see man su ). You can use a here document to embed multiple su commands in your script:

How to display a list of su commands?

To display a list of commands, enter the following: Here are some common options to use with the su command: Username – Replace username with the actual username you want to log in with. This can be any user, not just root. –c or –command [command] – Runs a specific command as the specified user.

Why can you use sudo Su within a shell script?

Because running “sudo su” opens a new shell and the command does not return until you exit from that shell. Perhaps split the script into 2 files: first one runs sudo and executes that 2nd script under sudo. MK. MK. sudo su will attempt to start a new shell as root.

What’s the difference between the Sudo and su commands?

Now since we have discussed the basics of the ‘su’ command as well, it’s time we discuss the differences between the ‘sudo’ and the ‘su’ commands. The primary difference between the two is the password they require: while ‘sudo’ requires current user’s password, ‘su’ requires you to enter the root user password.

What is the purpose of the SU Command?

The main work of the su command is to let you switch to some other user during a login session. In other words, the tool lets you assume the identity of some other user without having to logout and then login (as that user).

How can I change the path of a su command?

Enter it, and the login will change to that user. If you omit a username, it will default to the root account. Now, the logged-in user can run all system commands. This will also change the home directory and path to executable files. Use the whoami command to verify you switched to a different user.