How to Use the su Command in Linux

Category: Advanced – Command Line • Est. reading time: 1 minute

The su command switches you to another user account. With no name given, it switches to root.

Switch to another user

su otherUser

Start a full login shell (recommended)

The dash loads that user’s own environment, the same as a real login. The su manual recommends this over a plain switch to avoid mixing environments.

su - otherUser

Keep your own environment instead

su -m otherUser        # -m or -p preserves your environment

Run as a user whose account has no login shell set

su -s /bin/bash otherUser

Running your own dedicated or self-managed server? We are glad to help. Reach us at support@allydrez.com or 1-321-209-2004.