Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would you go about setting up the correct environment variables and any other settings that should be set when using the su - username command, but without the hyphen?


If I use

su - fooUser

How would I simulate the above after running su without the hyphen?

su fooUser

What do I need to run here to setup all the configuration and everything else that the hyphen sets up?

share|improve this question

migrated from Oct 2 '12 at 13:25

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

Short answer: You can't.

The longer, more correct answer: You can move everything from /etc/profile and equivalent to /etc/bashrc and equivalent (details depend on the shell(s) you're using), and have the former source the latter; that will get you as close as it's possible to get (with the caveat that some things may need extra if/elif/fi tests if they should or shouldn't be run for login shells).

The extra hyphen is a short-hand for "-l" or "--login", which tells su(1) how to invoke the shell: By convention, a shell knows that it's a "login" shell if its argv[0] (the name it gets told it was started as, which does not need to be anything like the filename of its binary) starts with a dash; for example, bash will find itself "called" -bash or -/bin/bash. You can confirm this by logging in on the console and running ps o pid,comm,args $$ - the "args" will start with a dash. A login shell uses a different set of startup files, which is the major difference; see the man-page for your shell(s) for details (e.g. bash invocation). There are some remaining subtleties about the environment that's set before bash ever starts, but that can all be fixed in those startup files.

At this point, it's useful to take a step back and consider: What problem are you trying to solve? Changing your identity shouldn't be something you routinely do; if you find yourself needing it, you should try to figure out how to fix the underlying thing you're trying to do not to require it.

share|improve this answer
Thanks. Not trying to solve a problem, I was just interested. I don't know why I didn't look at the su manpage, probably just because it was a dash and I didn't think of it like an argument. – SDK Apr 30 '13 at 9:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.