How do I run a Linux command as another user?
- runuser -l userNameHere -c ‘command’ runuser -l userNameHere -c ‘/path/to/command arg1 arg2’ runuser -u user — command1 arg1 arg2.
- su – su – username.
- su – root -c “command” ## OR ## su – -c “command arg1”
- su – root -c “ls -l /root”
How do I run a file as user? Just find an application (or a shortcut) you want to start, hold the Shift key, and right-click on it. Select Run as different user in the context menu.
How do I login as user in Linux?
- Username – Replace username with the actual username you want to log in with.
- –c or –command [command] – Runs a specific command as the specified user.
- – or –l or –login [username] – Runs a login script to change to a specific username.
How do I run as sudo user? To use sudo to run a command as another user, we need to use the -u (user) option. Here, we’re going run the whoami command as the user mary . If you use the sudo command without the -u option, you’ll run the command as root . And of course, because you’re using sudo you’ll be prompted for your password.