Personal tools
You are here: Home Wiki Su
Views

Run a shell as a substitute user

How do I execute a command as root, without logging out?

The su, or substute user command allows you to become another user from your current shell. To become root::

        su
        # whoami
        root
        #

What is the difference between "su" and "su -"?

"su" maintains your current environment, while "su -" acts like a login shell. Use "su -" if you want to act like you just opened up a new terminal and logged in as root.

I don't want to be root. I have joe's password, and I want to log in as him.

Easy, Su can substitute as any user, not just root.:

       [[user@host]$ su joe
       Password:       [[joe@host]$

Same rules apply about the dash: "su - joe"

That's really neat. I just want to run a command, instead of logging in.

Su anticipated that: use the -c option:

        [[user@host]$ su -c whoami
        Password:
        root
        [[user@host]$

Is Su the only command that can do this?

For another way, look at the sudo command.

subtopics:



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: