Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I am on OSX. Can use both login(1) or su(1) to login as any user.

But, two binaries to make the same job??

Which one consumes less system resources?

Which one is less prone to security risks?

Which differences under the hood?

[ Note, I don't mind gaining root access. I just plan to automate access to accounts on a multi-user, networked *nix. ]

share|improve this question

migrated from Apr 17 '12 at 4:39

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

up vote 0 down vote accepted

login starts a shell with a fresh environment, discarding the current one.

su starts a shell using the existing environment and modifies only the HOME, USER and SHELL variables.

For example,

> export foo=bar
> su <username>
> echo $foo


> export foo=bar
> login <username>
> echo $foo

prints nothing.

AFAIK, su -l is equivalent to login.

share|improve this answer
That's good: su -l is equivalent to login . What if I need to manage to give access to 300 hundreds accounts at the same time? su -l is equivalent to login from a "resources consuming" standpoint? – Ignazio Pupu Apr 17 '12 at 11:06

su(1) will create a new shell with the current environment, and once you exit from the subshell, you will be returned to the invoking shell.

login(1) too will create a new shell but with a fresh environment.

share|improve this answer

It's not exactly same job. "su" just changes user who owns current terminal, "login" (as name says) creates new session.

I'm not OSX expert but in all *NIXes important security consideration is to forbid remote direct login to root. It should be only done by "su" after logging in as ordinary user.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .