Linux lets an authorised user open a shell as another account without ending the original session. This can be useful for administration or working with a site’s own permissions.

Use su with the target account’s password

Replace username with the intended account:

su - username

Normally, su asks for the target account’s password. The login-shell option - loads that account’s environment and changes to its home directory. Root generally does not need its password.

Use sudo when your policy permits it

An authorised sudo user can run:

sudo -iu username

Sudo normally authenticates the invoking user, subject to local policy. Permission to use sudo does not necessarily allow access to every target account.

You do not need to combine sudo and su for this purpose.

Open a separate SSH login

For a new remote session, use:

Replace the server name and use the account’s authorised password or key. Verify an unfamiliar host key through a trusted channel before accepting it.

Check and leave the session

Run whoami to confirm the current account. Use exit to return from a nested shell or close the separate SSH connection.

Accounts with restricted shells or denied login access may not permit an interactive session. Do not change those restrictions just to switch users.