Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Apr 17 '12 at 4:39

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

3 Answers 3

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
bar

but:

> 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

Your Answer

 
discard

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.