Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'd like to log in as a different user without logging out of the current one (on the same terminal). How do I do that?

share|improve this question

3 Answers 3

up vote 68 down vote accepted

How about using the su command?

$ whoami
user1
$ su - user2
Password:
$ whoami
user2
$ exit
logout

If you want to log in as root, there's no need to specify username:

$ whoami
user1
$ su -
Password:
$ whoami
root
$ exit
logout

Generally, you can use sudo to launch a new shell as the user you want; the -u flag lets you specify the username you want:

$ whoami
user1
$ sudo -u user2 zsh
$ whoami
user2

There are more circuitous ways if you don't have sudo access, like ssh username@localhost, but sudo is probably simplest, provided that it's installed and you have permission to use it.

share|improve this answer
1  
Also, su - [user] may be useful -- the extra dash gives you a login shell. –  ephemient Oct 27 '10 at 20:40
$ whoami 

This command prints the current user. To change users, we will have to use this command (followed by the user's password):

$ su secondUser
Password:

After entering the correct password, you will be logged in as the specified user (which you can check by rerunning whoami.

share|improve this answer

Generally you use sudo to launch a new shell as the user you want; the -u flag lets you specify the username you want:

[mrozekma@etudes-1 ~] % whoami
mrozekma
[mrozekma@etudes-1 ~] % sudo -u nobody zsh
[nobody@etudes-1 ~] % whoami
nobody

There are more circuitous ways if you don't have sudo access, like ssh username@localhost, but I think sudo is probably simplest if it's installed and you have permission to use it

share|improve this answer
    
What if my system has neither ssh server or sudo? Can you mention that portion on the answer? –  Tshepang Oct 27 '10 at 19:52
    
ok, Pratt answered that one –  Tshepang Oct 27 '10 at 20:01
2  
sudo -s gives you a shell like su, sudo -i simulates login like su -. Can be combined with -u $user, of course. –  ephemient Oct 27 '10 at 20:41

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.