Skip to content

Monday, November 30th, 2009

New Linux User

HOWTO: Become Another User Without Logging Off.

October 28, 2005 by Jon  
Filed under How To

The magic su command is normally only used to change into the superuser. However, it can be used to change into any user.

In a terminal window, type:

su username

Where username is the name of the user you want to become.

If you’re logged in as the superuser, then you will be able to become any user you like without being prompted for a password. If you’re not the superuser, you will be prompted for the password of the user you’re attempting to become.

  • StumbleUpon
  • Digg
  • Facebook
  • Mixx
  • Google
  • TwitThis
  • Reddit
  • Yahoo! Buzz
  • Slashdot
  • E-mail this story to a friend!

Comments

10 Responses to “HOWTO: Become Another User Without Logging Off.”
  1. You might be interested to research the use of a “-” in the command.

    (Please take the following with a lump of Salt)
    su mollyfud
    is different to
    su – mollyfud

    and both are useful.
    From memory, and you probably want to check this out, without the “-” you are just changing the User you are but leaving your envirnment the same as it is (i.e. environment variables like PATH will be the same before and after the su command).
    If you use the “-”, it is the same as logging in as that user and you get there environment.

    This is handy to know especally if you su to root but can’t run some admin commands you su’d for in the first place. Its probably because the user you su’d from doesn’t have the admin directorys in there path.

    HTH
    Molly
    Http://www.mollyzine.com

    PS. I take no responsiblity if this info turns out as wrong.

  2. Jon says:

    Thanks Molly.

    Another personal favourite of mine is su -c command. This will make you the root user (after prompting for the root password) just for that single command and then you will be returned to your normal mundane self after execution.

    It’s a little safer than just su’ing because you may forget to exit back to your normal self and continue operating as the root user.

  3. gilberto says:

    Hello friends, i’m need help to enter like root with a only line command like this “su username password=xxx” is it posible?

    Thanks a lot

  4. Jon says:

    I’m not 100% sure what you mean gilberto. If you mean that you are already root and you want to become another user, just type

    su username

    Since you are already root you don’t need the user’s password.

    If you mean how do you become root with only one line, then you’ll have to wait until I get home to my Linux box to test that out.

  5. geoff says:

    The only way I can think is perhaps:

    echo "password" | su

  6. geoff says:

    Or, to become a different non-root user:

    echo "password" | su username

  7. Jon says:

    I get a ’su must be run from a terminal’ message when I try either of those options.

    This is a good one…anyone?

  8. geoff says:

    Are you not typing them at a terminal?

  9. Jon says:

    Yeah. Sure am…stupid error message…

  10. Jason says:

    It means you have to type the password interactively (not piped in). This is a safety measure, so that you don’t (for example) type your password into a script, where it can easily be read by others.

    If you want to run a command as root within a script, you should look at ’sudo’, where you can configure whether a password is required, and which commands should be allowed to be run as root.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


About Us | Advertise with us | Blog for EveryJoe | Privacy Policy | Terms of Use
Get This Theme | Sitemap


All content is Copyright © 2005-2009 b5media. All rights reserved.