Linux Mint – Running commands or programs as other users

How to change the time zone on Windows Server 2019

There may come a time where you need to impersonate another user on your system. In some of our examples so far, we’ve used the sudo command, which essentially runs commands as the root user. On a Linux system, the root account is the account that has access to basically everything. If Linux was a game of chess, think of the root account as the queen—it can go wherever it wants and delete whatever it wants.


In Linux Mint (as well as most Ubuntu derivatives), the root account is disabled by default. Although the root account is disabled, you can still run commands as the root. Technically, the sudo command impersonates the root and works even if the root account is disabled. You can enable the root account with the sudo passwd command and disable it once again with the sudo passwd -l root command.

While we’ll go over the technical details of the sudo command in the next section, it’s important to understand how to run commands as a different user. While the sudo command allows you to run commands as if you were the root account, you can actually run commands as any user you want provided you have either root access or the user’s password. The su – username -c "command" command will allow you to run a command as a different user. For example, to execute mycommand as the user jeff, you would enter the following command line:

su – jeff -c "mycommand"

The su command stands for switch user, and the -c flag followed by a command in quotes executes this command as if it were executed by the user you specified. You will then be prompted for that user’s password, and only then is the command executed. You can even switch to another user outright by executing the following command line:

sudo su - jeff

Why might it be necessary to run commands as other users? If you’re using Mint on your own personal computer, there’s probably not much purpose to do so beyond the sudo command. However, in a corporate environment, you may have user accounts that run individual services automatically, and you may need to use such usernames in scripts to run automated tasks. Additionally, you can also assist a family member or friend to perform a task, all without logging out of your own account.

Comments are closed.